As an App, how can I programmatically inject javascript into the Order Status page ?

GreatTeam
Visitor
3 0 0

Hello all,

We are struggling with my team to figure out how could we inject javascript into the Order Status page (https://website.myshopify.com/XXX/orders/XXX)

For now all our JS code is in a snippet, included in the theme.liquid file. But if my understanding is correct, the theme.liquid is not used on this Order Status page.

Our objective is to get access to the liquid object order.attribues, to get the details of the products of the order passed and send them in a POST call to our app.

Any hint? 

Many thanks

Replies 2 (2)

diego_ezfy
Shopify Partner
2967 571 900

Please refer to this answer.

sajal_timilsina
Shopify Partner
1 0 0

It is a simple process. There is an feature of RESTAPI to perform CURD operation on script tag. 
https://shopify.dev/docs/api/admin-rest/2024-01/resources/scripttag#get-script-tags
To replicate the steps in POSTMAN,

1 Create a Custom app with script tag permission for Admin API. 


2) Install the app and get the , AAdmin API token. snapt.....

Follow the steps below.

to replicate this request in Postman, follow these steps:

  1. Open Postman and create a new request.

  2. Set the request type to POST.

  3. Enter the request URL: https://your-development-store.myshopify.com/admin/api/2024-01/script_tags.json Replace your-development-store with your Shopify store's development URL.

  4. In the Headers section, add the following key-value pairs:

    • Key: X-Shopify-Access-Token Value: {access_token} Replace {access_token} with your Shopify access token.
    • Key: Content-Type Value: application/json
  5. In the Body section, select the raw option and choose JSON (application/json) as the format.

  6. Copy and paste the JSON payload into the body:

    json
    { "script_tag": { "event": "onload", "src": "https://example.com/my_script.js" } }

    Ensure the JSON payload matches the structure and data you want to send in the request.

  7. Click the Send button to execute the request.

This setup in Postman replicates the cURL command by specifying the request type as POST, setting the URL, adding headers for authentication and content type, and providing the JSON payload in the request body. Adjust the URL, headers, and JSON payload as needed for your specific Shopify script tag creation.

Thanks
Sajal Timilsina | Shopify App Developer