4

Is there any way via AMPScript or SSJS to utilize HTTP methods outside of GET and POST?

I have had no problem utilizing these two via the HTTPPost() and HTTPGet() functions, but have not found any way to utilize any of the other methods - such as PUT, DELETE or PATCH.

The reason I ask is that I have inherited some script all in AMPscript that gathers, formats and separates the data/HTML for emails, but now we need to use PUT to update via REST API and I would rather not have to rewrite the whole thing or otherwise export this data and send to another system to run the REST call.

I also would prefer a non-clientside option as it is a major security risk - so no JavaScript/Ajax.


EDIT

I have found something that seems to hopefully point me in the right direction, but have had no luck myself yet.

The function is in SSJS as Script.Util.HttpRequest()

It shows the option to change the method, but as I said, I have not gotten this to work yet:

Additional Properties
contentType - String value indicating content type sent with requests using POST method
method - String value indicating HTTP method to use:
GET
DELETE
HEAD
OPTIONS
PATCH
POST
PUT
postData - String value indicating POST data sent with request - required for POST method

11

GREAT NEWS!!!

Firstly I want to thank SFMC Global Support, for the first time since they were Salesforce they were actually EXTREMELY helpful and quick. (Shout out to Jeff Ross)

We found out that with the Script.Util.HttpRequest() function you actually CAN use

GET
DELETE
HEAD
OPTIONS
PATCH
POST
PUT

It took a few days of both of us digging and searching, but we found it. Hope this helps someone else avoid this headache!

Below is a sample script for this:

<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();
</script>
  • 1
    There are a bunch of other SSJS functions that are completely undocumented, e.g. Platform.Request.RequestURL, etc. Would be nice if they'd actually support the community by releasing them. – Adam Spriggs Jan 18 '18 at 21:13
  • 1
    The HTTP properties are (as I like to say) 'Lightly Documented' here: developer.salesforce.com/docs/… – Gortonington Jan 18 '18 at 21:28
  • 1
    @Gortonington you are a lifesaver. Your answer makes my day, a buddy of mine refer me here!!!! – tkhuynh Mar 29 '18 at 23:33
0

Unfortunately not, the only two methods are GET and POST. The SSJS and AMPScript functions are limited and can't be extended to other VERBS.

  • Thanks for the answer Amtera, can you please provide me some sources or documentation backing this up? I have found that just because SFMC does not list something in their docs, does not mean it is not possible. – Gortonington Jan 10 '18 at 14:28
  • So the AMPScript functions, HTTPGET and HTTPPOST are pretty self explanatory - they can't be modified to support different verbs. The SSJS HTTP.Post and HTTP.Get methods are just wrappers for the equivaluent AMPScript functions. The definition for the HTTP.Get method contains the following reference. Platform.Function.HTTPGet(url, 0, 0, headerNames, headerValues, status); – Amtera Jan 10 '18 at 14:35
  • What about the ScriptUtilHttpRequest in SSJS. It looked the most promising of all the functions (developer.salesforce.com/docs/…) – Gortonington Jan 10 '18 at 14:43
  • I must've missed that function, it looks like it is achievable with Script.Util.HttpRequest() - the example on the page seems to allow you to change the method. – Amtera Jan 10 '18 at 15:03
  • Agreed. I wanted to post and see if anyone has already done this or if there were repercussions on this function as I am sure someone else had this issue. – Gortonington Jan 10 '18 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.