API Documentation: Objects: Script Tag

kpthill edited this page Dec 3, 2012 · 7 revisions

Script Tag

Go back to read introductory information and usage guidelines about the API.

Object name

script_tag

Associated Capabilities

read_script_tag
write_script_tag

Object Description

A Script Tag is a Javascript URL that you can load into the pages of a store. When a customer visits the store's website, this Javascript is included in the web browser, augmenting the customer's shopping experience with your Javascript.

A script tag object revolves around the two main attributes src and event:

  • src — The URL of the hosted script source to be included on the store's website.

  • event — The DOM event that, when fired, triggers loading of a Script Tag with a src attribute set. The only allowable value at this point is onload (i.e. when the page is loaded).

A note on the src attribute:

We highly recommend that your script be available both to http and https requests at the same URL. If this is the case, then you can set the script source to the protocol-agnostic form that looks like //my_cdn.com/my_script.js.

When Lexity includes your script while a customer is browsing a site via http, it will not include any Javascript files hosted on https servers (and vice-versa) for security reasons.

You should not use document.write() in your scripts - this function will be ignored by many browsers when it is called from an asynchronously loaded script.

You should not listen for the page load in your scripts - we already refrain from running your script until the page load event has fired, so code listening for onload will never be run.

If the store uninstalls your app, all of the script tags which have been added to the store via your app will be removed.

Object Attributes

Field Description Notes
id The unique id for this script tag.
src The script source URL to be included on the store's website. Scripts starting with http:// (https://) will only be included if the customer is browsing the site over http (https). Scripts starting with the protocol-agnostic // will be included with either protocol.
event The trigger for this script tag to be loaded. Only onload is supported right now.
created_at The time at which this script was created. Format: ISO 8601
updated_at The time at which this script was last updated. Format: ISO 8601

Query Parameters Available for this Object:

Field Description Notes
src Return object(s) with the given src (or an empty list). Filters via exact match.
limit Limit of number of script tags in the response. Defaults to 50, maximum allowed value is 250.
page For paginated responses, the page to show. Defaults to 1.
since_id Only show objects with id greater than this value.
created_at_min Show objects created after this date. Format: YYYY-MM-DD
created_at_max Show objects created before this date. Format: YYYY-MM-DD
updated_at_min Show objects updated after this date. Format: YYYY-MM-DD
updated_at_max Show objects updated before this date. Format: YYYY-MM-DD
fields Comma-separated string with the fields you want to returned in the response body. Defaults to null, indicating you want all fields to be returned

Available API Interactions

Get script tags

Request

GET {base_url}/script_tags.json

Request data

(empty)

Example response

HTTP/1.1 200 OK

{
  "script_tags": [
    {
      "id": 123456,
      "src": "//my_cdn.com/my_script.js",
      "event": "onload",
      "created_at": "2011-01-01T00:00:01-08:00",
      "updated_at": "2011-01-01T00:00:01-08:00"
    }
  ]
}

Create a new script tag

Request

POST {base_url}/script_tags.json

Request data

{
  "script_tag": {
    "src": "//my_cdn.com/my_script.js",
    "event": "onload"
  }
}

Example response

HTTP/1.1 201 Created

{
  "script_tag": {
    "id": 123456,
    "src": "//my_cdn.com/my_script.js",
    "event": "onload",
    "created_at": "2011-01-01T00:00:01-08:00",
    "updated_at": "2011-01-01T00:00:01-08:00"
  }
}

Count script tags

Request

GET {base_url}/script_tags/count.json

Request data

(empty)

Example response

HTTP/1.1 200 OK

{
  "count": 2
}

Edit a script tag

Request

PUT {base_url}/script_tags/{id}.json

Request data

{
  "script_tag": {
    "src": "//my_cdn.com/my_other_script.js"
  }
}

Example response

HTTP/1.1 200 OK

{
  "script_tag": {
    "id": 123456,
    "src": "//my_cdn.com/my_other_script.js",
    "event": "onload",
    "created_at": "2011-01-01T00:00:01-08:00",
    "updated_at": "2012-01-01T00:00:01-08:00"
  }
}

Delete a script tag

Request

DELETE {base_url}/script_tags/{id}.json

Request data

(empty)

Example response

HTTP/1.1 200 OK

{}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.