Can someone give me more details of the function Script.Util.HttpRequest mentioned on the site:


Beyond the example, are there more methods available? And are there descriptions for the methods, for example for req.emptyContentHandling?


1 Answer 1


I acutally just wrote an article on this in my brand spanking new blog. Below are the highlights from it as well as a sample taken from my original SFSE post on it.

Here are the available Methods:


Here is a working sample (taken from here)

<script runat=server>
Platform.Load("core", "1.1.1");

var accessToken = {{yourToken}};
var url = 'https://www.exacttargetapis.com/asset/v1/content/assets/{{ContentID}}'

var payload = '{{yourPayload}}';

var auth = 'Bearer ' + accessToken;

  var req = new Script.Util.HttpRequest(url);
  req.emptyContentHandling = 0;
  req.retries = 2;
  req.continueOnError = true;
  req.contentType = "application/json"
  req.setHeader("Authorization", auth);
  req.method = "PUT"; /*** You can change the method here ***/
  req.postData = payload;

  var resp = req.send();

and below is an overview on the above code:

auth is the authorization token (in this sample, the OAuth token you get via API for SFMC.) The assumption being that you have already made the call to the auth URL to receive the token. Its value is the combination of the accessToken (OAuth) and the require prepend of ‘Bearer ‘.

url is the complete url of your API call. This includes the base url, the endpoint and any ‘unique ids’ necessary (e.g. {{ConntentID}} in the sample)

payload this is the xml/json/etc. ‘body’ of your request. If you are doing POST, PUT, PATCH, etc. This is basically the part that tells the endpoint what to do to what. As it varies depending on endpoint and system, I left this as just a variable in the sample.

req is very similar to WSProxy and is setting up the Request as an object for us to enter information into.

req.emptyContentHandling is actually pretty self explanatory, value of ‘true’ (1) will let the call continue without error if the payload is empty. ‘False’ (0) will cause an error if the payload is empty.

req.retries sets the amount of retry attempts the function will do before failing the call.

req.continueOnError is pretty self explanatory as well. If you have true, it will continue the request regardless of non-fatal errors. On false, it will fail the call if there are any non-fatal errors.

req.contentType is the definition of the content type of the payload.

req.setHeader sets the name/value pairs inside of the header of the API call. In my sample, I included the Authorization header values

req.method is where you would select the method of your call. e.g. PUT, POST, GET, PATCH, DELETE, etc.

req.postData is where the payload we previously created is stored.

req.Send() is then the execution of the fully formed call after all the pieces have been put together.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .