frenchtoasters
Contributor
Contributor

Unable to use setHeader on REST request.

I am trying to set some headers on a REST request and looking at the documentation it says that I can use the setHeader method to this. However when I run the workflow with this option set I get the following error.

Property or method 'setHeader' not found on object RESTRequest

Here is the code i am using

var PostResponse = BRHost.createRequest("POST", "/api/sessionMngr/?v=v1_1", null).execute();

var newPost = BRHost.createRequest("POST","/api/tenants");

newPost.contextType = "text/xml";

newPost.setHeader = ("Accept", "application/xml");

newPost.setHeader = ("Name", username);

etc...

I am running version 1.0.6.2501990 of the rest plugin, if that makes a difference.

Tags (1)
1 Reply
iiliev
VMware Employee
VMware Employee

Hi,

setHeader(...) is a scripting method, and invocation syntax for scripting methods is a slightly different:.

So, instead of:

newPost.setHeader = ("Accept", "application/xml"); 

newPost.setHeader = ("Name", username); 

it should be:

newPost.setHeader("Accept", "application/xml"); 

newPost.setHeader("Name", username); 

Also, on line 3 of your sample code you are using contextType property. I think there is no such property; perhaps you meant contentType ?