Query Content

The content of a given snippet can be retrieved based on the snippet id.

GET /rest/asset/v1/snippet/{id}/content.json
{
   "success":true,
   "warnings":[ ],
   "errors":[ ],
   "requestId":"5c50#14b04376159",
   "result":[
      {
         "type":"HTML",
         "content":"draft testUpdateSnippetContent1 HTML Content"
      },
      {
         "type":"Text",
         "content":"draft testUpdateSnippetContent1 Text Content"
      }
   ]
}

The call returns a list of content sections,  which consist of sections of type HTML or type DynamicContent, and optionally a section with a type of Text.

Create and Update

Snippets follow the complex asset creation pattern, where the call to create snippet, and its content are made separately, so the first call must be to the create endpoint, with an optional description.   Data is passed as x-www-form-urlencoded, not as JSON.

POST /rest/asset/v1/snippets.json
Content-Type: application/x-www-form-urlencoded
name=Test Snippet 09 - deverly&folder={"id":395,"type":"Folder"}&description=This is a test snippet
{
    "success": true,
    "warnings": [],
    "errors": [],
    "requestId": "bd57#14e231ee3a1",
    "result": [
        {
            "id": 13,
            "name": "Test Snippet 09 - deverly",
            "description": "This is a test snippet",
            "createdAt": "2015-06-24T01:11:43Z+0000",
            "updatedAt": "2015-06-24T01:11:43Z+0000",
            "url": "https://app-abm.marketo.com/#SN13B2ZN395",
            "folder": {
                "type": "Folder",
                "value": 395,
                "folderName": "Snippets"
            },
            "status": "draft",
            "workspace": "Default"
        }
    ]
}

Adding or replacing content in a snippet is done by id. The content can be of the types Text, HTML, or DynamicContent. If the type is Text, then the content parameter is plain text endpoint, while if it is HTML, then it is the desired markup text. If the type is set to DynamicContent, then the content parameter should be set to the id of the segmentation to be associated with the snippet.

POST /rest/asset/v1/snippet/{id}/content.json
Content-Type: application/x-www-form-urlencoded
type=HTML&content=draft testUpdateSnippetContent1 HTML Content
{
   "success":true,
   "warnings":[ ],
   "errors":[ ],
   "requestId":"73d9#14b04376139",
   "result":[
      {
         "id":82
      }
   ]
}

Updating metadata is also done by id. Only name and description can be updated:

POST /rest/asset/v1/snippet/{id}.json
Content-Type: application/x-www-form-urlencoded
name=Test Snippet&description=New Description
{
   "success":true,
   "warnings":[ ],
   "errors":[ ],
   "requestId":"9ad0#14b043762b1",
   "result":[
      {
         "id":82,
         "name":"Test Snippet",
         "description":"New Description",
         "createdAt":"2015-01-19T22:01:52Z+0000",
         "updatedAt":"2015-01-19T22:01:53Z+0000",
         "url": "https://app-abm.marketo.com/#SN3B2ZN395",
         "folder":{
            "type":"Folder",
            "value":662,
            "folderName": "Snippets"
         },
         "status":"draft",
         "workspace":"Default"
      }
   ]
}

Dynamic Content

Snippets follow the standard pattern for dynamic content, but they only represent one whole content section by themselves, so each snippet may contain only one dynamic section, with a list of internal sections optionally for each segment in the used segmentation. Dynamic content can be queried by snippet id alone, since there may only be one dynamic content section in a snippet.

GET /rest/asset/v1/snippet/{id}/dynamicContent.json
{
    "success": true,
    "warnings": [ ],
    "errors": [ ],
    "requestId": "ae3#14c2b499111",
    "result": [
        {
            "createdAt": "2015-03-13T06:24:35Z+0000",
            "updatedAt": "2015-03-17T20:29:42Z+0000",
            "id": 70,
            "segmentation": 1001,
            "content": [
                {
                    "id": "Nzk*",
                    "segmentId": 1001,
                    "segmentName": "Area",
                    "content": "Sample HTML for Area",
                    "type": "HTML"
                },
                {
                    "id": "Nzk*",
                    "segmentId": 1001,
                    "segmentName": "Area",
                    "content": "Sample Text for Area",
                    "type": "Text"
                },
                {
                    "id": "Nzk*",
                    "segmentId": 1002,
                    "segmentName": "Default",
                    "content": "Sample HTML for Default",
                    "type": "HTML"
                },
                {
                    "id": "Nzk*",
                    "segmentId": 1002,
                    "segmentName": "Default",
                    "content": "Sample Text for Default",
                    "type": "Text"
                }
            ]
        }
    ]
}

Approval

Snippets have endpoints available for approving, unapproving, and discarding drafts, which follow the standard asset pattern. A snippet must be in draft status for it to be approved.

Approve

POST /rest/asset/v1/snippet/{id}/approveDraft.json
{
    "success": true,
    "warnings": [ ],
    "errors": [ ],
    "requestId": "11903#14db1af2f6c",
    "result": [
        {
            "id": 3,
            "name": "Test Snippet 02 - deverly",
            "description": "hey this is a test snippet!",
            "createdAt": "2015-06-02T00:32:37Z+0000",
            "updatedAt": "2015-06-02T00:32:37Z+0000",
            "url": "https://app-abm.marketo.com/#SN3B2ZN395",
            "folder": {
                "type": "Folder",
                "value": 395,
                "folderName": "Snippets"
            },
            "status": "approved",
            "workspace": "Default"
        }
    ]
}

Unapprove

The unapprove endpoint can only be used on approved snippets.

POST /rest/asset/v1/snippet/{id}/unapprove.json
{
    "success": true,
    "warnings": [ ],
    "errors": [ ],
    "requestId": "7d20#14db1c7a2a9",
    "result": [
        {
            "id": 89,
            "name": "Test Snippet 01 - deverly",
            "description": "",
            "createdAt": "2015-05-15T19:01:22Z+0000",
            "updatedAt": "2015-05-15T19:07:07Z+0000",
            "url": "https://app-abm.marketo.com/#SN1B2ZN395",
            "folder": {
                "type": "Folder",
                "value": 395,
                "folderName": "Snippets"
            },
            "status": "draft",
            "workspace": "Default"
        }
    ]
}

Discard Draft

The snippet must be in draft status to be discarded.  An approved snippet cannot be discarded.

POST /rest/asset/v1/snippet/{id}/discardDraft.json
{
   "success":true,
   "warnings":[ ],
   "errors":[ ],
   "requestId":"674c#14b043760de",
   "result":[
      {
         "id":88
      }
   ]
}

Clone

Cloning a snippet with the API is simple and follows the standard pattern, with a required name, id of the original snippet and folder, as well as an optional description.  If no approved version exists, then the draft version is cloned.

POST /rest/asset/v1/snippet/{id}/clone.json
Content-Type: application/x-www-form-urlencoded
name=Test Snippet Clone 3 - deverly&folder={"id":395,"type":"Folder"}&description=This is a test snippet
{
    "success": true,
    "warnings": [],
    "errors": [],
    "requestId": "21c9#14e2327e33d",
    "result": [
        {
            "id": 14,
            "name": "Test Snippet Clone 3 - deverly",
            "description": "This is a test snippet",
            "createdAt": "2015-06-24T01:21:33Z+0000",
            "updatedAt": "2015-06-24T01:21:33Z+0000",
            "url": "https://app-abm.marketo.com/#SN14B2ZN395",
            "folder": {
                "type": "Folder",
                "value": 395,
                "folderName": "Snippets"
            },
            "status": "draft",
            "workspace": "Default"
        }
    ]
}
recommendation-more-help