Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting current Product ID with Shopify API for a Javascript API call

Tags:

shopify

I'm toying with developing a Shopify App that uses the DaisyAPI dynamic image service for Shopify. In order to make the correct call to the Daisy API, I need to know what Product the customer is looking at. It seems like, to reliably do that, I will need to manipulate their product.liquid theme to insert a hidden value containing the Product ID so that Jquery can pick up that value and insert it into the API call.

What's the best way to ensure every product page contains the product ID in such a way jQuery can reliably find it? Am I overlooking something obvious?

Many thanks!

like image 350
Hairgami_Master Avatar asked Aug 24 '12 20:08

Hairgami_Master


People also ask

How do I get product JSON in Shopify?

In order to get started with using Product JSON in Shopify, you will first need to create a private app. You can create a private app by going to the Apps section of your Shopify admin, and then selecting the Manage private apps link. Once you have created your private app, you will be given a API key and API password.

How do I find my Shopify product ID?

In your Shopify Admin, go to Products and choose the product you want. The product_id is the number string at the end of the URL.


2 Answers

Another option would be to use the Ajax API to request the product. Of you know you're on a product page simple make a request to the same URL and append .json. You will then have a json representation of the product that you can do whatever yo want with.

To get you js into the theme you can use a script tag which will load js from you server onto the shop.

like image 145
John Duff Avatar answered Oct 18 '22 20:10

John Duff


You are missing a very obvious and cool Liquid filter.

In Liquid, pump the Object for it's JSON.

var p = {{ product | json }};

And then go to town... you cannot go far on the client without this concept. Get the JSON man.. get the JSON...

like image 33
David Lazar Avatar answered Oct 18 '22 21:10

David Lazar