<?php
$adminToken = "";
$slug = "dish-washing-powder";
$url = "example.com/rest/V1/…";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: Bearer $adminToken", "Content-Type:application/json" ]);
$response = curl_exec($ch);
curl_close($ch);
$products = json_decode($response, true); echo "<pre>";
print_r($products); echo "</pre>";
?>
Not fetching the product details.
Output look like this. I need to use slug instead of sku.
Below is the json I’m getting while running on Postman.
Any help would be appreciated. Thanks in advance
{
"items": [],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "url_key",
"value": "dish-washing-powder/",
"condition_type": "eq"
}
]
}
]
},
"total_count": 0
}
Any help would be appreciated.
My expected output is like the below
{
"id": 391,
"sku": "abc-1",
"name": "dish washing powder",
"attribute_set_id": 4,
"price": 12.68,
"status": 2,
"visibility": 4,
"type_id": "simple",
"created_at": "2020-10-27 11:30:00",
"updated_at": "2024-12-03 04:19:58",
"weight": 0.7,
"extension_attributes": {
"website_ids": [
1
],
Note: I was able to get it as a sku by fetching like this.
https://example.com/rest/V1/products/{sku}
For slug this seems to work – https://example.com/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=url_key&searchCriteria[filterGroups][0][filters][0][value]=my-product-name&searchCriteria[filterGroups][0][filters][0][condition_type]=eq
But can I simplify it more like the sku url.