Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Remember that when you are calling an external URL to fetch data via an API call to another system that you must encode special characters specifically. For example the URL that you may type into a browser to test may look like this:
https://someserver.somwhere.com:443/apicall?parameter1=test string¶meter2=test^number
but when scripting that into a string variable you'll need to replace the space and the carrot with the proper encoded values (%20 and %5E)
var params = {
username : "me",
password : "password",
url : "https://someserver.somwhere.com:443/apicall?parameter1=test%20string¶meter2=test%5Enumber",
ignoreSSLErrors : false,
timeout : 60,
headers : headers
};
var result = Resources['ContentLoaderFunctions'].LoadXML(params);
also note that in this instance we're making a secure connection therefore port 443 (typically the default) was explicitly specified...
There's actually a build in JavaScript function called encodeURI() that will handle the encoding automatically.
So, we could do:
....
password: "password",
url: encodeURI("https://someserver.somewhere.com:443/apicall?parameter1=test string¶meter2=test^number"),
....
which will result in: https://someserver.somewhere.com:443/apicall?parameter1=test%20string¶meter2=test%5Enumber