Get Id of awebhook product update

java2dev
New Member
14 0 0

Hello,

  please how can I get the id product from the webhook product update json response ?

Thanks in advance.

Replies 3 (3)
Jordan
Shopify Staff
Shopify Staff
300 3 74

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

java2dev
New Member
14 0 0

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.

Jordan
Shopify Staff
Shopify Staff
300 3 74

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