Passing host variable in REST Message

swisstech08
Mega Contributor

Hi,

I'm trying to solve an issue I am having with a REST message. The following is the REST Message configuration/setup:

var hostName = 'test.hostname.com';

var request = new sn_ws.RESTMessageV2('System Information', 'POST SiteToken');
 request.setStringParameter('baseUrl','test.hostname.com');
//request.setStringParameter('baseUrl',hostName);
request.setStringParameter('api','15.8');
request.setRequestHeader('Accept','application/json');
request.setRequestHeader('Content-Type','application/json');
//request.setStringParameter('siteID','ae0377db-5dc5-4f31-aea2-f');

 var response = request.execute();

This is the REST Message endpoint:

https://${baseUrl}/api/${api}/auth/signin
When I run the rest request it passes successfully, http=200, and I get the correct information back

When I run the request with the hostname as a variable:

request.setStringParameter('baseUrl',hostName);

Then the request fails with error message: unknown host.

I have done some troubleshooting with Xplore and there when using the hostname variable in the request and do:

gs.print("Set Endpoint: " + sm.getEndpoint());

it returns the correct endpoint:

test.hostname.com

 

Any idea on why this fails when using a variable in the REST message setup?

Thank you,

Roland

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Hello,

It looks weird but just a try to cast the variable to a String with double quotes.

var hostName = "test.hostname.com";

Can you make this change and see if it works. I have seen some posts where the double quotes have messed up.

Thanks!

View solution in original post

4 REPLIES 4

Alikutty A
Tera Sage

Hello,

It looks weird but just a try to cast the variable to a String with double quotes.

var hostName = "test.hostname.com";

Can you make this change and see if it works. I have seen some posts where the double quotes have messed up.

Thanks!

Hi Alikutty,


Thank you that solved the issue.

 

Great!! Can you please mark my response as correct answer and close this thread?

Thanks!

I think you have marked the wrong response as correct answer. Can you please mark my first response as correct answer so the community users can refer to it?