Files
- Topics:
- REST API
CREATED FOR:
- Admin
Marketo subscriptions allow for storage of arbitrary files like images, scripts, documents, and style sheets. All of these can be worked with remotely via the REST API. The storage available in Marketo subscriptions is not optimized for bandwidth-intensive applications, so alternatives should be used for proper audio and video streaming applications.
Query
Querying files is simple and follows the standard query types for assets of by id, by name, and browsing.
By Id
GET /rest/asset/v1/file/{id}.json
{
"success":true,
"warnings":[ ],
"errors":[ ],
"requestId":null,
"result":[
{
"id":147,
"size":61346,
"mimeType":"image/jpeg",
"url":"http://mlm.devlocal.marketo.com/rs/test/assets/rYXNeQFFVu",
"folder":{
"type":"Email",
"id":10613
},
"name":"rYXNeQFFVu",
"description":null,
"createdAt":"2014-12-09T22:33:57Z+0000",
"updatedAt":"2014-12-09T22:33:57Z+0000"
}
]
}
By Name
Specify the name of the file using the required name
parameter.
GET /rest/asset/v1/file/byName.json?name=foo.png
{
"success": true,
"warnings": [],
"errors": [],
"requestId": "9049#15918a76619",
"result": [
{
"id": 46488,
"size": 13987,
"mimeType": "image/png",
"url": "http://na-abm.marketo.com/rs/mktodemoaccount88/assets/foo.png",
"folder": {
"type": "Image",
"id": 436,
"name": "My Images"
},
"name": "foo.png",
"description": "This is a test file.",
"createdAt": "2015-05-06T22:16:58Z+0000",
"updatedAt": "2015-05-06T22:19:29Z+0000"
}
]
}
Browse
There are three optional parameters:
- folder - parent folder specified as JSON block containing “id” and “type” attributes
- offset - integer that specifies where to begin retrieving entries (default is 0); can be used with maxReturn parameter
- maxReturn - integer that specifies the maximum number of entries to return (default is 20, maximum is 200)
GET /rest/asset/v1/files.json?folder={"id":436, "type": "Folder"}&maxReturn=3
{
"success": true,
"warnings": [],
"errors": [],
"requestId": "17e4e#14e23372d80",
"result": [
{
"id": 46484,
"size": 1454,
"mimeType": "text/plain",
"url": "http://na-abm.marketo.com/rs/mktodemoaccount88/assets/websites.png",
"folder": {
"type": "Image",
"id": 436,
"name": "My Images - deverly"
},
"name": "websites.png",
"description": "This is a test file.",
"createdAt": "2015-05-06T20:15:58Z+0000",
"updatedAt": "2015-06-22T02:12:36Z+0000"
},
{
"id": 46486,
"size": 4169,
"mimeType": "image/png",
"url": "http://na-abm.marketo.com/rs/mktodemoaccount88/assets/mobile.png",
"folder": {
"type": "Image",
"id": 436,
"name": "My Images - deverly"
},
"name": "mobile.png",
"description": null,
"createdAt": "2015-05-06T22:13:33Z+0000",
"updatedAt": "2015-05-06T22:13:33Z+0000"
},
{
"id": 46488,
"size": 13987,
"mimeType": "image/png",
"url": "http://na-abm.marketo.com/rs/mktodemoaccount88/assets/foo.png",
"folder": {
"type": "Image",
"id": 436,
"name": "My Images - deverly"
},
"name": "foo.png",
"description": "This is a test file.",
"createdAt": "2015-05-06T22:16:58Z+0000",
"updatedAt": "2015-05-06T22:19:29Z+0000"
}
]
}
Create and Update
Creating a file is done with a multipart/form-data type of request. Minimally, the name, folder, and file are required in the request, with an optional description, and an insertOnly flag, which prevents a create call from updating an existing file with the same name. For the file parameter, a “filename” is required in the Content-Disposition header, in addition to the name parameter. You must also pass a Content-Type header for file, which will be the MIME-type which Marketo will use to serve the file with.
POST /rest/asset/v1/files.json
------WebKitFormBoundary2VyWOacQSupl4gUL
Content-Disposition: form-data; name="file"; filename="marketo.html"
Content-Type: text/html
<html>
<body>
<h1>Test Page - marketo.html</h1>
</body>
</html>
------WebKitFormBoundary2VyWOacQSupl4gUL
Content-Disposition: form-data; name="name"
marketo.html
------WebKitFormBoundary2VyWOacQSupl4gUL
Content-Disposition: form-data; name="folder"
{"id":436,"type":"Folder"}
------WebKitFormBoundary2VyWOacQSupl4gUL
Content-Disposition: form-data; name="description"
This is a test file
------WebKitFormBoundary2VyWOacQSupl4gUL—
{
"success": true,
"warnings": [],
"errors": [],
"requestId": "278d#14e23316f63",
"result": [
{
"id": 46960,
"size": 69,
"mimeType": "text/html",
"url": "http://na-abm.marketo.com/rs/mktodemoaccount88/assets/marketo.html",
"folder": {
"type": "Image",
"id": 436,
"name": "My Images - deverly"
},
"name": "marketo.html",
"description": "This is a test file",
"createdAt": "2015-06-24T01:31:59Z+0000",
"updatedAt": "2015-06-24T01:31:59Z+0000"
}
]
}
Updating a file can be done based on its id. The only parameter is a file parameter which has the same requirements as creation.
POST /rest/asset/v1/file/{id}/content.json
------WebKitFormBoundary2VyWOacQSupl4gUL
Content-Disposition: form-data; name="file"; filename="marketo.html"
Content-Type: text/html
<html>
<body>
<h1>Test Page - marketo.html</h1>
</body>
</html>
------WebKitFormBoundary2VyWOacQSupl4gUL--
{
"success": true,
"warnings": [],
"errors": [],
"requestId": null,
"result": [
{
"id": 67,
"size": 512000,
"mimeType": "image/png",
"url": "http://pages.devlocal.marketo.com/rs/test/assets/aLZiwCkXor",
"folder": {
"type": "Email",
"id": 10391
},
"name": "aLZiwCkXor",
"description": null,
"createdAt": "2014-12-18T09:03:43Z+0000",
"updatedAt": "2015-01-07T04:40:20Z+0000"
}
]
}