ScriptTag
The ScriptTag resource represents remote javascripts which are loaded into the pages of a shop's storefront 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 Haravan 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 Haravan API lets you do the following with the ScriptTag resource. More detailed versions of these general actions may be available:
- GET /web/script_tags.jsonReceive a list of all ScriptTags
- GET /web/script_tags/count.jsonReceive a count of all ScriptTags
- GET /web/script_tags/#{id}.jsonReceive a single ScriptTag
- POST /web/script_tags.jsonCreate a new ScriptTag
- PUT /web/script_tags/#{id}.jsonModify an existing ScriptTag
- DELETE /web/script_tags/#{id}.jsonRemove a ScriptTag from the database
ScriptTag properties
created_at |
The date and time when the ScriptTag was created. The API returns this value in ISO 8601 format. |
event |
DOM event which triggers the loading of the script. Valid values are: "onload." |
id |
The unique numeric identifier for the ScriptTag. |
src |
Specifies the location of the ScriptTag. |
display_scope |
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 |
The date and time when the ScriptTag was last updated. The API returns this value in ISO 8601 format. |
Endpoints
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 /web/script_tags.json
Hide ResponseHTTP/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 /web/script_tags.json?since_id=421379493
Hide ResponseHTTP/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 /web/script_tags.json?src=https://js-aplenty.com/foo.js
Hide ResponseHTTP/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 /web/script_tags/count.json
Hide ResponseHTTP/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 /web/script_tags/#{id}.json
Hide ResponseHTTP/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 /web/script_tags.json
{ "script_tag": { "event": "onload", "src": "https:\/\/djavaskripped.org\/fancy.js" } }Hide 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 /web/script_tags/#{id}.json
{ "script_tag": { "id": 596726825, "src": "https:\/\/somewhere-else.com\/another.js" } }Hide 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 /web/script_tags/#{id}.json
Hide ResponseHTTP/1.1 200 OK {}