Difference between revisions of "API ScriptTag"

From Spiffy Stores Knowledge Base

Line 101: Line 101:
 
}
 
}
 
</style>
 
</style>
 +
</html>
  
 +
<span class="api-endpoint-request"><span class="api-endpoint-request-type api-endpoint-request-type-get">GET</span> /admin/script_tags.json </span>
  
<span class="api-endpoint-request">
+
{| class="wikitable" style="width: 100%"
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
+
|style="width: 30%"|limit
        GET
+
|<p>Amount of results</p>(default: 50) (maximum: 250)
      </span>
+
|-
      /admin/script_tags.json
+
|page
    </span>
+
|Page to show (default: 1)
    <div class="api-endpoint-description">
+
|-
    </div>
+
|since_id
    <div class="api-endpoint-contentx">
+
|Restrict results to after the specified ID
      <div class="api-endpoint-queryparameters">
+
|-
        <table>
+
|created_at_min
          <tbody>
+
|Show script_tags created after date (format: 2014-04-25T16:15:47-04:00)
              <tr>
+
|-
                <td>limit</td>
+
|created_at_max
                <td>
+
|Show script_tags created before date (format: 2014-04-25T16:15:47-04:00)
                    <p>Amount of results</p>
+
|-
                  (default: 50)
+
|updated_at_min
                  (maximum: 250)
+
|Show script_tags last updated after date (format: 2014-04-25T16:15:47-04:00)
                </td>
+
|-
              </tr>
+
|updated_at_max
              <tr>
+
|Show script_tags last updated before date (format: 2014-04-25T16:15:47-04:00)
                <td>page</td>
+
|-
                <td>
+
|src
                    <p>Page to show</p>
+
|Show script tags with a given URL
                  (default: 1)
+
|-
                </td>
+
|fields
              </tr>
+
|comma-separated list of fields to include in the response
              <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;: [
 
    {
 
      &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 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 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>
 
        </div>
 
    </div>
 
  </div>
 
  <div id="create" class="api-endpoint">
 
    <span class="api-endpoint-request">
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
 
        POST
 
      </span>
 
      /admin/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;: {
 
    &quot;src&quot;: [
 
      &quot;can&#39;t be blank&quot;,
 
      &quot;Source must be secure (HTTPS)&quot;
 
    ],
 
    &quot;event&quot;: [
 
      &quot;can&#39;t be blank&quot;,
 
      &quot;is not included in the list&quot;
 
    ]
 
  }
 
}</pre>
 
          </div>
 
        </div>
 
        <div class="api-endpoint-example">
 
          <h3 class="api-endpoint-example-title">Create a new script tag</h3>
 
          <div class="api-endpoint-example-request">
 
              <pre>POST /admin/script_tags.json</pre>
 
              <pre>{
 
  &quot;script_tag&quot;: {
 
    &quot;event&quot;: &quot;onload&quot;,
 
    &quot;src&quot;: &quot;https:\/\/djavaskripped.org\/fancy.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 201 Created
 
{
 
  &quot;script_tag&quot;: {
 
    &quot;id&quot;: 870402689,
 
    &quot;src&quot;: &quot;https:\/\/djavaskripped.org\/fancy.js&quot;,
 
    &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>
 
    </div>
 
  </div>
 
  <div id="update" class="api-endpoint">
 
    <span class="api-endpoint-request">
 
      <span class="api-endpoint-request-type api-endpoint-request-type-get">
 
        PUT
 
      </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">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>
 
<br><br><br>
  

Revision as of 11:10, 19 May 2017

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




Further Reference