On checkout completion perform action

On checkout completion perform action

Bhavika1
Shopify Partner
7 0 0

I have created a custom extension for checkout where I have 2 meta fields and now I want the user completes the checkout, I want to hit an API. What is the correct way to do this without the use of webhooks. 

 

Thanks 

Replies 9 (9)

rockstar08
Shopify Partner
5 0 0

You can use the script tags api, which will add your script js file to the website, and you can add any custom js code inside it to trigger any further api request.

Good thing is, the scripts will automatically be removed on plugin unistallation

 

Here is the documentation for this : 

https://shopify.dev/docs/api/admin-rest/2024-07/resources/scripttag

Bhavika1
Shopify Partner
7 0 0

@rockstar08  we have to keep the shopify scripts on some other server I want to do everything from my store only. How is that possible if you have any idea please help.
Thanks

rockstar08
Shopify Partner
5 0 0

Drop your js files into assets folder of your dev shopify or any shopify store you have, and use this liquid code to render the shopify js url:


{{ 'filename.js' | asset_url | script_tag }}

Replace filename.js with your own file name, either add this code in your theme.liquid or header.liquid , once added, you can get the script url from shopify cdn, you can use that url, and remove the code you added to get the dynamic js link.

Try this, I am not sure, if those dynamic links work for long time time or might discontinue, you can try it..
Ref to the code : https://shopify.dev/docs/api/liquid/filters/asset_url

Bhavika1
Shopify Partner
7 0 0

@rockstar08  Okay thanks, Also do you have any idea regarding checkout extension. There I have created 2 custom fields using metafields  and now i want to hit an api after checkout what functions I can use in the script.

If you have any idea then please let me know. 

Thanks

Bhavika1
Shopify Partner
7 0 0

@rockstar08  Okay thanks, Also do you have any idea regarding checkout extension. There I have created 2 custom fields using metafields  and now i want to hit an api after checkout what functions I can use in the script.

If you have any idea then please let me know. 

Thanks

Bhavika1
Shopify Partner
7 0 0

@rockstar08  Okay thanks, Also do you have any idea regarding checkout extension. There I have created 2 custom fields using meta fields  and now I want to hit an API after checkout what functions I can use in the script.

If you have any idea then please let me know. 

Thanks

Bhavika1
Shopify Partner
7 0 0

@rockstar08  Okay thanks, Also do you have any idea regarding checkout extension. There I have created 2 custom fields using meta fields  and now I want to hit an API after checkout what functions I can use in the script.

If you have any idea then please let me know. 

Thanks

Bhavika1
Shopify Partner
7 0 0

@rockstar08 Okay thanks, also do you have any idea regarding checkout extension. There I have created 2 custom fields using meta fields  and now I want to hit an API after checkout what functions I can use in the script.

If you have any idea, then please let me know. 

Thanks

rockstar08
Shopify Partner
5 0 0

in your js script, access the Shopify object, its availaible on the checkout page, and check out for some attributes within that object, if those are available you can hit your api.. to play with the object, enter Shopify in browser console, while you are on the order status completed page.. you can test your code in console before adding to your js...

The best way ideally is placing your code in the Customer Events, using the analytics.subscribe event [https://shopify.dev/docs/api/web-pixels-api/standard-events/checkout_completed].

I am not sure how to aceheive this with shopify app. Any logic you place here, will be triggered by shopify on order completion. Ref : https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/manage