I am trying to access a specific product using its id from the below url,
https://tempstore.myshopify.com/products/1234.json
Its giving me 404 error.
Although, I am able to access all products as below:
https://tempstore.myshopify.com/products.json
I have to access the product which was just processed in checkout process.
I have its id as below:
var products = Shopify.checkout.line_items;
products will contain an array of product id’s only which are processed in checkout.
Now I need to access all other properties of these products.
I can surely do this:
https://tempstore.myshopify.com/admin/products/1234.json
But it requires Authentication.
Any thoughts?
2
Answers
This is how I solved it, If it helps anybody :)
From the frontend, you need to have the product handle to get the JSON object:
or
(Note that the returned values from the
.js
and.json
endpoints are quite different from each other!)Like you point out, the Shopify.checkout.line_items array of objects only has the product IDs, not the product handles. We’re not completely out-of-luck, though, because we can get the entire list of products in the store including the product handles by hitting the
/products.json
endpoint.Of course, this means grabbing a potentially huge JSON object just to get information that we should’ve had included in the checkout line items… but unless there’s some alternate source of the line item information available on the checkout page, looping through the entire list may be what you need to do.
So your end code would look something like this:
Hope this helps!