Skip to Content
0
Jun 12, 2018 at 05:29 PM

Passing parameters in HTTP request in HCI using groovy

1073 Views Last edit Jun 12, 2018 at 05:34 PM 4 rev

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.dateTo}&landmarkId=b8b6ab4c-3dc4-4975-96e3-3032fff55712; message.setProperty("url",url);

return message;

}

Appreciate the support

Regards

HS