Snippets are reusable HTML components which can be embedded into Emails and Landing Pages and which can be segmented for dynamic content. Snippets don’t have associated templates, and can be created and deployed within other assets within Marketo.
Query
Querying snippets follows the standard pattern for assets, except it does not have a By Name method. Both the By Id and Browse methods allow the use of the status field to retrieve either approved or draft versions of the snippet.
By Id
1 |
GET /rest/asset/v1/snippet/{id}.json?status=approved |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
{ "success":true, "warnings":[ ], "errors":[ ], "requestId":"fa0f#14b04375f0a", "result":[ { "id":83, "name":"BYkHVJEedl", "description":"yzSLvNFyrmeVmyLzqryUfGlDOJTnvyyfsQTXPDCGdCwcWUlfoCNApUqYgwZGElrUFoxBHJcMdXdqTKvtjtfsmPgokyRgVLeHyJCw", "createdAt":"2015-01-19T22:01:52Z+0000", "updatedAt":"2015-01-19T22:01:52Z+0000", "folder":{ "type":"Folder", "value":662 }, "status":"approved", "workspace":"Default" } ] } |
Browse
1 |
GET /rest/asset/v1/snippets.json?maxReturn=3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
{ "success":true, "warnings":[ ], "errors":[ ], "requestId":"f9cc#14b04376181", "result":[ { "id":23, "name":"ADJvMLBMpS", "description":"XkzFUVLXVHrojLGLJVLPpwguOXuDvhAqaaSkBUVzgHrgDhqqRzyXlULIXSHJvfBHjCSaMwjyEdrdxcjFCRoNFVvdBBTDfSrUJzaR", "createdAt":"2015-01-15T20:10:39Z+0000", "updatedAt":"2015-01-15T20:10:39Z+0000", "url": null, "folder":{ "type":"Folder", "value":620, "folderName": "Snippets" }, "status":"draft", "workspace":"Default" }, { "id":46, "name":"Biswa Snippet", "description":"", "createdAt":"2015-01-16T05:18:55Z+0000", "updatedAt":"2015-01-16T05:19:27Z+0000", "url": null, "folder":{ "type":"Folder", "value":630, "folderName": "Snippets" }, "status":"draft", "workspace":"Default" }, { "id":12, "name":"dJJQkKbUYq", "description":"VXuHkYMREHrhxUSgYbKfaNeLisdFxOromCXQNrgmModvkuoyZdQjtAbXxDUbBvoDVCZmAVbasiHyWoWfTwgrGxnzpKepGrAUvfen", "createdAt":"2015-01-15T05:12:33Z+0000", "updatedAt":"2015-01-15T05:12:33Z+0000", "url": null, "folder":{ "type":"Folder", "value":615, "folderName": "Snippets" }, "status":"draft", "workspace":"Default" } ] } |
Query Content
The content of a given snippet can be retrieved based on the snippet id.
1 |
GET /rest/asset/v1/snippet/{id}/content.json |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
{ "success":true, "warnings":[ ], "errors":[ ], "requestId":"5c50#14b04376159", "result":[ { "type":"HTML", "content":"draft testUpdateSnippetContent1 HTML Content" }, { "type":"Text", "content":"draft testUpdateSnippetContent1 Text Content" } ] } |
The call will return 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 needs to be to the create endpoint, with an optional description. Data is passed as x-www-form-urlencoded, not as JSON.
1 |
POST /rest/asset/v1/snippets.json |
1 |
Content-Type: application/x-www-form-urlencoded |
1 |
name=Test Snippet 09 - deverly&folder={"id":395,"type":"Folder"}&description=This is a test snippet |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "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 just 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.
1 |
POST /rest/asset/v1/snippet/{id}/content.json |
1 |
Content-Type: application/x-www-form-urlencoded |
1 |
type=HTML&content=draft testUpdateSnippetContent1 HTML Content |
1 2 3 4 5 6 7 8 9 10 11 |
{ "success":true, "warnings":[ ], "errors":[ ], "requestId":"73d9#14b04376139", "result":[ { "id":82 } ] } |
Updating metadata is also done by id. Only name and description can be updated:
1 |
POST /rest/asset/v1/snippet/{id}.json |
1 |
Content-Type: application/x-www-form-urlencoded |
1 |
name=Test Snippet&description=New Description |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "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.
1 |
GET /rest/asset/v1/snippet/{id}/dynamicContent.json |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
{ "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
1 |
POST /rest/asset/v1/snippet/{id}/approveDraft.json |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "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.
1 |
POST /rest/asset/v1/snippet/{id}/unapprove.json |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "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.
1 |
POST /rest/asset/v1/snippet/{id}/discardDraft.json |
1 2 3 4 5 6 7 8 9 10 11 |
{ "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 will be cloned.
1 |
POST /rest/asset/v1/snippet/{id}/clone.json |
1 |
Content-Type: application/x-www-form-urlencoded |
1 |
name=Test Snippet Clone 3 - deverly&folder={"id":395,"type":"Folder"}&description=This is a test snippet |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "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" } ] } |