Difference between revisions of "API ScriptTag"
From Spiffy Stores Knowledge Base
Line 88: | Line 88: | ||
} | } | ||
</style> | </style> | ||
− | + | ||
<span class="api-endpoint-request"> | <span class="api-endpoint-request"> | ||
Line 464: | Line 464: | ||
</div> | </div> | ||
− | + | </html> | |
<br><br><br> | <br><br><br> | ||
Revision as of 10:55, 19 May 2017
The ScriptTag resource represents remote JavaScripts which are loaded into the pages of a store's shopfront and in the order status page of checkout. This makes it easy to add functionality to those pages without touching any theme templates.
A script tag has the following attributes:
- src: The URL of the remote script.
- event: The DOM event which triggers the loading of the script. Currently, "onload" is the only supported event.
- display_scope: Tell Spiffy Stores where to include the script; "online_store", "order_status" or "all". Default to "all".
ScriptTags are scoped to the app that created them. When an app is uninstalled from a shop, all of the script tags which it created are automatically removed along with it.
What you can do with ScriptTag
The Spiffy Stores API lets you do the following with the ScriptTag resource. More detailed versions of these general actions may be available:
- GET /admin/script_tags.json
Receive a list of all ScriptTags - GET /admin/script_tags/count.json
Receive a count of all ScriptTags - GET /admin/script_tags/#{id}.json
Receive a single ScriptTag - POST /admin/script_tags.json
Create a new ScriptTag - PUT /admin/script_tags/#{id}.json
Modify an existing ScriptTag - DELETE /admin/script_tags/#{id}.json
Remove a ScriptTag from the database
ScriptTag properties
created_at | "created_at": "2012-08-24T14:01:47-04:00" The date and time when the ScriptTag was created. The API returns this value in ISO 8601 format. |
event | "event": "onload" DOM event which triggers the loading of the script. Valid values are: "onload." |
id | "id": 596726825 The unique numeric identifier for the ScriptTag. |
src | "src": "https://js-aplenty.com/foo.js" Specifies the location of the ScriptTag. |
display_scope | "display_scope": "online_store" Specifies where the file should be included. "online_store" means only web storefront, "order_status" means only the order status page, while "all" means both. |
updated_at | "updated_at": "2012-08-24T14:01:47-04:00" The date and time when the ScriptTag was last updated. The API returns this value in ISO 8601 format. |
Endpoints
GET /admin/script_tags.json
limit |
Amount of results (default: 50) (maximum: 250) |
page |
Page to show (default: 1) |
since_id |
Restrict results to after the specified ID |
created_at_min |
Show script_tags created after date (format: 2014-04-25T16:15:47-04:00) |
created_at_max |
Show script_tags created before date (format: 2014-04-25T16:15:47-04:00) |
updated_at_min |
Show script_tags last updated after date (format: 2014-04-25T16:15:47-04:00) |
updated_at_max |
Show script_tags last updated before date (format: 2014-04-25T16:15:47-04:00) |
src |
Show script tags with a given URL |
fields |
comma-separated list of fields to include in the response |
Get a list of all script tags for your shop.
GET /admin/script_tags.jsonView Response
HTTP/1.1 200 OK { "script_tags": [ { "id": 421379493, "src": "https:\/\/js-aplenty.com\/bar.js", "event": "onload", "created_at": "2017-03-15T13:27:53-04:00", "updated_at": "2017-03-15T13:27:53-04:00", "display_scope": "all" }, { "id": 596726825, "src": "https:\/\/js-aplenty.com\/foo.js", "event": "onload", "created_at": "2017-03-15T13:27:53-04:00", "updated_at": "2017-03-15T13:27:53-04:00", "display_scope": "all" } ] }
Get a list of all script tags after the specified ID
GET /admin/script_tags.json?since_id=421379493View Response
HTTP/1.1 200 OK { "script_tags": [ { "id": 596726825, "src": "https:\/\/js-aplenty.com\/foo.js", "event": "onload", "created_at": "2017-03-15T13:27:53-04:00", "updated_at": "2017-03-15T13:27:53-04:00", "display_scope": "all" } ] }
Get script tags with a particular URL
GET /admin/script_tags.json?src=https://js-aplenty.com/foo.jsView Response
HTTP/1.1 200 OK { "script_tags": [ { "id": 596726825, "src": "https:\/\/js-aplenty.com\/foo.js", "event": "onload", "created_at": "2017-03-15T13:27:53-04:00", "updated_at": "2017-03-15T13:27:53-04:00", "display_scope": "all" } ] }
src |
Count script tags with given URL |
Get a count of all script tags for your shop.
GET /admin/script_tags/count.jsonView Response
HTTP/1.1 200 OK { "count": 2 }
fields |
comma-separated list of fields to include in the response |
Get a single script tags by its ID.
GET /admin/script_tags/#{id}.jsonView Response
HTTP/1.1 200 OK { "script_tag": { "id": 596726825, "src": "https:\/\/js-aplenty.com\/foo.js", "event": "onload", "created_at": "2017-03-15T13:27:53-04:00", "updated_at": "2017-03-15T13:27:53-04:00", "display_scope": "all" } }
Trying to create a script tag without a src and event will return an error
HTTP/1.1 422 Unprocessable Entity { "errors": { "src": [ "can't be blank", "Source must be secure (HTTPS)" ], "event": [ "can't be blank", "is not included in the list" ] } }
Create a new script tag
POST /admin/script_tags.json
{ "script_tag": { "event": "onload", "src": "https:\/\/djavaskripped.org\/fancy.js" } }View Response
HTTP/1.1 201 Created { "script_tag": { "id": 870402689, "src": "https:\/\/djavaskripped.org\/fancy.js", "event": "onload", "created_at": "2017-03-15T13:28:16-04:00", "updated_at": "2017-03-15T13:28:16-04:00", "display_scope": "all" } }
Update a script tag's URL
PUT /admin/script_tags/#{id}.json
{ "script_tag": { "id": 596726825, "src": "https:\/\/somewhere-else.com\/another.js" } }View Response
HTTP/1.1 200 OK { "script_tag": { "id": 596726825, "src": "https:\/\/somewhere-else.com\/another.js", "event": "onload", "created_at": "2017-03-15T13:27:53-04:00", "updated_at": "2017-03-15T13:28:14-04:00", "display_scope": "all" } }
Remove an existing script tag from a shop
DELETE /admin/script_tags/#{id}.jsonView Response
HTTP/1.1 200 OK {}