ScriptTag

The ScriptTag resource represents remote JavaScript code that is loaded into the pages of a shop's storefront or the order status page of checkout. This lets you add functionality to those pages without using theme templates.

Script tags are scoped to the app that created them. When an app is uninstalled from a shop, all of the script tags that it created are automatically removed along with it.

What you can 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 (ISO 8601) when the script tag was created.

event
required
"event": "onload"

The DOM event that triggers the loading of the script. Valid values: onload.

id
"id": 596726825

The ID for the script tag.

src
required
"src": "https://js-aplenty.com/foo.js"

The URL of the remote script.

display_scope
"display_scope": "online_store"

The page or pages on the online store where the script should be included. Valid values:

  • online_store: Include the script only on the web storefront.
  • order_status: Include the script only on the order status page.
  • all: Include the script on both the web storefront and the order status page.

updated_at
"updated_at": "2012-08-24T14:01:47-04:00"

The date and time (ISO 8601) when the script tag was last updated.

Endpoints

GET /admin/script_tags.json
Retrieves a list of all script tags
limit

The number of results to return.

(default: 50) (maximum: 250)
page

The page of results to show.

(default: 1)
since_id

Restrict results to after the specified ID.

created_at_min

Show script tags created after this date. (format: 2014-04-25T16:15:47-04:00)

created_at_max

Show script tags created before this date. (format: 2014-04-25T16:15:47-04:00)

updated_at_min

Show script tags last updated after this date. (format: 2014-04-25T16:15:47-04:00)

updated_at_max

Show script tags last updated before this date. (format: 2014-04-25T16:15:47-04:00)

src

Show script tags with this URL.

fields

A comma-separated list of fields to include in the response.

Retrieve a list of all script tags

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": "2018-05-07T15:33:38-04:00",
      "updated_at": "2018-05-07T15:33:38-04:00",
      "display_scope": "all"
    },
    {
      "id": 596726825,
      "src": "https://js-aplenty.com/foo.js",
      "event": "onload",
      "created_at": "2018-05-07T15:33:38-04:00",
      "updated_at": "2018-05-07T15:33:38-04:00",
      "display_scope": "all"
    }
  ]
}

Retrieve a list of all 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": "2018-05-07T15:33:38-04:00",
      "updated_at": "2018-05-07T15:33:38-04:00",
      "display_scope": "all"
    }
  ]
}

Retrieve 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": "2018-05-07T15:33:38-04:00",
      "updated_at": "2018-05-07T15:33:38-04:00",
      "display_scope": "all"
    }
  ]
}
GET /admin/script_tags/count.json
Retrieves a count of all script tags
src

Count only script tags with a given URL.

Retrieve 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
Retrieves a single script tag
fields

A comma-separated list of fields to include in the response.

Retrieve a single script tag by its ID

GET /admin/script_tags/#{script_tag_id}.json
View Response
HTTP/1.1 200 OK
{
  "script_tag": {
    "id": 596726825,
    "src": "https://js-aplenty.com/foo.js",
    "event": "onload",
    "created_at": "2018-05-07T15:33:38-04:00",
    "updated_at": "2018-05-07T15:33:38-04:00",
    "display_scope": "all"
  }
}
POST /admin/script_tags.json
Creates a new script tag

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": 870402687,
    "src": "https://djavaskripped.org/fancy.js",
    "event": "onload",
    "created_at": "2018-05-07T15:52:37-04:00",
    "updated_at": "2018-05-07T15:52:37-04:00",
    "display_scope": "all"
  }
}

Creating 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"
    ]
  }
}
PUT /admin/script_tags/596726825.json
Updates a script tag

Update a script tag's URL

PUT /admin/script_tags/#{script_tag_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": "2018-05-07T15:33:38-04:00",
    "updated_at": "2018-05-07T15:52:37-04:00",
    "display_scope": "all"
  }
}
DELETE /admin/script_tags/596726825.json
Deletes a script tag

Delete an existing script tag

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