{"metadata":{"image":[],"title":"","description":""},"api":{"url":"/resource/:site_id/:resource_id","auth":"required","params":[{"name":"resource_id","type":"string","default":"","desc":"A unique, immutable identifier for this resource.","required":true,"in":"path","ref":"","_id":"56d9e707337fd11300d6a41d"},{"name":"data","type":"object","default":"","desc":"JSON object representing resource fields to create or update.","required":false,"in":"body","ref":"","_id":"57432daaeed4ab0e00edc650"},{"name":"site_id","type":"string","default":"","desc":"The unique Boomtrain identifier for your site.","required":true,"in":"path","ref":"","_id":"574f5a1a014ddc0e00d14896"}],"results":{"codes":[{"code":"// Occurs when an new resource is created or updated as a result of this request.\n{\n  'data': \n    {\n    \t'message': 'The resource, $resource_id, was updated at $bt_updated_at.'\n  \t}\n}","language":"json","status":201},{"status":400,"language":"text","code":"// Occurs when the resource could not be created or updated due to a bad request format.\n{\n  'errors': [\n    {\n    \t'message': '<Description of the error>'\n  \t}\n   ]\n}"},{"status":403,"language":"text","code":"// Occurs when the site is invalid or the JWT token used to authorize the action is invalid.\n{\n  'errors': [\n    {\n    \t'message': '<description of the error>'\n  \t}\n  ]\n}"}]},"settings":"57432f2eeed4ab0e00edc652","examples":{"codes":[{"code":"curl \n-H 'Content-Type:application/json'\n-H 'Authorization: Bearer <jwt>'\n-X PUT \n-d '{\"resource_type\": \"article\",\"title\": \"A Marketing Guide to Personalization\", \"url\":\"marketingreads.com/marketing-guide-personalization\", \"thumbnail\":\"https://marketingreads.com/wp-content/uploads/2015/07/forbesrevenuefromdigital.jpeg\", \"body\":\"Body of the article.\", \"description\":\"Description of the article.\", \"published_at\": \"2016-05-20T18:24:02Z\", \"modified_at\": \"2016-05-23T18:24:02Z\", \"props\": {\"category\":\"Marketing\"} }'\n'https://resources.api.boomtrain.com/resource/your-site/a1234'","language":"curl"}]},"method":"put"},"next":{"description":"","pages":[]},"title":"Create or Update a Resource","type":"endpoint","slug":"create-update-resource","excerpt":"Creates or updates resources via upsert into your resources collection. If the resource does not already exist, it will be created. If it already exists, it will overwrite all fields specified in the request.","body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Resource Schema\"\n}\n[/block]\nThe following fields may be sent in the body of the request to create or update the resource specified in the route:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Resource Field\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"resource_type (required)\",\n    \"0-1\": \"String\",\n    \"0-2\": \"A string designation of the resource type, e.g. `article`, `product`, `recipe`, `video`.\",\n    \"1-0\": \"title\",\n    \"2-0\": \"url\",\n    \"3-0\": \"thumbnail\",\n    \"4-0\": \"body\",\n    \"5-0\": \"description\",\n    \"6-0\": \"published_at\",\n    \"7-0\": \"modified_at\",\n    \"9-0\": \"props\",\n    \"1-2\": \"A human-readable title for this resource.\",\n    \"1-1\": \"String\",\n    \"2-1\": \"URL\",\n    \"2-2\": \"A URL indicating the location on the web for this resource.\",\n    \"3-1\": \"URL\",\n    \"3-2\": \"A URL to an image of or for this resource.\",\n    \"4-1\": \"String\",\n    \"5-2\": \"A short text description of this resource, often used in the display/rendering of the resource.\",\n    \"4-2\": \"A body of text for this resource. For articles and similar long-form content, the full body of the article should be here.\",\n    \"5-1\": \"String\",\n    \"6-1\": \"ISO-8601 Timestamp\",\n    \"6-2\": \"The publication date of this resource.\",\n    \"7-2\": \"The last modification date of this resource.\",\n    \"7-1\": \"ISO-8601 Timestamp\",\n    \"9-1\": \"Map <String, String>\",\n    \"9-2\": \"A dictionary of additional metadata about this resource.\",\n    \"8-0\": \"is_blacklisted\",\n    \"8-1\": \"Boolean\",\n    \"8-2\": \"`true` to exclude from all content recommendations. `false` or un-set if not.\",\n    \"10-0\": \"variants\",\n    \"10-1\": \"Map <String, Object>\",\n    \"10-2\": \"A dictionary of variants of this resource. Variants are keyed by a unique identifier, and their value contains a dictionary of values that map to known resource fields\"\n  },\n  \"cols\": 3,\n  \"rows\": 11\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Creating a Resource\"\n}\n[/block]\nCreate a resource with a given `resource_id` by specifying one or more fields as referenced in the Resource Schema above in the body of the request. If no resource with the specified `resource_id` exists, one will be created.\n\nNote that the request will fail if any of the standard resource fields listed in the Resource Schema above are not of the correct type. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Updating an Existing Resource\"\n}\n[/block]\nIf a resource with the specified `resource_id` does exist, we will update the existing resource.\n\nAny fields specified in the body of the request will be updated with the new values specified. If a field is not in the body of the request, it will remain unchanged.\n\nNote that the request will fail if any of the standard resource fields listed in the Resource Schema above are not of the correct type.\n[block:api-header]\n{\n  \"title\": \"Managing Variants of a Resource\"\n}\n[/block]\nVariants of a given resource are managed by specifying a \"variants\" object in the request with any number of variants in it. Only variants that are included in this object will be augmented; variants not specified in the body of the request will remain unchanged.\n\nVariants should only contain fields that are compatible with your existing resource fields (see [Get Resource Fields](doc:get-resource-fields) for more details). That is, any variant's fields MUST match an existing field. Variants are not required to have any specific fields.\n\nSpecifying the same variant key more than once in the same `PUT` request will result in the last object specified with that variant being the value set. That means a put with data:\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    resource_type: \\\"product\\\", \\n    variants: {\\n      \\\"1234a\\\": {color: \\\"Red\\\", size_1: 32, size_2: 30},\\n      \\\"1234a\\\": {color: \\\"Blue\\\"}\\n    }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nwould result in variant 1234a having one property, color: Blue.\n\nSetting a variant's value to the empty object, `{}`, will delete that variant.","updates":[],"order":7,"isReference":true,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"573f6feeaf3dec2d00585e83","__v":6,"createdAt":"2016-05-20T20:13:34.974Z","user":"566887ff8639090d00759415","editedParams":true,"parentDoc":null,"project":"56aff08c3a5b810d00745d99","editedParams2":true,"version":{"version":"1","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["56aff08d3a5b810d00745d9d","56aff24f3a5b810d00745da0","56aff25dbc304a0d00ace207","56aff287e0b1e40d00c53798","56aff2b260a37a0d00ed8883","56aff2b8e0b1e40d00c53799","56aff2bd5b1f01170014dc7b","56aff2c9d21e9c0d00b62993","56aff493aef9a21700da0e67","56aff4ce1486990d009c0f64","56aff4da5b1f01170014dc7d","56aff4dfe0b1e40d00c537a2","56aff4e59d32e30d0006d3e9","56aff4e91486990d009c0f65","56aff4f93a5b810d00745da2","56aff4fe9d32e30d0006d3ea","56b91c7ab1e03e0d001057c5","56c4f51aba4a540d0091b9a2","56cd09488c4a331d002c1e44","56d4ec4773dcd20b00fb8769","56e79bc515f96b2200878e54","56ec25c538ff1d2200d56cc2","56ec3a6f36bc8e0e00f190c8","56ec3e308ea7ce0e00a3d8b0","5724d8fe4255580e005938b2","5724dc842ad0bc1700122803","5776ef2a04f7500e0095dc37","57ab9f70b5e8742000e17eb9","57d7117646dcc30e007dd21f","58e6abd5b1eece19008b7d31","59288c65e2653627003e1221","5a8f4797a44f8600128e75ee","5bbf8833eb416300039a2c14","5ea811617bf4b5007328a0af"],"_id":"56aff08c3a5b810d00745d9c","project":"56aff08c3a5b810d00745d99","releaseDate":"2016-02-01T23:55:56.544Z","__v":34,"createdAt":"2016-02-01T23:55:56.544Z"},"category":{"sync":{"isSync":false,"url":""},"pages":["56d4ec8573dcd20b00fb876a"],"title":"Server-Side Integration REST API","slug":"authorization","order":3,"from_sync":false,"reference":true,"_id":"56d4ec4773dcd20b00fb8769","__v":1,"version":"56aff08c3a5b810d00745d9c","createdAt":"2016-03-01T01:11:35.547Z","project":"56aff08c3a5b810d00745d99"},"githubsync":""}

putCreate or Update a Resource

Creates or updates resources via upsert into your resources collection. If the resource does not already exist, it will be created. If it already exists, it will overwrite all fields specified in the request.

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Path Params

resource_id:
required
string
A unique, immutable identifier for this resource.
site_id:
required
string
The unique Boomtrain identifier for your site.

Body Params

data:
object
JSON object representing resource fields to create or update.

Examples


Result Format


Documentation

[block:api-header] { "type": "basic", "title": "Resource Schema" } [/block] The following fields may be sent in the body of the request to create or update the resource specified in the route: [block:parameters] { "data": { "h-0": "Resource Field", "h-1": "Type", "h-2": "Description", "0-0": "resource_type (required)", "0-1": "String", "0-2": "A string designation of the resource type, e.g. `article`, `product`, `recipe`, `video`.", "1-0": "title", "2-0": "url", "3-0": "thumbnail", "4-0": "body", "5-0": "description", "6-0": "published_at", "7-0": "modified_at", "9-0": "props", "1-2": "A human-readable title for this resource.", "1-1": "String", "2-1": "URL", "2-2": "A URL indicating the location on the web for this resource.", "3-1": "URL", "3-2": "A URL to an image of or for this resource.", "4-1": "String", "5-2": "A short text description of this resource, often used in the display/rendering of the resource.", "4-2": "A body of text for this resource. For articles and similar long-form content, the full body of the article should be here.", "5-1": "String", "6-1": "ISO-8601 Timestamp", "6-2": "The publication date of this resource.", "7-2": "The last modification date of this resource.", "7-1": "ISO-8601 Timestamp", "9-1": "Map <String, String>", "9-2": "A dictionary of additional metadata about this resource.", "8-0": "is_blacklisted", "8-1": "Boolean", "8-2": "`true` to exclude from all content recommendations. `false` or un-set if not.", "10-0": "variants", "10-1": "Map <String, Object>", "10-2": "A dictionary of variants of this resource. Variants are keyed by a unique identifier, and their value contains a dictionary of values that map to known resource fields" }, "cols": 3, "rows": 11 } [/block] [block:api-header] { "type": "basic", "title": "Creating a Resource" } [/block] Create a resource with a given `resource_id` by specifying one or more fields as referenced in the Resource Schema above in the body of the request. If no resource with the specified `resource_id` exists, one will be created. Note that the request will fail if any of the standard resource fields listed in the Resource Schema above are not of the correct type. [block:api-header] { "type": "basic", "title": "Updating an Existing Resource" } [/block] If a resource with the specified `resource_id` does exist, we will update the existing resource. Any fields specified in the body of the request will be updated with the new values specified. If a field is not in the body of the request, it will remain unchanged. Note that the request will fail if any of the standard resource fields listed in the Resource Schema above are not of the correct type. [block:api-header] { "title": "Managing Variants of a Resource" } [/block] Variants of a given resource are managed by specifying a "variants" object in the request with any number of variants in it. Only variants that are included in this object will be augmented; variants not specified in the body of the request will remain unchanged. Variants should only contain fields that are compatible with your existing resource fields (see [Get Resource Fields](doc:get-resource-fields) for more details). That is, any variant's fields MUST match an existing field. Variants are not required to have any specific fields. Specifying the same variant key more than once in the same `PUT` request will result in the last object specified with that variant being the value set. That means a put with data: [block:code] { "codes": [ { "code": "{\n resource_type: \"product\", \n variants: {\n \"1234a\": {color: \"Red\", size_1: 32, size_2: 30},\n \"1234a\": {color: \"Blue\"}\n }\n}", "language": "json" } ] } [/block] would result in variant 1234a having one property, color: Blue. Setting a variant's value to the empty object, `{}`, will delete that variant.

User Information

Try It Out

put
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}