1

Can SFMC make outbound API calls to an external web service?

I'm trying to find a solution on the web but it doesn't seem to be anything related to this out there.

1 Answer 1

2

Yes it can!

There are two 'default' options via GET and POST (and POST2) functions. There are also SSJS versions of these functions as well.

But there is also another Script.Util.HttpRequest() option for any of the different methods you may want outside POST and GET.

Full details on script.util here from my previous answer/investigation on it.

HTTPGET example:
HTTPGet('http://www.example.com',false,0,@CallStatus)

HTTPPost example:
%%=HTTPPost("http://example.com","text/html",@exampleContent,@CallStatus)=%%

HTTPPost2 example:

%%[var @output,@respheader]%%
%%=HTTPPost2('http://www.example.com/','text/html', '', true, @output,@respheader, 'Authorization', 'Example', 'User-Agent', 'Example')=%%
Output: %%=v(@output)=%%
Header: %%=v(@respheader)=%%

Sample of Script.Util.HttpRequest:
(this one is internal facing, but can be used for external endpoints as well)

<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
  • How to send certificate and key file in this request?
    – anurag
    Apr 10, 2020 at 12:27

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.