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 https://apis.haravan.com/web/script_tags.json


limit

Amount of results

(default: 50) (maximum: 50)

page

Page to show

(default: 1)

since_id
Restrict results to after the specified ID
created_at_minShow script_tags created after date (format: 2008-12-31 03:00)
created_at_maxShow script_tags created before date (format: 2008-12-31 03:00)
updated_at_minShow 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 https://apis.haravan.com/web/script_tags.json

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 https://apis.haravan.com/web/script_tags.json?src=http://js-aplenty.com/foo.js

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 https://apis.haravan.com/web/script_tags.json?since_id=421379493

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"
    }
  ]
}

Count script tags with given URL src

GET https://apis.haravan.com/web/script_tags/count.json

Get a count of all script tags for your shop.

GET https://apis.haravan.com/web/script_tags/count.json

Response:

HTTP/1.1 200 OK
{
  "count": 2
}
https://apis.haravan.com/web/script_tags/596726825.json

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


Get a single script tags by its ID.

GET https://apis.haravan.com/web/script_tags/#{id}.json

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"
  }
}

create

POST https://apis.haravan.com/web/script_tags.json
{
  "script_tag": {
    "event": "onload",
    "src": "http:\/\/djavaskripped.org\/fancy.js"
  }
}

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 https://apis.haravan.com/web/script_tags.json
{
  "script_tag": {
    "body": "foobar"
  }
}

Response:

HTTP/1.1 422 Unprocessable Entity
{
  "errors": {
    "src": [
      "can't be blank"
    ],
    "event": [
      "can't be blank",
      "is not included in the list"
    ]
  }
}


Update a script tags's URL

PUT https://apis.haravan.com/web/script_tags/#{id}.json
{
  "script_tag": {
    "id": 596726825,
    "src": "http:\/\/somewhere-else.com\/another.js"
  }
}

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"
  }
}


Remove an existing script tag from a shop

DELETE https://apis.haravan.com/web/script_tags/#{id}.json

Response:

HTTP/1.1 200 OK
{}