Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hello,
please how can I get the id product from the webhook product update json response ?
Thanks in advance.
Hey there,
The product ID is included in the product/update webhook request body. See the Webhook reference for more details: here
- Jordan
Jordan | Developer Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi Jordan, yes I try to print in a file the call so I use the following code
webhookContent = "";
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
$webhookContent .= fread($webhook, 4096);
}
fclose($webhook);
$webhookContent = json_decode($webhookContent, true);
$id = $webhookContent['id'];
file_put_contents('webhook.xml', $id); // The id is printed in the file
$pr = new Product($id, $category, $credential, $shop); // at this level the $id is empty
I don't know if I need to use $_GET or $_REQUEST to save the id value in a variable and then use it in "new product"
Thanks in advance.
Hey java2dev,
In what way are you using $id when passing it as an argument in
new Product($id, ...)
If you're trying to set the ID of a new Product, that won't be possible. The ID field is not writable.
- Jordan
Jordan | Developer Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
User | RANK |
---|---|
5 | |
4 | |
4 | |
4 | |
3 |