Difference between revisions of "API ScriptTag"

From Spiffy Stores Knowledge Base

m
 
(16 intermediate revisions by one other user not shown)
Line 1: Line 1:
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.
+
The ScriptTag resource represents remote JavaScript code that is loaded into the pages of a store's shopfront or the checkout pages. This lets you add functionality to these pages without needing to update any theme templates.
  
A script tag has the following attributes:
+
Script tags are scoped to the app that created them. When an app is uninstalled from a store, all of the script tags associated with it are automatically removed.
  
* src: The URL of the remote script.
+
== ScriptTag Properties ==
* 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".
 
  
 +
{| class="reference"
 +
!id
 +
|<pre>{ "id" : 191 }</pre>
 +
A unique numeric identifier for the script tag.
 +
|-
 +
!src
 +
|<pre>{ "src" : "https://js-library.com/widget.js" }</pre>
 +
The URL of the remote script that is to be included on the page.
 +
|-
 +
!event
 +
|<pre>{ "event": "onload" }</pre>
 +
The DOM event that triggers the loading of the script. Valid values are:
 +
 +
* onload
 +
|-
 +
!display_scope
 +
|<pre>{ "display_scope": "online_store" }</pre>
 +
The page or pages where the script should be included. Valid values are:
 +
 +
* online_store: Include the script only on the shopfront pages
 +
* order_checkout: Include the script on the checkout pages
 +
* all: Include the script on all pages.
 +
|-
 +
!created_at
 +
|<pre>{ "created_at": "2008-07-15T20:00:00-04:00" }</pre>
 +
The date and time (ISO 8601 format) when the script tag was created.
 +
|-
 +
!updated_at
 +
|<pre>{ "updated_at": "2008-07-16T20:00:00-04:00" }</pre>
 +
The date and time (ISO 8601 format) when the script tag was last updated.
 +
|}
 +
 +
== Endpoints ==
 +
 +
=== <code>GET /api/script_tags.json</code> ===
 +
 +
Retrieve a list of all script tags.
 +
 +
==== Optional Parameters ====
 +
 +
{| class="reference"
 +
!limit
 +
|Number of results returned. The default is 30, with a maximum of 50 in a single request.
 +
|-
 +
!page
 +
|The number of the page to return. The number of results per page is set by the <code>limit</code> parameter. If more results are required, then submit the request again, increasing the page number each time.
 +
|-
 +
!since_id
 +
|Limit the results to only include objects which have an id greater than the given value.
 +
|-
 +
!src
 +
|Limit the results to only include script tags with the given source URL.
 +
|-
 +
!created_at_min
 +
|Return only the script tags created after the given date and time. Use the format "2014-12-31 12:00".
 +
|-
 +
!created_at_max
 +
|Return only the script tags created before the given date and time. Use the format "2014-12-31 12:00".
 +
|-
 +
!updated_at_min
 +
|Return only the script tags updated after the given date and time. Use the format "2014-12-31 12:00".
 +
|-
 +
!updated_at_max
 +
|Return only the script tags updated before the given date and time. Use the format "2014-12-31 12:00".
 +
|-
 +
!fields
 +
|A comma-separated list of fields to return in the response.
 +
|}
 +
 +
==== Example Request and Response ====
 +
 +
<pre>
 +
GET /api/script_tags.json
  
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.
+
HTTP/1.1 200 OK
  
 +
{
 +
  "script_tags": [
 +
    {
 +
      "id": 12343,
 +
      "src": "https://test.spiffyserver.com/global/address_finder.js?key=4EK23454567878HMAPNT",
 +
      "event": "onload",
 +
      "display_scope": "order_checkout",
 +
      "created_at": "2017-04-12T17:15:07.873+10:00",
 +
      "updated_at": "2017-04-12T17:15:07.873+10:00"
 +
    }, ...
 +
  ]
 +
}
  
==What you can do with ScriptTag==
+
Examples using filters
  
The Spiffy Stores API lets you do the following with the ScriptTag resource. More detailed versions of these general actions may be available:
+
GET /api/script_tags.json?fields=id,src,display_scope
  
* GET /admin/script_tags.json<br>Receive a list of all ScriptTags
+
</pre>
* GET /admin/script_tags/count.json<br>Receive a count of all ScriptTags
 
* GET /admin/script_tags/#{id}.json<br>Receive a single ScriptTag
 
* POST /admin/script_tags.json<br>Create a new ScriptTag
 
* PUT /admin/script_tags/#{id}.json<br>Modify an existing ScriptTag
 
* DELETE /admin/script_tags/#{id}.json<br>Remove a ScriptTag from the database
 
  
 +
=== <code>GET /api/script_tags/count.json</code> ===
  
==ScriptTag properties==
+
Return a count of the number of script tags.
  
<html>
+
==== Optional Parameters ====
  <style type="text/css">
+
 
  table.wikitable td { padding: 10px 20px !important; text-align: left; vertical-align: top; }
+
{| class="reference"
  table.wikitable pre {padding: 0 !important; border: none !important; }
+
!since_id
  </style>
+
|Limit the results to only include objects which have an id greater than the given value.
</html>
 
{| class="wikitable" style="width: 100%"
 
|style="width: 30%"|created_at
 
|<pre>"created_at": "2012-08-24T14:01:47-04:00"</pre><br>The date and time when the ScriptTag was created. The API returns this value in ISO 8601 format.
 
|-
 
|event
 
|<pre>"event": "onload"</pre><br>DOM event which triggers the loading of the script. Valid values are: "onload."
 
 
|-
 
|-
|id
+
!src
|<pre>"id": 596726825</pre><br>The unique numeric identifier for the ScriptTag.
+
|Limit the results to only include script tags with the given source URL.
 
|-
 
|-
|src
+
!created_at_min
|<pre>"src": "https://js-aplenty.com/foo.js"</pre><br>Specifies the location of the ScriptTag.
+
|Return only the script tags created after the given date and time. Use the format "2014-12-31 12:00".
 
|-
 
|-
|display_scope
+
!created_at_max
|<pre>"display_scope": "online_store"</pre><br>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.
+
|Return only the script tags created before the given date and time. Use the format "2014-12-31 12:00".
 
|-
 
|-
|updated_at
+
!updated_at_min
|<pre>"updated_at": "2012-08-24T14:01:47-04:00"</pre><br>The date and time when the ScriptTag was last updated. The API returns this value in ISO 8601 format.
+
|Return only the script tags updated after the given date and time. Use the format "2014-12-31 12:00".
 +
|-
 +
!updated_at_max
 +
|Return only the script tags updated before the given date and time. Use the format "2014-12-31 12:00".
 
|}
 
|}
  
 +
==== Example Request and Response ====
  
== Endpoints==
+
<pre>
<html>
+
GET /api/script_tags/count.json
<style type="text/css">
 
  
.api-endpoint-request {
+
HTTP/1.1 200 OK
  padding: 15px 30px;
+
 
  display: block;
+
{
  background: #30373b;
+
   "count": 4
   color: #fff;
 
 
}
 
}
  
.api-endpoint-request-type {
+
</pre>
  display: block;
+
 
  float: left;
+
=== <code>GET /api/script_tags/SCRIPT_TAG_ID.json</code> ===
  background: #2a2c2e;
+
 
  padding: 15px 30px;
+
Retrieves a single script tag by ID.
  margin: -15px 30px 0 -30px;
+
 
  color: #fff;
+
==== Optional Parameters ====
}
+
 
 +
{| class="reference"
 +
!fields
 +
|A comma-separated list of fields to return in the response.
 +
|}
  
.api-endpoint-description {
+
==== Example Request and Response ====
  padding: 15px 30px;
 
  display: block;
 
  background: #f9fafa;
 
  border-bottom: 0;
 
}
 
  
.api-endpoint-content, .api-endpoint-description {
+
<pre>
  border: 1px solid #e5e5e5;
+
GET /api/script_tags/12343.json
  border-top: 0;
 
}
 
</style>
 
  
 +
HTTP/1.1 200 OK
  
<span class="api-endpoint-request">
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
 
        GET
 
      </span>
 
      /admin/script_tags.json
 
    </span>
 
    <div class="api-endpoint-description">
 
    </div>
 
    <div class="api-endpoint-content">
 
      <div class="api-endpoint-queryparameters">
 
        <table>
 
          <tbody>
 
              <tr>
 
                <td>limit</td>
 
                <td>
 
                    <p>Amount of results</p>
 
                  (default: 50)
 
                  (maximum: 250)
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>page</td>
 
                <td>
 
                    <p>Page to show</p>
 
                  (default: 1)
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>since_id</td>
 
                <td>
 
                    <p>Restrict results to after the specified ID</p>
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>created_at_min</td>
 
                <td>
 
                    <p>Show script_tags created after date (format: 2014-04-25T16:15:47-04:00)</p>
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>created_at_max</td>
 
                <td>
 
                    <p>Show script_tags created before date (format: 2014-04-25T16:15:47-04:00)</p>
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>updated_at_min</td>
 
                <td>
 
                    <p>Show script_tags last updated after date (format: 2014-04-25T16:15:47-04:00)</p>
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>updated_at_max</td>
 
                <td>
 
                    <p>Show script_tags last updated before date (format: 2014-04-25T16:15:47-04:00)</p>
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>src</td>
 
                <td>
 
                    <p>Show script tags with a given URL</p>
 
                </td>
 
              </tr>
 
              <tr>
 
                <td>fields</td>
 
                <td>
 
                    <p>comma-separated list of fields to include in the response</p>
 
                </td>
 
              </tr>
 
          </tbody>
 
        </table>
 
      </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Get a list of all script tags for your shop.</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>GET /admin/script_tags.json</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 200 OK
 
{
 
  &quot;script_tags&quot;: [
 
    {
 
      &quot;id&quot;: 421379493,
 
      &quot;src&quot;: &quot;https:\/\/js-aplenty.com\/bar.js&quot;,
 
      &quot;event&quot;: &quot;onload&quot;,
 
      &quot;created_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
      &quot;updated_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
      &quot;display_scope&quot;: &quot;all&quot;
 
    },
 
    {
 
      &quot;id&quot;: 596726825,
 
      &quot;src&quot;: &quot;https:\/\/js-aplenty.com\/foo.js&quot;,
 
      &quot;event&quot;: &quot;onload&quot;,
 
      &quot;created_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
      &quot;updated_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
      &quot;display_scope&quot;: &quot;all&quot;
 
    }
 
  ]
 
}</pre>
 
          </div>
 
        </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Get a list of all script tags after the specified ID</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>GET /admin/script_tags.json?since_id=421379493</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 200 OK
 
 
{
 
{
   &quot;script_tags&quot;: [
+
   "script_tag": {
     {
+
     "id": 12343,
      &quot;id&quot;: 596726825,
+
     "src": "https://test.spiffyserver.com/global/address_finder.js?key=4EK23454567878HMAPNT",
      &quot;src&quot;: &quot;https:\/\/js-aplenty.com\/foo.js&quot;,
+
     "event": "onload",
      &quot;event&quot;: &quot;onload&quot;,
+
     "display_scope": "order_checkout",
      &quot;created_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
+
     "created_at": "2017-04-12T17:15:07.873+10:00",
      &quot;updated_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
+
     "updated_at": "2017-04-12T17:15:07.873+10:00"
      &quot;display_scope&quot;: &quot;all&quot;
 
     }
 
  ]
 
}</pre>
 
          </div>
 
        </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Get script tags with a particular URL</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>GET /admin/script_tags.json?src=https://js-aplenty.com/foo.js</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 200 OK
 
{
 
  &quot;script_tags&quot;: [
 
    {
 
      &quot;id&quot;: 596726825,
 
      &quot;src&quot;: &quot;https:\/\/js-aplenty.com\/foo.js&quot;,
 
      &quot;event&quot;: &quot;onload&quot;,
 
      &quot;created_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
      &quot;updated_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
      &quot;display_scope&quot;: &quot;all&quot;
 
     }
 
  ]
 
}</pre>
 
          </div>
 
        </div>
 
    </div>
 
  </div>
 
  <div id="count" class="api-endpoint">
 
     <span class="api-endpoint-request">
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
 
        GET
 
      </span>
 
      /admin/script_tags/count.json
 
    </span>
 
     <div class="api-endpoint-description">
 
    </div>
 
    <div class="api-endpoint-content">
 
      <div class="api-endpoint-queryparameters">
 
        <table>
 
          <tbody>
 
              <tr>
 
                <td>src</td>
 
                <td>
 
                    <p>Count script tags with given URL</p>
 
                </td>
 
              </tr>
 
          </tbody>
 
        </table>
 
      </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Get a count of all script tags for your shop.</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>GET /admin/script_tags/count.json</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 200 OK
 
{
 
  &quot;count&quot;: 2
 
}</pre>
 
          </div>
 
        </div>
 
    </div>
 
  </div>
 
  <div id="show" class="api-endpoint">
 
    <span class="api-endpoint-request">
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
 
        GET
 
      </span>
 
      /admin/script_tags/596726825.json
 
    </span>
 
    <div class="api-endpoint-description">
 
    </div>
 
    <div class="api-endpoint-content">
 
      <div class="api-endpoint-queryparameters">
 
        <table>
 
          <tbody>
 
              <tr>
 
                <td>fields</td>
 
                <td>
 
                    <p>comma-separated list of fields to include in the response</p>
 
                </td>
 
              </tr>
 
          </tbody>
 
        </table>
 
      </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Get a single script tags by its ID.</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>GET /admin/script_tags/#{id}.json</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 200 OK
 
{
 
  &quot;script_tag&quot;: {
 
    &quot;id&quot;: 596726825,
 
    &quot;src&quot;: &quot;https:\/\/js-aplenty.com\/foo.js&quot;,
 
    &quot;event&quot;: &quot;onload&quot;,
 
    &quot;created_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
     &quot;updated_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
    &quot;display_scope&quot;: &quot;all&quot;
 
 
   }
 
   }
}</pre>
+
}
          </div>
+
</pre>
        </div>
+
 
    </div>
+
=== <code>POST /api/script_tags.json</code> ===
  </div>
+
 
  <div id="create" class="api-endpoint">
+
Create a new script tag.
    <span class="api-endpoint-request">
+
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
+
==== Example Request and Response ====
        POST
+
 
      </span>
+
<pre>
      /admin/script_tags.json
+
POST /api/script_tags.json
    </span>
+
 
    <div class="api-endpoint-description">
 
    </div>
 
    <div class="api-endpoint-content">
 
      <div class="api-endpoint-queryparameters">
 
        <table>
 
          <tbody>
 
          </tbody>
 
        </table>
 
      </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Trying to create a script tag without a src and event will return an error</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>POST /admin/script_tags.json</pre>
 
              <pre>{
 
  &quot;script_tag&quot;: {
 
    &quot;body&quot;: &quot;foobar&quot;
 
  }
 
}</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 422 Unprocessable Entity
 
 
{
 
{
   &quot;errors&quot;: {
+
   "script_tag": {
     &quot;src&quot;: [
+
     "src": "https://js-library.com/widgets.js",
      &quot;can&#39;t be blank&quot;,
+
     "event": "onload",
      &quot;Source must be secure (HTTPS)&quot;
+
     "display_scope": "online_store"
     ],
 
    &quot;event&quot;: [
 
      &quot;can&#39;t be blank&quot;,
 
      &quot;is not included in the list&quot;
 
     ]
 
 
   }
 
   }
}</pre>
+
}
          </div>
+
 
        </div>
+
HTTP/1.1 201 Created
        <div class="api-endpoint-example">
+
</pre>
          <h3 class="api-endpoint-example-title">Create a new script tag</h3>
+
 
          <div class="api-endpoint-example-request">
+
=== <code>PUT /api/script_tags/SCRIPT_TAG_ID.json</code> ===
              <pre>POST /admin/script_tags.json</pre>
+
 
              <pre>{
+
Updates a script tag.
  &quot;script_tag&quot;: {
+
 
    &quot;event&quot;: &quot;onload&quot;,
+
==== Example Request and Response ====
    &quot;src&quot;: &quot;https:\/\/djavaskripped.org\/fancy.js&quot;
+
 
  }
+
<pre>
}</pre>
+
PUT /api/script_tags/12343.json
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
+
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 201 Created
 
 
{
 
{
   &quot;script_tag&quot;: {
+
   "script_tag": {
     &quot;id&quot;: 870402689,
+
     "id": 12343,
     &quot;src&quot;: &quot;https:\/\/djavaskripped.org\/fancy.js&quot;,
+
     "src": "https://another-library.com/new_widget.js"
    &quot;event&quot;: &quot;onload&quot;,
 
    &quot;created_at&quot;: &quot;2017-03-15T13:28:16-04:00&quot;,
 
    &quot;updated_at&quot;: &quot;2017-03-15T13:28:16-04:00&quot;,
 
    &quot;display_scope&quot;: &quot;all&quot;
 
 
   }
 
   }
}</pre>
+
}
          </div>
+
 
        </div>
+
HTTP/1.1 200 OK
    </div>
+
</pre>
  </div>
+
 
  <div id="update" class="api-endpoint">
+
=== <code>DELETE /api/script_tags/SCRIPT_TAG_ID.json</code> ===
    <span class="api-endpoint-request">
+
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
+
Deletes a script tag.
        PUT
+
 
      </span>
+
==== Example Request and Response ====
      /admin/script_tags/596726825.json
+
 
    </span>
+
<pre>
    <div class="api-endpoint-description">
+
DELETE /api/script_tags/12312.json
    </div>
+
 
    <div class="api-endpoint-content">
+
HTTP/1.1 200 OK
      <div class="api-endpoint-queryparameters">
 
        <table>
 
          <tbody>
 
          </tbody>
 
        </table>
 
      </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Update a script tag's URL</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>PUT /admin/script_tags/#{id}.json</pre>
 
              <pre>{
 
  &quot;script_tag&quot;: {
 
    &quot;id&quot;: 596726825,
 
    &quot;src&quot;: &quot;https:\/\/somewhere-else.com\/another.js&quot;
 
  }
 
}</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 200 OK
 
{
 
  &quot;script_tag&quot;: {
 
    &quot;id&quot;: 596726825,
 
    &quot;src&quot;: &quot;https:\/\/somewhere-else.com\/another.js&quot;,
 
    &quot;event&quot;: &quot;onload&quot;,
 
    &quot;created_at&quot;: &quot;2017-03-15T13:27:53-04:00&quot;,
 
    &quot;updated_at&quot;: &quot;2017-03-15T13:28:14-04:00&quot;,
 
    &quot;display_scope&quot;: &quot;all&quot;
 
  }
 
}</pre>
 
          </div>
 
        </div>
 
    </div>
 
  </div>
 
  <div id="destroy" class="api-endpoint">
 
    <span class="api-endpoint-request">
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
 
        DELETE
 
      </span>
 
      /admin/script_tags/596726825.json
 
    </span>
 
    <div class="api-endpoint-description">
 
    </div>
 
    <div class="api-endpoint-content">
 
      <div class="api-endpoint-queryparameters">
 
        <table>
 
          <tbody>
 
          </tbody>
 
        </table>
 
      </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Remove an existing script tag from a shop</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>DELETE /admin/script_tags/#{id}.json</pre>
 
            <a href="#" class="docs-button-small api-endpoint-example-response-button">View Response</a>
 
          </div>
 
          <div class="api-endpoint-example-response">
 
            <pre>HTTP/1.1 200 OK
 
{}</pre>
 
          </div>
 
        </div>
 
    </div>
 
  </div>
 
  
</html>
+
{}
<br><br><br>
+
</pre>
  
 
== Further Reference ==
 
== Further Reference ==

Latest revision as of 11:38, 14 June 2018

The ScriptTag resource represents remote JavaScript code that is loaded into the pages of a store's shopfront or the checkout pages. This lets you add functionality to these pages without needing to update any theme templates.

Script tags are scoped to the app that created them. When an app is uninstalled from a store, all of the script tags associated with it are automatically removed.

ScriptTag Properties

id
{ "id" : 191 }

A unique numeric identifier for the script tag.

src
{ "src" : "https://js-library.com/widget.js" }

The URL of the remote script that is to be included on the page.

event
{ "event": "onload" }

The DOM event that triggers the loading of the script. Valid values are:

  • onload
display_scope
{ "display_scope": "online_store" }

The page or pages where the script should be included. Valid values are:

  • online_store: Include the script only on the shopfront pages
  • order_checkout: Include the script on the checkout pages
  • all: Include the script on all pages.
created_at
{ "created_at": "2008-07-15T20:00:00-04:00" }

The date and time (ISO 8601 format) when the script tag was created.

updated_at
{ "updated_at": "2008-07-16T20:00:00-04:00" }

The date and time (ISO 8601 format) when the script tag was last updated.

Endpoints

GET /api/script_tags.json

Retrieve a list of all script tags.

Optional Parameters

limit Number of results returned. The default is 30, with a maximum of 50 in a single request.
page The number of the page to return. The number of results per page is set by the limit parameter. If more results are required, then submit the request again, increasing the page number each time.
since_id Limit the results to only include objects which have an id greater than the given value.
src Limit the results to only include script tags with the given source URL.
created_at_min Return only the script tags created after the given date and time. Use the format "2014-12-31 12:00".
created_at_max Return only the script tags created before the given date and time. Use the format "2014-12-31 12:00".
updated_at_min Return only the script tags updated after the given date and time. Use the format "2014-12-31 12:00".
updated_at_max Return only the script tags updated before the given date and time. Use the format "2014-12-31 12:00".
fields A comma-separated list of fields to return in the response.

Example Request and Response

GET /api/script_tags.json

HTTP/1.1 200 OK

{
  "script_tags": [
    {
      "id": 12343,
      "src": "https://test.spiffyserver.com/global/address_finder.js?key=4EK23454567878HMAPNT",
      "event": "onload",
      "display_scope": "order_checkout",
      "created_at": "2017-04-12T17:15:07.873+10:00",
      "updated_at": "2017-04-12T17:15:07.873+10:00"
    }, ...
  ]
}

Examples using filters

GET /api/script_tags.json?fields=id,src,display_scope

GET /api/script_tags/count.json

Return a count of the number of script tags.

Optional Parameters

since_id Limit the results to only include objects which have an id greater than the given value.
src Limit the results to only include script tags with the given source URL.
created_at_min Return only the script tags created after the given date and time. Use the format "2014-12-31 12:00".
created_at_max Return only the script tags created before the given date and time. Use the format "2014-12-31 12:00".
updated_at_min Return only the script tags updated after the given date and time. Use the format "2014-12-31 12:00".
updated_at_max Return only the script tags updated before the given date and time. Use the format "2014-12-31 12:00".

Example Request and Response

GET /api/script_tags/count.json

HTTP/1.1 200 OK

{
  "count": 4
}

GET /api/script_tags/SCRIPT_TAG_ID.json

Retrieves a single script tag by ID.

Optional Parameters

fields A comma-separated list of fields to return in the response.

Example Request and Response

GET /api/script_tags/12343.json

HTTP/1.1 200 OK

{
  "script_tag": {
    "id": 12343,
    "src": "https://test.spiffyserver.com/global/address_finder.js?key=4EK23454567878HMAPNT",
    "event": "onload",
    "display_scope": "order_checkout",
    "created_at": "2017-04-12T17:15:07.873+10:00",
    "updated_at": "2017-04-12T17:15:07.873+10:00"
  }
}

POST /api/script_tags.json

Create a new script tag.

Example Request and Response

POST /api/script_tags.json

{
  "script_tag": {
    "src": "https://js-library.com/widgets.js",
    "event": "onload",
    "display_scope": "online_store"
  }
}

HTTP/1.1 201 Created

PUT /api/script_tags/SCRIPT_TAG_ID.json

Updates a script tag.

Example Request and Response

PUT /api/script_tags/12343.json

{
  "script_tag": {
    "id": 12343,
    "src": "https://another-library.com/new_widget.js"
  }
}

HTTP/1.1 200 OK

DELETE /api/script_tags/SCRIPT_TAG_ID.json

Deletes a script tag.

Example Request and Response

DELETE /api/script_tags/12312.json

HTTP/1.1 200 OK

{}

Further Reference