0

I have to perform a GET Request a Microsoft Dynamics 365 CRM URL. The request has one query parameter called select and the value of the query param is as below

consultingid,expert,scientist,host_value,numberofdaysspentconsultingannualsurvey,dateofsurvey&$expand=scientist($select=employeeid)

I am using the encodeURI function in Dataweave as below as the value has & $ etc

                <http:request method="GET" config-ref="Dynamics365_CRM_Request_Configuration" path="${dynamics365.crm.http.path}" doc:name="Request" doc:id="903e22c5-47c0-47bd-9faa-c87d217bf856" >
                    <http:headers ><![CDATA[#[import * from dw::core::URL
                    output application/java
---
{
    "Authorization" : "Bearer " ++ vars.bearerToken,
    "Prefer": "odata.maxpagesize=250, odata.include-annotations=OData.Community.Display.V1.FormattedValue",
    "Content-Type" : "application/json"
}]]]></http:headers>
                    <http:query-params ><![CDATA[#[import * from dw::core::URL
                    output application/java
---
{
    "\$select" : encodeURI(vars.dynamicsUrl)
}]]]></http:query-params>
                </http:request>

When I submit I am getting a response saying Syntax error: character '&' is not valid I see that the & is correctly encoded with %26 as below fragment

%2Cdateofsurvey%26%24expand%3Dsage_scientist%28%24select%3Demployeeid%29 

Any help would be greatly appreciated.

hpandalai
  • 438
  • 2
  • 13
  • 31

1 Answers1

0

You need to use encodeURIComponent.

encodeURI is used to create an overall valid URL. It will not encode the characters that are allowed in a URL, for example "&". Therefore encodeURI will not encode: ~!@#$&*()=:/,;?+'

encodeURIComponent is used to get a string that you can use inside a URI (component of URI) so it will encode everything that has a special meaning for a URI

You can refer to this question for more details. It is for JS but the concept is same

Harshank Bansal
  • 2,798
  • 2
  • 7
  • 22