Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Rest Admin API request to get product_id from the handle of product

Rest Admin API request to get product_id from the handle of product

mankirat
New Member
4 0 0

Hello, I was able to use https://<storename>.myshopify/admin/products.json?handle=<handle_name> to get the json data for a particular product using only its handle. But recently, It has been returning an empty dataset. Does anyone know an alternative way to get the product_id from the handle of a product.

Thank you.

Replies 7 (7)

Bunty
Shopify Partner
133 39 83

I can give you 2

https://<storename>.myshopify/products/<handle_name>.js
https://<storename>.myshopify/products/<handle_name>.json

mankirat
New Member
4 0 0
{"errors":{"id":"expected String to be a id"}}

This is the return I am getting from both the requests. 

Thank you for the quick reply. 

Bunty
Shopify Partner
133 39 83

Not exactly sure what you did there but here is a concrete example if I wasn't clear

 

This is a product page

https://www.mollyjogger.com/products/scrimshaw-heirloom-knife-kit

This is the js link

https://www.mollyjogger.com/products/scrimshaw-heirloom-knife-kit.js

This is the json link

https://www.mollyjogger.com/products/scrimshaw-heirloom-knife-kit.json

 

I get correct response for all of the above, let me know how you go.

 

PS: The links will work the same with a Shopify domain, for example

https://mollyjogger.myshopify.com/products/scrimshaw-heirloom-knife-kit.js

 

This returns

{
	"id": 110366610,
	"title": "Scrimshaw Knife Kit",
	"handle": "scrimshaw-heirloom-knife-kit",
	"description": "<meta charset=\"utf-8\">\n<p><span style=\"line-height: 1.2;\">Scrimshaw is an early American art form originating from the whaling industry in the late 1700’s. During the many idle hours at sea, a whaler etched drawings of nautical themes on items that were readily available to him such as sperm whale teeth and bones. His primary etching instrument was a sail needle, nail or pocket knife. After he scratched his art work into the surface of the bone, he would rub lamp black or tobacco juice into the scratch to reveal the drawing. As America traveled west, the frontiersmen carried the art form with them, applying it to their powder-horns, knives and other accoutrements. </span>  <strong data-mce-fragment=\"1\"><a href=\"https://www.pinterest.com/mollyjogger/diy-scrimshaw-kit/\" title=\"Scrimshaw DIY Kit\" data-mce-fragment=\"1\" data-mce-href=\"https://www.pinterest.com/mollyjogger/diy-scrimshaw-kit/\" target=\"_blank\">Checkout the examples from our customers</a></strong></p>\n<p>You can experience this art form too as you scrimshaw the images of a hunt, big catch or simply the family name on your very own bone-handled pocket knife. This kit includes all you'll need to complete the project and is a perfect starter introduction into scrimshaw.</p>\n<p><strong>Choose from knife style:  Trapper (4 1/8” closed) or Lock-back (3 5/8” closed).</strong></p>\n<p><strong>Kit Includes:</strong></p>\n<ul>\n<li>One Natural Bone Handled Pocket Knife (Imported)</li>\n<li>Steel-point Scribe</li>\n<li>Honing Stone <strong>NEW</strong>\n</li>\n<li><span class=\"Apple-style-span\" style=\"font-weight: normal;\">1/2 Dram India Ink</span></li>\n<li>\n<span class=\"Apple-style-span\" style=\"font-weight: normal;\"></span><span class=\"Apple-style-span\" style=\"font-weight: normal;\">Tracing Tool</span>\n</li>\n<li>\n<span class=\"Apple-style-span\" style=\"font-weight: normal;\"></span><span class=\"Apple-style-span\" style=\"font-weight: normal;\">Transfer Paper</span>\n</li>\n<li>\n<span class=\"Apple-style-span\" style=\"font-weight: normal;\"></span><span class=\"Apple-style-span\" style=\"font-weight: normal;\">Fine Steel Wool</span>\n</li>\n<li>\n<span class=\"Apple-style-span\" style=\"font-weight: normal;\"></span><span class=\"Apple-style-span\" style=\"font-weight: normal;\">Ink Applicators</span>\n</li>\n<li>\n<span class=\"Apple-style-span\" style=\"font-weight: normal;\"></span><span class=\"Apple-style-span\" style=\"font-weight: normal;\">Step by Step Instructions and sample graphics</span>\n</li>\n</ul>\n<p><span class=\"Apple-style-span\" style=\"font-weight: normal;\"><span>For ages 16 &amp; up.  Kits are assembled in the USA.</span></span></p>\n<meta charset=\"utf-8\">\n<p> </p>",
	"published_at": "2012-11-07T14:20:00-06:00",
	"created_at": "2012-11-07T14:20:24-06:00",
	"vendor": "Mollyjogger",
	"type": "Gear",
	"tags": [
		"best seller",
		"gifts",
		"Knife"
	],
	"price": 4850,
	"price_min": 4850,
	"price_max": 4850,
	"available": true,
	"price_varies": false,
	"compare_at_price": 4850,
	"compare_at_price_min": 4850,
	"compare_at_price_max": 4850,
	"compare_at_price_varies": false,
	"variants": [
		{
			"id": 19134658055,
			"title": "Lockback Knife",
			"option1": "Lockback Knife",
			"option2": null,
			"option3": null,
			"sku": "",
			"requires_shipping": true,
			"taxable": true,
			"featured_image": {
				"id": 21650923143,
				"product_id": 110366610,
				"position": 2,
				"created_at": "2016-09-29T14:40:41-05:00",
				"updated_at": "2019-01-11T11:51:14-06:00",
				"alt": "scrimshaw lockback lock-back knife mollyjogger kit DIY",
				"width": 2048,
				"height": 1365,
				"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7361.jpg?v=1547229074",
				"variant_ids": [
					19134658055
				]
			},
			"available": true,
			"name": "Scrimshaw Knife Kit - Lockback Knife",
			"public_title": "Lockback Knife",
			"options": [
				"Lockback Knife"
			],
			"price": 4850,
			"weight": 0,
			"compare_at_price": 4850,
			"inventory_quantity": 31,
			"inventory_management": "shopify",
			"inventory_policy": "deny",
			"barcode": "",
			"featured_media": {
				"alt": "scrimshaw lockback lock-back knife mollyjogger kit DIY",
				"id": 2891710487,
				"position": 2,
				"preview_image": {
					"aspect_ratio": 1.5,
					"height": 1365,
					"width": 2048,
					"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7361.jpg?v=1547229074"
				}
			},
			"requires_selling_plan": false,
			"selling_plan_allocations": []
		},
		{
			"id": 436184701,
			"title": "Trapper Knife",
			"option1": "Trapper Knife",
			"option2": null,
			"option3": null,
			"sku": "0016",
			"requires_shipping": true,
			"taxable": true,
			"featured_image": {
				"id": 21650925575,
				"product_id": 110366610,
				"position": 5,
				"created_at": "2016-09-29T14:40:47-05:00",
				"updated_at": "2019-01-11T11:51:14-06:00",
				"alt": "scrimshaw lockback trapper knife mollyjogger kit DIY",
				"width": 2048,
				"height": 1365,
				"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7364.jpg?v=1547229074",
				"variant_ids": [
					436184701
				]
			},
			"available": true,
			"name": "Scrimshaw Knife Kit - Trapper Knife",
			"public_title": "Trapper Knife",
			"options": [
				"Trapper Knife"
			],
			"price": 4850,
			"weight": 0,
			"compare_at_price": 4850,
			"inventory_quantity": 70,
			"inventory_management": "shopify",
			"inventory_policy": "deny",
			"barcode": "",
			"featured_media": {
				"alt": "scrimshaw lockback trapper knife mollyjogger kit DIY",
				"id": 2891808791,
				"position": 5,
				"preview_image": {
					"aspect_ratio": 1.5,
					"height": 1365,
					"width": 2048,
					"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7364.jpg?v=1547229074"
				}
			},
			"requires_selling_plan": false,
			"selling_plan_allocations": []
		},
		{
			"id": 33365139207,
			"title": "Sunfish Knife  (SOLD OUT)",
			"option1": "Sunfish Knife  (SOLD OUT)",
			"option2": null,
			"option3": null,
			"sku": "",
			"requires_shipping": true,
			"taxable": true,
			"featured_image": null,
			"available": false,
			"name": "Scrimshaw Knife Kit - Sunfish Knife  (SOLD OUT)",
			"public_title": "Sunfish Knife  (SOLD OUT)",
			"options": [
				"Sunfish Knife  (SOLD OUT)"
			],
			"price": 4850,
			"weight": 0,
			"compare_at_price": 4850,
			"inventory_quantity": 0,
			"inventory_management": "shopify",
			"inventory_policy": "deny",
			"barcode": "",
			"requires_selling_plan": false,
			"selling_plan_allocations": []
		}
	],
	"images": [
		"//cdn.shopify.com/s/files/1/0156/0327/products/scrimshaw-knife-kit.jpg?v=1547229074",
		"//cdn.shopify.com/s/files/1/0156/0327/products/IMG_7361.jpg?v=1547229074",
		"//cdn.shopify.com/s/files/1/0156/0327/products/ben.scrimshaw.jpg?v=1547229074",
		"//cdn.shopify.com/s/files/1/0156/0327/products/Screen_shot_2014-03-03_at_5.42.21_PM.png?v=1547229074",
		"//cdn.shopify.com/s/files/1/0156/0327/products/IMG_7364.jpg?v=1547229074"
	],
	"featured_image": "//cdn.shopify.com/s/files/1/0156/0327/products/scrimshaw-knife-kit.jpg?v=1547229074",
	"options": [
		{
			"name": "Knife Style",
			"position": 1,
			"values": [
				"Lockback Knife",
				"Trapper Knife",
				"Sunfish Knife  (SOLD OUT)"
			]
		}
	],
	"url": "/products/scrimshaw-heirloom-knife-kit",
	"media": [
		{
			"alt": "scrimshaw knife kit mollyjogger trapper diy",
			"id": 2891677719,
			"position": 1,
			"preview_image": {
				"aspect_ratio": 1.0,
				"height": 1600,
				"width": 1600,
				"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/scrimshaw-knife-kit.jpg?v=1547229074"
			},
			"aspect_ratio": 1.0,
			"height": 1600,
			"media_type": "image",
			"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/scrimshaw-knife-kit.jpg?v=1547229074",
			"width": 1600
		},
		{
			"alt": "scrimshaw lockback lock-back knife mollyjogger kit DIY",
			"id": 2891710487,
			"position": 2,
			"preview_image": {
				"aspect_ratio": 1.5,
				"height": 1365,
				"width": 2048,
				"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7361.jpg?v=1547229074"
			},
			"aspect_ratio": 1.5,
			"height": 1365,
			"media_type": "image",
			"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7361.jpg?v=1547229074",
			"width": 2048
		},
		{
			"alt": "scrimshaw knife kit mollyjogger trapper diy",
			"id": 2891743255,
			"position": 3,
			"preview_image": {
				"aspect_ratio": 1.0,
				"height": 500,
				"width": 500,
				"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/ben.scrimshaw.jpg?v=1547229074"
			},
			"aspect_ratio": 1.0,
			"height": 500,
			"media_type": "image",
			"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/ben.scrimshaw.jpg?v=1547229074",
			"width": 500
		},
		{
			"alt": null,
			"id": 2891776023,
			"position": 4,
			"preview_image": {
				"aspect_ratio": 1.335,
				"height": 445,
				"width": 594,
				"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/Screen_shot_2014-03-03_at_5.42.21_PM.png?v=1547229074"
			},
			"aspect_ratio": 1.335,
			"height": 445,
			"media_type": "image",
			"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/Screen_shot_2014-03-03_at_5.42.21_PM.png?v=1547229074",
			"width": 594
		},
		{
			"alt": "scrimshaw lockback trapper knife mollyjogger kit DIY",
			"id": 2891808791,
			"position": 5,
			"preview_image": {
				"aspect_ratio": 1.5,
				"height": 1365,
				"width": 2048,
				"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7364.jpg?v=1547229074"
			},
			"aspect_ratio": 1.5,
			"height": 1365,
			"media_type": "image",
			"src": "https://cdn.shopify.com/s/files/1/0156/0327/products/IMG_7364.jpg?v=1547229074",
			"width": 2048
		}
	],
	"requires_selling_plan": false,
	"selling_plan_groups": []
}
mankirat
New Member
4 0 0

It does work on the product pages from the domain of the store directly but I does not seem to returning in the myshopify store request. And, I need it on there since I want to get the product_id of a product in draft status and they won't be published on the store url. So, The only way to get those would be through 

https://<storename>.myshopify/admin/products.json but that returns 

{"errors":{"id":"expected String to be a id"}}

 

Bunty
Shopify Partner
133 39 83
https://<storename>.myshopify/admin/products.json

double-check the URL I sent, I don't have /admin/ in them, as I explained, those URLs work with the myshopify domain, it is a Shopify feature

https://shopify.dev/api/ajax/reference/product

mankirat
New Member
4 0 0

https://<storename>.myshopify/admin/products.json works as intended but the handle endpoint does not. And the https://shopify.dev/api/ajax/reference/product is an AJAX API request so I don't think it works the same as a REST API request. Thank you for the help so far.

partner_fitc_ws
Shopify Partner
7 0 0

I know you posted about this a while ago but I eventually found a solution when getting stuck myself so this might help others if not you...

 

https://<storename>.myshopify.com/admin/api/2024-01/products.json?handle=toy-rocking-horse (for all the usual fields)

https://<storename>.myshopify.com/admin/api/2024-01/products.json?handle=toy-rocking-horse&fields=id (if you just wanted the id as you originally asked about)

https://<storename>.myshopify.com/admin/api/2024-01/products.json?handle=toy-rocking-horse&fields=id... (if a subset of the fields was useful by also passing in a comma separated list of values)
(if 
All working as of today