How to get product Information by Product ID ?

How to get product Information by Product ID ?

masumluf
Excursionist
38 0 9

Hello Is there any API exist to get product details like price by productID ?

Replies 8 (8)

ReturnPrime
Shopify Partner
488 67 111

Hi @masumluf ,

Hope you are doing well.

 

You can use the below mentioned API to fetch the product details using product id.

https://shopify.dev/api/admin-rest/2022-04/resources/product#get-products-product-id

 

Please mark it as a solution and leave a like if you find it helpful.

 

Cheers!!

Shubham

Return Prime

masumluf
Excursionist
38 0 9

My api request will come from a store front , so I can not generate access token , i need to call another api to generate api token. so this method wont help me. but I found a solution in another way. 

ReturnPrime
Shopify Partner
488 67 111

That is great!

 

Could you share that solution here as well so it will help others who might need it? 🙂

Sha_Hassan
Shopify Partner
12 0 4

Use the below code to get the product information by product id

{% assign product_id = param | times: 1 %}
{% assign products_obj = collections.all.products | where: 'id', product_id %}
{% assign product = products_obj[0] %}


Where param is your product id. Let me know if that's work for you

farreal
Shopify Partner
12 0 5

@Sha_Hassan This works perfectly for what I needed!

Sha_Hassan
Shopify Partner
12 0 4

Perfect, @masumluf did it work for you as well?

MaxDesign
Shopify Partner
214 15 89

This method is limited to 50 iterations, therefore it will only check for the 50 first products of the collection. In other words: it might not work.

I think you could still do:

{% paginate collections.all.products by 1000 %}
  {% assign product_id = param | times: 1 %}
{% assign products_obj = collections.all.products | where: 'id', product_id %}
{% assign product = products_obj[0] %} {% endpaginate %}

But this is a "trick" and if the collection starts to get too big this could make performances worst, so use with caution.

Reach out to me at admin@maxdesign.expert
buildpath
Shopify Partner
59 11 21

Yes please share the solution you found 

Ecom entrepreneur since 2004 | Shopify App developer since 2021 | Shopify merchant and theme developer since 2016