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 Shopify where to include the script; "online_store", "order_status" or "all". Default to "all".

When an app is uninstalled from a shop, all of the script tags which it created are automatically removed along with it.

What can you do with ScriptTag?

The Shopify API lets you do the following with the ScriptTag resource. More detailed versions of these general actions may be available:

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.json
View Response
HTTP/1.1 200 OK
{
  "script_tags": [
    {
      "id": 421379493,
      "src": "https:\/\/js-aplenty.com\/bar.js",
      "event": "onload",
      "created_at": "2016-11-09T13:42:07-05:00",
      "updated_at": "2016-11-09T13:42:07-05:00",
      "display_scope": "all"
    },
    {
      "id": 596726825,
      "src": "https:\/\/js-aplenty.com\/foo.js",
      "event": "onload",
      "created_at": "2016-11-09T13:42:07-05:00",
      "updated_at": "2016-11-09T13:42:07-05:00",
      "display_scope": "all"
    }
  ]
}

Get a list of all script tags after the specified ID

GET /admin/script_tags.json?since_id=421379493
View Response
HTTP/1.1 200 OK
{
  "script_tags": [
    {
      "id": 596726825,
      "src": "https:\/\/js-aplenty.com\/foo.js",
      "event": "onload",
      "created_at": "2016-11-09T13:42:07-05:00",
      "updated_at": "2016-11-09T13:42:07-05:00",
      "display_scope": "all"
    }
  ]
}

Get script tags with a particular URL

GET /admin/script_tags.json?src=https://js-aplenty.com/foo.js
View Response
HTTP/1.1 200 OK
{
  "script_tags": [
    {
      "id": 596726825,
      "src": "https:\/\/js-aplenty.com\/foo.js",
      "event": "onload",
      "created_at": "2016-11-09T13:42:07-05:00",
      "updated_at": "2016-11-09T13:42:07-05:00",
      "display_scope": "all"
    }
  ]
}
GET /admin/script_tags/count.json
src

Count script tags with given URL

Get a count of all script tags for your shop.

GET /admin/script_tags/count.json
View Response
HTTP/1.1 200 OK
{
  "count": 2
}
GET /admin/script_tags/596726825.json
fields

comma-separated list of fields to include in the response

Get a single script tags by its ID.

GET /admin/script_tags/#{id}.json
View Response
HTTP/1.1 200 OK
{
  "script_tag": {
    "id": 596726825,
    "src": "https:\/\/js-aplenty.com\/foo.js",
    "event": "onload",
    "created_at": "2016-11-09T13:42:07-05:00",
    "updated_at": "2016-11-09T13:42:07-05:00",
    "display_scope": "all"
  }
}
POST /admin/script_tags.json

Trying to create a script tag without a src and event will return an error

POST /admin/script_tags.json
{
  "script_tag": {
    "body": "foobar"
  }
}
View Response
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": 870402688,
    "src": "https:\/\/djavaskripped.org\/fancy.js",
    "event": "onload",
    "created_at": "2016-11-09T13:42:18-05:00",
    "updated_at": "2016-11-09T13:42:18-05:00",
    "display_scope": "all"
  }
}
PUT /admin/script_tags/596726825.json

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": "2016-11-09T13:42:07-05:00",
    "updated_at": "2016-11-09T13:42:17-05:00",
    "display_scope": "all"
  }
}
DELETE /admin/script_tags/596726825.json

Remove an existing script tag from a shop

DELETE /admin/script_tags/#{id}.json
View Response
HTTP/1.1 200 OK
{}