Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
/*webhook*/ $chh = curl_init(); $params = [ 'webhook' => [ 'topic' => 'app/uninstalled', 'address' => 'https://example.herokuapp.com/delete.php', 'format' => 'json' ] ]; $json_string_params = json_encode($params); $headers = array( 'X-Shopify-Access-Token:'.$access_token, 'Content-Type:application/json' ); curl_setopt($chh, CURLOPT_URL, 'https://example.myshopify.com/admin/webhooks.json'); curl_setopt($chh, CURLOPT_HTTPHEADER, $headers); curl_setopt($chh, CURLOPT_HEADER, false); curl_setopt($chh, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($chh, CURLOPT_POSTFIELDS, $json_string_params); curl_setopt($chh, CURLOPT_RETURNTRANSFER, true); $resultt = curl_exec($chh); $final = json_decode($resultt); /*webhook*/
This is my code and. After firng this one i'm getting below response but still webhook not registered.
stdClass Object ( [webhook] => stdClass Object ( [id] => 475440480367 [address] => https://example.herokuapp.com/delete.php [topic] => app/uninstalled [created_at] => 2019-01-18T05:04:20-05:00 [updated_at] => 2019-01-18T05:04:20-05:00 [format] => json [fields] => Array ( ) [metafield_namespaces] => Array ( ) ) )
Can anyone review my code?
Solved! Go to the solution
Hi,
Have you queried the webhooks endpoint to check i.e. GET /admin/webhooks.json ? Webhooks created by your app do not show up in admin UI as they're bound to your app, not the "admin app".
Sadly I cannot offer any review on PHP because I am not a PHP developer, though looking at the cURL it all looks okay. So above is just a suggestion to double check.
Best wishes!
yes, i did queried as you specified.
But its still not showing our registered webhooks in json format. It shows only from the admin side manually.
Any possibilities?
Strange because the response you mention clearly shows the webhook ID so I'd assume it was created successfully. Could you try the same POST operation using a REST client such as Postman or Insomnia, using the same API credentials as your app and making sure you have cookies disabled in your request - just to narrow down the possibilities whether it's the API request itself, or maybe something in the PHP client request.
I tried in Postman also. But result was same!
i don't know wthat to do now!
So again, just to confirm, POST /admin/webhooks.json with
{ "webhook": { "topic": "app/uninstalled", "address": "https://test.requestcatcher.com/", "format": "json" } }
via a REST client doesn't work?
I've just tested the endpoint and was able to create and confirm the webhook was registered.
If you're still having no luck with any of that, I suggest you post the X-Request-Id from your response header so that Shopify staff can look in to the details of the request.
OK i'm getting you in REST. Can you post your flow with you've tried!.
No special flow, just 1 single request like I posted above.
i'm firing with this flow.
https://{username}:{password}@{shop}.myshopify.com/admin/webhooks.json
Is it correct?
curl --request POST \ --url https://store.myshopify.com/admin/webhooks.json \ --header 'authorization: Basic XXXXXXX' \ --header 'content-type: application/json' \ --data '{ "webhook": { "topic": "app/uninstalled", "address": "https://test.requestcatcher.com/", "format": "json" } }'
This is an accepted solution.
Hey now it's working like a charm, I've checked with the request catcher and I got a response. But still, one thing is remaining that now I've to get that response in my app file e.g. /delete.php. So for that, I'm finding receiving the code if you can help me with that it'd be Veeery appreciable for me. :))))
Hey again. Sorry, but I cannot help you out with PHP because it's simply not a language I know.
The process of creating a webhook handler on your side is pretty straightforward:
General advice and gotchas for webhooks are:
During development use any of the free or paid localhost tunnelers. Makes life easier.
Good luck!
Hello @Pratham_Jani & @KarlOffenberger,
We are having the same problem where webhook API is giving response with webhook id, But when we open let's say examplestore/admin/webhooks.json, At there, the webhook array is empty and our webhook is not registered. I have written about this issue in this forum https://community.shopify.com/c/Shopify-APIs-SDKs/Shopify-webhook-api-is-giving-response-but-not-reg....
If you have overcome the problem, It would be really kind of you to help us with this, Right now we are stuck in it and clueless.
Awaiting your response. Thanks