[SalesForce] How to create & update email using REST API – Salesforce Marketing Cloud

I want to create as well as update an email using REST API.

I am using following documentation links:

  1. POST /asset/v1/content/assets
  2. 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?

Best Answer

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.

Related Topic