API ScriptTag

From Spiffy Stores Knowledge Base

The ScriptTag resource represents remote JavaScripts which are loaded into the pages of a store's shopfront 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 Spiffy Stores 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 Spiffy Stores API lets you do the following with the ScriptTag resource. More detailed versions of these general actions may be available:

  • GET /admin/script_tags.json
    Receive a list of all ScriptTags
  • GET /admin/script_tags/count.json
    Receive a count of all ScriptTags
  • GET /admin/script_tags/#{id}.json
    Receive a single ScriptTag
  • POST /admin/script_tags.json
    Create a new ScriptTag
  • PUT /admin/script_tags/#{id}.json
    Modify an existing ScriptTag
  • DELETE /admin/script_tags/#{id}.json
    Remove a ScriptTag from the database


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


Response

HTTP/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 /admin/script_tags.json?since_id=421379493


Response

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




Further Reference