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.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityYes 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>