cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Passing parameters in HTTP request in HCI using groovy

hsonnenahalli
Contributor
0 Kudos
1,284

Dear Experts-

I am working on a scenario in which, I need to pass date calculation to the URL so that can get the data every 15 mins when the particular flow runs. I have written the following code but when executed the values are not getting picked up. I think am declaring the URL as constant but am not sure how to get this working. Please, it would be appreciated if any light can be shed on this issue. When I execute below code am seeing following error in which the date calculation is getting passed.

ERROR

//partners.parkhub.com/transactions?dateFromsetProperty.dateFrom=&dateTosetProperty.dateTo=&landmarkId=b8b6ab4c-3dc4-4975-96e3-3032fff55712 with statusCode: 403

Groovy Code

import com.sap.it.api.mapping.*;

import java.text.SimpleDateFormat;

import java.text.DateFormat;

import java.util.Locale;

import java.util.TimeZone;

import com.sap.gateway.ip.core.customdev.util.Message; import java.util.HashMap; import java.lang.*;

{ def Message processData(Message message) { def currDT = new Date(); def newDateObj = new Date(currDT.getTime() - 15*60000); message.setHeader("Content-Type","application/json"); message.setHeader("Accept","application/json"); message.setProperty("fromDateTimeUTC",currDT.getTime() ); message.setProperty("toDateTimeUTC ",newDateObj); message.setProperty("dateFrom",currDT.getTime() ); message.setProperty("dateTo",newDateObj); message.setProperty("landmarkId","b8b6ab4c-3dc4-4975-96e3-3032fff55712")

def url = https://partners.parkhub.com/transactions?dateFrom=${setProperty.dateFrom}&dateTo=${setProperty.date...; message.setProperty("url",url);

return message;

}

Appreciate the support

Regards

HS

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Hi Hari

If you don't need the two dates elsewhere in your integration flow, you don't need to store them in properties. Just store them in local variables, and add those to your URL. So something like:

def dateFrom = ....
def dateTo = ....

.
.
.

def url = "https://partners.parkhub.com/transactions?dateFrom=${dateFrom}&dateTo=${dateTo}&landmarkId=b8b6ab4c-3dc4-4975-96e3-3032fff55712"

If you do need to store the dates in properties, you can access those properties in your URL as follows:

def url = "https://partners.parkhub.com/transactions?dateFrom=${message.getProperty('dateFrom')}&dateTo=${message.getProperty('dateTo')}&landmarkId=b8b6ab4c-3dc4-4975-96e3-3032fff55712"

Regards,

Morten

hsonnenahalli
Contributor

You rock. Thanks a lot.

Regards

HS

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

No problem. Regards, Morten

Answers (0)