Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Error Invalid URL : REST API : GET Call : Ascii Code Encoding

Ketan Mittal1
Kilo Contributor

I am trying to do a get call via the Rest Messages for this endpoint : https://ocwen-sb.api.identitynow.com/beta/accounts?filters=sourceId eq "2c918084742b9e9a0174447f3d0d1821" and nativeIdentity eq "EXT100001"

However, when I try to run this, I get an error as "invalid URL".

Funny thing, this works well & good on the Postman. I searched a bit about this on google and got to know that apparently, some of these values need to be changes to ascii codes.

So I changed it to this : https://ocwen-sb.api.identitynow.com/beta/accounts?filters=(sourceId=2c918084742b9e9a0174447f3d0d1821&nativeIdentity=EXT100001)

Now I get "Method failed: (/beta/accounts) with code: 400"

{"detailCode":"400.1 Bad request content","trackingId":"7ed978c82e0540ebb13c9aec18c664ae","messages":[{"locale":"en-US","localeOrigin":"DEFAULT","text":"The request was syntactically correct but its content is semantically invalid."}]}

Couldn't find any solution. Need help.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Ketan Mittal 

I assume you must be setting the endpoint of the REST Message using setEndPoint()

please update as below

var sourceId = '2c918084742b9e9a0174447f3d0d1821';

var nativeIdentity = 'EXT100001';

var url = 'https://ocwen-sb.api.identitynow.com/beta/accounts?filters=(sourceId=' + sourceId + '&nativeIdentity=' + nativeIdentity + ')';

url = encodeURIComponent(url);

var request = new sn_ws.RESTMessageV2();
request.setEndpoint();
request.setHttpMethod('GET');

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Geoff_T
Mega Sage

Hi,

Have you tried to use encodeURIComponent?

 

var queryParam = 'sourceId eq "2c918084742b9e9a0174447f3d0d1821" and nativeIdentity eq "EXT100001"'

var uri = 'https://ocwen-sb.api.identitynow.com/beta/accounts?filters=' + encodeURIComponent(queryParam);


Something like the above.

 

Let me know if it works.

Thanks Geoff. but how do I use this in the Rest Messages ?

find_real_file.png

 

Hi Ketan,

If you are hardcoding the endpoint in that then use this directly

https://ocwen-sb.api.identitynow.com/beta/accounts?filters=(sourceId=2c918084742b9e9a0174447f3d0d1821&nativeIdentity=EXT100001)

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Tried this. Doesn't work. Method failed: (/beta/accounts) with code: 400 The request was syntactically correct but its content is semantically invalid.