ScriptTag

The ScriptTag resource represents remote javascripts which are loaded into the pages of a shop's storefront and in the final "Thank You" page of checkout. This makes it easy to add functionality to those pages without touching any theme templates.

A script tag has two main 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.

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

Reminder

A ScriptTag will only appear in checkout if the src starts with 'https://' in order not to break the SSL lock.

What can you 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:

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" : "http://js-aplenty.com/foo.js" }

Specifies the location of the ScriptTag.

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: 2008-12-31 03:00)

created_at_max

Show script_tags created before date (format: 2008-12-31 03:00)

updated_at_min

Show script_tags last updated after date (format: 2008-12-31 03:00)

updated_at_max

Show script_tags last updated before date (format: 2008-12-31 03: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": [
    {
      "created_at": "2015-03-28T13:31:19-04:00",
      "event": "onload",
      "id": 421379493,
      "src": "http:\/\/js-aplenty.com\/bar.js",
      "updated_at": "2015-03-28T13:31:19-04:00"
    },
    {
      "created_at": "2015-03-28T13:31:19-04:00",
      "event": "onload",
      "id": 596726825,
      "src": "http:\/\/js-aplenty.com\/foo.js",
      "updated_at": "2015-03-28T13:31:19-04:00"
    }
  ]
}

Get script tags with a particular URL

GET /admin/script_tags.json?src=http://js-aplenty.com/foo.js
View Response
HTTP/1.1 200 OK
{
  "script_tags": [
    {
      "created_at": "2015-03-28T13:31:19-04:00",
      "event": "onload",
      "id": 596726825,
      "src": "http:\/\/js-aplenty.com\/foo.js",
      "updated_at": "2015-03-28T13:31:19-04:00"
    }
  ]
}

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": [
    {
      "created_at": "2015-03-28T13:31:19-04:00",
      "event": "onload",
      "id": 596726825,
      "src": "http:\/\/js-aplenty.com\/foo.js",
      "updated_at": "2015-03-28T13:31:19-04:00"
    }
  ]
}
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": {
    "created_at": "2015-03-28T13:31:19-04:00",
    "event": "onload",
    "id": 596726825,
    "src": "http:\/\/js-aplenty.com\/foo.js",
    "updated_at": "2015-03-28T13:31:19-04:00"
  }
}
POST/admin/script_tags.json

create

POST /admin/script_tags.json
{
  "script_tag": {
    "event": "onload",
    "src": "http:\/\/djavaskripped.org\/fancy.js"
  }
}
View Response
HTTP/1.1 201 Created
{
  "script_tag": {
    "created_at": "2015-03-28T13:33:05-04:00",
    "event": "onload",
    "id": 764371934,
    "src": "http:\/\/djavaskripped.org\/fancy.js",
    "updated_at": "2015-03-28T13:33:05-04:00"
  }
}

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"
    ],
    "event": [
      "can't be blank",
      "is not included in the list"
    ]
  }
}
PUT/admin/script_tags/596726825.json

Update a script tags's URL

PUT /admin/script_tags/#{id}.json
{
  "script_tag": {
    "id": 596726825,
    "src": "http:\/\/somewhere-else.com\/another.js"
  }
}
View Response
HTTP/1.1 200 OK
{
  "script_tag": {
    "created_at": "2015-03-28T13:31:19-04:00",
    "event": "onload",
    "id": 596726825,
    "src": "http:\/\/somewhere-else.com\/another.js",
    "updated_at": "2015-03-28T13:33:06-04:00"
  }
}
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
{}

Haravan - Công ty công nghệ cung cấp giải pháp kinh doanh thương mại điện tử, duy nhất tại Việt Nam được Google lựa chọn vào chương trình bệ phóng tiềm năng với hỗ trợ và đào tạo công nghệ để vươn ra thị trường quốc tế vững chắc.