I want to create as well as update an email using REST API.
I am using following documentation links:
- POST /asset/v1/content/assets
- PUT /asset/v1/content/assets/{id}
(https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/routes.htm)
I am able to retrieve content using GET API call (GET /asset/v1/content/assets).
However, I am not sure where to put the updated HTML code in my PUT or POST API request. Do I have to put it in URL or I have to put it in BODY of the API request? If BODY, then what would be the structure of the BODY? How my JSON would look like?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
An example provided in the docs for adding content is below:
{ "name": "NTO Welcome Series Email", "channels": { "email": true, "web": false }, "views": { "html": { "content": "<!DOCTYPE html><body>This is a simple message.</body></html>" }, "text": {}, "subjectline": {}, "preheader": {} }, "assetType": { "name": "templatebasedemail", "id": 207 } }
You would set your new/updated html into the ‘content’ (views > html > content) section of the above JSON.
You can also view more samples here – including HTML Paste, Simple Template based and Complex template based emails.
Method 2
I used Apex to update the content of a Html Email Template (AssetId = 208): on the code i have to use this header ‘request.setHeader(‘X-HTTP-Method-Override’,’PATCH’)’ and made a POST action on the request to get success, and the json example is the following:
{ "views":{ "html":{ "content":"Here goes the html code of the template" } }, "assetType":{ "name":"htmlemail", "id":208 } }
the url to call is the one that you mention:
../asset/v1/content/assets/{id}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0