cancel
Showing results for 
Search instead for 
Did you mean: 

Pass Query parameters values to Target URL using policies

ramu_g4
Participant
0 Kudos

Hi Experts,

We are working on SAP APIM to pass some 11 query parameters values from source to target URL.

We have source URL something like below (strings in bold are source query parameter names).

As you can see there are around 10 query parameters coming from Source system.

https://<host>/org/v1/api/compdata/vendor_profile?companyno=06598&companyname=&siteno=&sitename=&address=&city=&state=&postal=&country=&pagesize=

I am using place holder then java script to pass values from query parameters passed from source to target URL.

Target URL looks something like below.

http://<host>:<port>;/OrgDev/rest/v1/datasources/VENDOR_PROFILE/execute?COUNTRY$PARAM='{country}'&COMPANY_NAME$PARAM='{companyname}'&COMPANY_NUMBER$PARAM='{companyno}'&SSP_NUMBER$PARAM='{siteno}'&SSP_NAME$PARAM='{sitename}'&SSP_ADDRESS$PARAM='{address}'&SSP_CITY_COUNTY$PARAM='{city}'&SSP_STATE$PARAM='{state}'&SSP_POSTAL_CODE$PARAM='{postal}'&pagesize='{pagesize}'

I have used java script policy to fetch values from source and pass them to target URL.

My configuration works completely fine when there are only 5 or 6 query parameters but does not work there are more query parameters from source like in this case where there are 10 query parameters.

Even API is not getting deployed when I give above target URL in bold as per below screenshot.

Looks like there is limitation of 256 characters when I try to deploy the API itself.

I get below error when I try to deploy the API like unable to update API and when I remove some query parameters to adjust the characters count to 256 or less then API is getting deployed successfully.

Could you please suggest another work around to overcome this issue.

Can we somehow use some policies to get this issue resolved and to generate target URL as required.

Kindly guide me to resolve this issue , Thank you!

Regards.

Accepted Solutions (0)

Answers (1)

Answers (1)

PriyankaChak
Active Contributor

Hi,

You can use Assign Message policy to add query params to create your target URL. In the Target URL, just keep http://<host>:<port>/OrgDev/rest/v1/datasources/VENDOR_PROFILE/execute.

Something similar to below code:

<AssignMessage xmlns="http://www.sap.com/apimgmt" async="false" continueOnError="false" enabled="true">
<Add>
<QueryParams>
<QueryParam name="COMPANY_NUMBER">{request.queryparam.companyno}</QueryParam>
</QueryParams>
</Add>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="request">request</AssignTo>
</AssignMessage>

Regards,

Priyanka

ramu_g4
Participant
0 Kudos

Hi Priyanka,

Thank you for response. Could you please let me know the position of policy that needs to added like on ProxyEndpoint (PreFlow/PostFlow) or TargetEndpoint (PreFlow/PostFlow).

Should I follow below syntax when I try to add multiple query parameters?

<AssignMessage xmlns="http://www.sap.com/apimgmt" async="false" continueOnError="false" enabled="true">
<Add>
<QueryParams>
<QueryParam name="COMPANY_NUMBER">{request.queryparam.companyno}</QueryParam>
<QueryParam name="SSP_COUNTRY">{request.queryparam.country}</QueryParam>
<QueryParam name="SSP_ADDRESS">{request.queryparam.address}</QueryParam>
<QueryParam name="SSP_CITY">{request.queryparam.city}</QueryParam>
</QueryParams>
</Add>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="request">request</AssignTo>
</AssignMessage><br>

Thanks,

Ramu.

PriyankaChak
Active Contributor
0 Kudos

ProxyEndpoint - PreFlow

ramu_g4
Participant
0 Kudos

hi Priyanka,

I was javascript to extract values and pass them to position of placeholder in URL , since there is limitation with length I cant use all 11 query parameters. I used this Javascript on ProxyEndpoint - postFlow . So I removed javascript policy and replaced it with AssignMessage and used below in assign message poilcy but getting error.

<AssignMessage xmlns="http://www.sap.com/apimgmt" async="false" continueOnError="false" enabled="true"> <Add>

<QueryParams>

<QueryParam name="SSP_COUNTRY$PARAM">{request.queryparam.country}</QueryParam>

<QueryParam name="COMPANY_NAME$PARAM">{request.queryparam.companyname}</QueryParam>

<QueryParam name="COMPANY_NUMBER$PARAM">{request.queryparam.companyno}</QueryParam>

<QueryParam name="SSP_NUMBER$PARAM">{request.queryparam.siteno}</QueryParam>

<QueryParam name="SSP_NAME$PARAM">{request.queryparam.sitename}</QueryParam>

</QueryParams>

</Add>

<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>

<AssignTo createNew="false" type="request">request</AssignTo>

</AssignMessage>

Regards.