Is it possible to make a POST call using REST API in marketing cloud email template? Basically, what im trying to achieve is that when email is sent from marketing cloud, POST call should be made to the 3rd party tool and this POST call will send a html version of the sent email as a JSON file. Any suggestions are much appreciated.
If you need it real time, every time the email is sent, then it will need to be inside the HTML of the email and will likely greatly slow down your email sends. Depending on the volume as well as the file size, this potentially could cause errors in your send as well.
For the in email send you would:
- Create a var to hold the View As WebPage (VAWP) link
SET @VAWPlink = AttributeValue("view_email_url")
- Create an AMPScript POST inside the email via HTTPPost2() passing the VAWP to your 3rd party system.
- Wrap this post in a conditional
IF AttributeValue("_messagecontext") == 'SEND' AND AttributeValue("_isTestSend") == false THEN /* YOUR POST HERE */ ENDIFThis will stop you from going into an infinite loop of POSTING when you grab the VAWP link.
- Have your 3rd party system do a GET to the VAWP link to get all the HTML.
- If you cannot have your 3rd party system do the GET, you will need to do the GET inside the email (not recommended) prior to the post to gather the HTML and then pass this to the system instead of the VAWP var. This way can cause an email to take a VERY long time to send.
The better option if you can have a delay would be to:
- collect the VAWP link
- Have the job id, email name and subscriberkey set as primary keys then upsert all of this info to a DE.
- Then have a script activity to GET the HTML and then POST it to your 3rd party system via a scheduled automation.
This will allow your sends to move much faster. There will still be a slowdown due to the UPSERT, but it will be much less than including the POST.