API Documentation: Objects: Script Blob

kpthill edited this page Dec 4, 2012 · 2 revisions

Script Blob

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

Object name

script_blob

Associated Capabilities

read_script_tag
write_script_tag

Object Description

A Script Blob is a Javascript snippet 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 blob has one main attribute, content — The content of the script source to be loaded on the store's website. The content will be included inside a <script> element on the merchant's page. It is restricted to 1024 characters; if you need more space, you should use the Script Tag object to load an externally-hosted script.

You should not use the document.write() function or add an onload listener in your script blobs, for the reasons given in the Script Tag Documentation.

If the store uninstalls your app, all of the script blobs 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 blob.
content The content of a <script> element to be included on the store's website. Limited to 1024 characters; should be valid Javsascript which gracefully degrades in every web browser.
created_at The time at which this script blob was created. Format: ISO 8601
updated_at The time at which this script blob was last updated. Format: ISO 8601

Query Parameters Available for this Object:

Field Description Notes
limit Limit of number of objects 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 blobs

Request

GET {base_url}/script_blobs.json

Request data

(empty)

Example response

HTTP/1.1 200 OK

{
  "script_blobs": [
    {
      "id": 123456,
      "content": "(function(){ console.log('I am an example script blob.'); }());",
      "created_at": "2011-01-01T00:00:01-08:00",
      "updated_at": "2011-01-01T00:00:01-08:00"
    }
  ]
}

Create a new script blob

Request

POST {base_url}/script_blobs.json

Request data

{
  "script_blob": {
    "content": "(function(){ console.log('I am an example script blob.'); }());"
  }
}

Example response

HTTP/1.1 201 Created

{
  "script_blob": {
    "id": 123456,
    "content": "(function(){ console.log('I am an example script blob.'); }());",
    "created_at": "2011-01-01T00:00:01-08:00",
    "updated_at": "2011-01-01T00:00:01-08:00"
  }
}

Count script blobs

Request

GET {base_url}/script_blobs/count.json

Request data

(empty)

Example response

HTTP/1.1 200 OK

{
  "count": 2
}

Edit a script blob

Request

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

Request data

{
  "script_blob": {
    "content": "(function(){ console.log('I am a different script blob content'); }());"
  }
}

Example response

HTTP/1.1 200 OK

{
  "script_blob": {
    "id": 123456,
    "content": "(function(){ console.log('I am a different script blob content'); }());",
    "created_at": "2011-01-01T00:00:01-08:00",
    "updated_at": "2012-01-01T00:00:01-08:00"
  }
}

Delete a script blob

Request

DELETE {base_url}/script_blobs/{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.