# ScriptTag <div class="note"><h4>Theme app extensions</h4> <p>Your app might not pass App Store review if it uses script tags instead of theme app extensions. All new apps, and apps that integrate with Online Store 2.0 themes, should use theme app extensions, such as app blocks or app embed blocks. Script tags are an alternative you can use with only vintage themes. <a href="/apps/online-store#what-integration-method-should-i-use" target="_blank">Learn more</a>.</p></div> <p>The ScriptTag resource represents remote JavaScript code that is loaded into the pages of a shop's storefront or the order status page of checkout. This lets you add functionality to those pages without using theme templates.</p> <p>Script tags are scoped to the app that created them. When an app is uninstalled from a shop, all of the script tags that it created are automatically removed along with it.</p> ## Resource Properties ### ScriptTag * created_at: The date and time (<a href='http://en.wikipedia.org/wiki/ISO_8601' target="_blank">ISO 8601</a>) when the script tag was created. * Type: x-string * Example: "2012-08-24T14:01:47-04:00" * event: The DOM event that triggers the loading of the script. Valid values: <code>onload</code>. * Type: x-string * Example: "onload" * id: The ID for the script tag. * Type: x-string * Example: 596726825 * src: The URL of the remote script. * Type: x-string * Example: "https://js.example.org/foo.js" * display_scope: The page or pages on the online store where the script should be included. Valid values: <ul> <li><code>online_store</code>: Include the script only on the web storefront.</li> <li><code>order_status</code>: Include the script only on the order status page.</li> <li><code>all</code>: Include the script on both the web storefront and the order status page.</li> </ul> * Type: x-string * Example: "online_store" * cache: Whether the Shopify CDN can cache and serve the script tag. Valid values: <ul> <li><code>true</code>: The script will be cached and served by the CDN. The cache expires 15 minutes after the script tag is successfully returned.</li> <li><code>false</code>: The script will be served as is.</li> </ul> Default value: <code>false</code>. * Type: x-string * Example: true * updated_at: The date and time (<a href='http://en.wikipedia.org/wiki/ISO_8601' target="_blank">ISO 8601</a>) when the script tag was last updated. * Type: x-string * Example: "2012-08-24T14:01:47-04:00" ## Retrieves a list of all script tags Retrieves a list of all script tags. <strong>Note:</strong> This endpoint implements pagination by using links that are provided in the response header. To learn more, refer to <a href='/api/usage/pagination-rest'>Make paginated requests to the REST Admin API</a>. ### Endpoint /admin/api/#{api_version}/script_tags.json (GET) ### Parameters * api_version (required): * created_at_max: Show script tags created before this date. (format: 2014-04-25T16:15:47-04:00) * created_at_min: Show script tags created after this date. (format: 2014-04-25T16:15:47-04:00) * fields: A comma-separated list of fields to include in the response. * limit: The number of results to return. * since_id: Restrict results to after the specified ID. * src: Show script tags with this URL. * updated_at_max: Show script tags last updated before this date. (format: 2014-04-25T16:15:47-04:00) * updated_at_min: Show script tags last updated after this date. (format: 2014-04-25T16:15:47-04:00) ### Responses #### 200 Retrieves a list of all script tags Examples: ##### Retrieve a list of all script tags Request: ``` GET /admin/api/unstable/script_tags.json ``` Response: ``` HTTP/1.1 200 OK {"script_tags":[{"id":421379493,"src":"https://js.example.org/bar.js","event":"onload","created_at":"2025-01-02T11:09:43-05:00","updated_at":"2025-01-02T11:09:43-05:00","display_scope":"all","cache":false},{"id":596726825,"src":"https://js.example.org/foo.js","event":"onload","created_at":"2025-01-02T11:09:43-05:00","updated_at":"2025-01-02T11:09:43-05:00","display_scope":"all","cache":false}]} ``` ##### Retrieve a list of all script tags after the specified ID Request: ``` GET /admin/api/unstable/script_tags.json ``` Response: ``` HTTP/1.1 200 OK {"script_tags":[{"id":596726825,"src":"https://js.example.org/foo.js","event":"onload","created_at":"2025-01-02T11:09:43-05:00","updated_at":"2025-01-02T11:09:43-05:00","display_scope":"all","cache":false}]} ``` ##### Retrieve a list of all script tags with a particular URL Request: ``` GET /admin/api/unstable/script_tags.json ``` Response: ``` HTTP/1.1 200 OK {"script_tags":[{"id":596726825,"src":"https://js.example.org/foo.js","event":"onload","created_at":"2025-01-02T11:09:43-05:00","updated_at":"2025-01-02T11:09:43-05:00","display_scope":"all","cache":false}]} ``` ## Creates a new script tag Creates a new script tag ### Endpoint /admin/api/#{api_version}/script_tags.json (POST) ### Parameters * api_version (required): ### Responses #### 201 Creates a new script tag Examples: ##### Create a new script tag Request: ``` POST /admin/api/unstable/script_tags.json {"script_tag":{"event":"onload","src":"https://example.com/my_script.js"}} ``` Response: ``` HTTP/1.1 201 Created {"script_tag":{"id":870402688,"src":"https://example.com/my_script.js","event":"onload","created_at":"2025-01-02T11:11:00-05:00","updated_at":"2025-01-02T11:11:00-05:00","display_scope":"all","cache":false}} ``` #### 422 Creates a new script tag Examples: ##### Creating a script tag without a src and event will return an error Request: ``` POST /admin/api/unstable/script_tags.json {"script_tag":{"body":"foobar"}} ``` Response: ``` HTTP/1.1 422 Unprocessable Entity {"errors":{"src":["can't be blank","must be secure (HTTPS)"],"event":["can't be blank","is invalid"]}} ``` ## Retrieves a count of all script tags Retrieves a count of all script tags ### Endpoint /admin/api/#{api_version}/script_tags/count.json (GET) ### Parameters * api_version (required): * src: Count only script tags with a given URL. ### Responses #### 200 Retrieves a count of all script tags Examples: ##### Retrieve a count of all script tags for your shop Request: ``` GET /admin/api/unstable/script_tags/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":2} ``` ## Retrieves a single script tag Retrieves a single script tag ### Endpoint /admin/api/#{api_version}/script_tags/{script_tag_id}.json (GET) ### Parameters * api_version (required): * script_tag_id (required): * fields: A comma-separated list of fields to include in the response. ### Responses #### 200 Retrieves a single script tag Examples: ##### Retrieve a single script tag by its ID Request: ``` GET /admin/api/unstable/script_tags/596726825.json ``` Response: ``` HTTP/1.1 200 OK {"script_tag":{"id":596726825,"src":"https://js.example.org/foo.js","event":"onload","created_at":"2025-01-02T11:09:43-05:00","updated_at":"2025-01-02T11:09:43-05:00","display_scope":"all","cache":false}} ``` ## Updates a script tag Updates a script tag ### Endpoint /admin/api/#{api_version}/script_tags/{script_tag_id}.json (PUT) ### Parameters * api_version (required): * script_tag_id (required): ### Responses #### 200 Updates a script tag Examples: ##### Update a script tag's URL Request: ``` PUT /admin/api/unstable/script_tags/596726825.json {"script_tag":{"id":596726825,"src":"https://somewhere-else.com/another.js"}} ``` Response: ``` HTTP/1.1 200 OK {"script_tag":{"src":"https://somewhere-else.com/another.js","cache":false,"id":596726825,"event":"onload","created_at":"2025-01-02T11:09:43-05:00","updated_at":"2025-01-02T11:11:04-05:00","display_scope":"all"}} ``` ## Deletes a script tag Deletes a script tag ### Endpoint /admin/api/#{api_version}/script_tags/{script_tag_id}.json (DELETE) ### Parameters * api_version (required): * script_tag_id (required): ### Responses #### 200 Deletes a script tag Examples: ##### Delete an existing script tag Request: ``` DELETE /admin/api/unstable/script_tags/596726825.json ``` Response: ``` HTTP/1.1 200 OK {} ```