Solved

webhook for the topic "appsubscriptions/update" failing

Web-Stat
Shopify Partner
10 1 1

Hello,

 

I am trying to create a webhook for the topic "app_subscriptions/update" and all I am getting is an error

 

{"errors":"Could not find the webhook topic app_subscriptions\/update"}

 

This is what I am posting:

 

curl -d '{"webhook": { "topic": "app_subscriptions/update", "address": "https://www.web-stat.com/shopifyHook.pl", "format": "json"}}' -H "Content-Type: application/json" -H "X-Shopify-Access-Token: shop_accesstoken" -X POST https://some_shop_url/admin/api/2019-07/webhooks.json

 

I create other webhooks for other topics just fine. It's only "app_subscriptions/update" that causes this error.

 

If anyone has any ideas it would be much appreciated!

 

Thank you 🙂

 

Olivier

Web-Stat

https://www.web-stat.com

 

Accepted Solutions (2)

Josh
Shopify Staff
1134 84 233

This is an accepted solution.

Hello @Web-Stat , 

 

At this time, this type of webhook can only be created with GraphQL mutations. 

 

Here's an example of a fairly basic one that would do the trick : 

 

mutation {
  webhookSubscriptionCreate(topic: APP_SUBSCRIPTIONS_UPDATE, webhookSubscription: {callbackUrl: "https://your-webhook-url.com/webhook", format: JSON}) {
    webhookSubscription {
      id
      callbackUrl
    }
  }
}

Hope it helps! 

Josh | 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 the Shopify Help Center or the Shopify Blog

View solution in original post

Josh
Shopify Staff
1134 84 233

This is an accepted solution.

Hey again Olivier

 

Happy I was able to help! That's.... interesting that you can't see the webhook still though to say the least.

 

I can definitely see the webhook exists on that shop, and it's also tied to an API permission related to your Web-Stat app. Unfortunately outside of that though I can't really test the API responses to see this myself without API access to the shop. All signs point to your webhook being set up working normally though, but if you still run into issues for some reason don't hesitate to post back here and we can find a way to work through this. 

Josh | 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 the Shopify Help Center or the Shopify Blog

View solution in original post

Replies 10 (10)

Josh
Shopify Staff
1134 84 233

This is an accepted solution.

Hello @Web-Stat , 

 

At this time, this type of webhook can only be created with GraphQL mutations. 

 

Here's an example of a fairly basic one that would do the trick : 

 

mutation {
  webhookSubscriptionCreate(topic: APP_SUBSCRIPTIONS_UPDATE, webhookSubscription: {callbackUrl: "https://your-webhook-url.com/webhook", format: JSON}) {
    webhookSubscription {
      id
      callbackUrl
    }
  }
}

Hope it helps! 

Josh | 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 the Shopify Help Center or the Shopify Blog

Web-Stat
Shopify Partner
10 1 1

Thank you so much. Yes, it is very helpful... But I am not quite there yet!

 

Here is what I POST to https://some_shop/admin/api/2019-07/graphql.json (with the proper access token)

 

'mutation {
   webhookSubscriptionCreate(
      topic: APP_SUBSCRIPTIONS_UPDATE,
      webhookSubscription: {
         callbackUrl: "https://www.web-stat.com/shopifyHook.pl",
         format: JSON
      }
   )
   {
      webhookSubscription {
         id
         callbackUrl
      }
   }

}';    

 

And here is the response:

 

{"data":{"webhookSubscriptionCreate":{"webhookSubscription":null}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":2000.0,"currentlyAvailable":1990,"restoreRate":100.0}}}}

 

So the call succeeds, but it seems no new webhook is being created.

 

Any idea what I might still be doing wrong?

 

Olivier

 

Josh
Shopify Staff
1134 84 233

Hey again! 

 

That's interesting, the same mutation works for me. It's also my mistake for not adding userErrors to my query example, there's likely an error message being returned that you're not seeing because it isn't being requested as a return value. 

 

Try this instead and see if it uncovers anything : 

 

mutation {
  webhookSubscriptionCreate(topic: APP_SUBSCRIPTIONS_UPDATE, webhookSubscription: {callbackUrl: "https://www.web-stat.com/shopifyHook.pl",, format: JSON}) {
    webhookSubscription {
      id
      callbackUrl
    }
    userErrors {
      field
      message
    }
  }
}

 

Josh | 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 the Shopify Help Center or the Shopify Blog

Web-Stat
Shopify Partner
10 1 1

Thank you so much for the follow up! I implemented and I now get an error, although it does not tell me much:

 

{"data":{"webhookSubscriptionCreate":{"webhookSubscription":null,"userErrors":[{"field":["webhookSubscription","callbackUrl"],"message":"Address for this topic has already been taken"}]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":2000.0,"currentlyAvailable":1990,"restoreRate":100.0}}}}

 

I am not sure what "Address for this topic has already been taken". I thought maybe it meant that this webhook was already in place and could not be created again? So to verify, I did a GET to https://some_shop/admin/api/2019-07/webhooks.json to see what live webhooks I have (on the same shop) and I get the one for "app/uninstalled" which I created when setting the account up (using my 'default' API method):

 

{"webhooks":[{"id":681402597421,"address":"https:\/\/www.web-stat.com\/shopifyHook.pl","topic":"app\/uninstalled","created_at":"2019-08-15T09:08:33-07:00..."}]}

 

So. as you can see, my APP_SUBSCRIPTIONS_UPDATE is not in there.... And I am not sure what the error message means.

 

Olivier

Web-Stat

 

Josh
Shopify Staff
1134 84 233

Hey again @Web-Stat ! 

 

That error message means that there is already a webhook set up with the same topic and target address. 

 

I am seeing an app_subscriptions/update webhook set up on the same shop in our database, it was created today at 09:49:37 UTC so it looks like at some point one of your requests succeeded. See if you can find the webhook with ID 687546630189 - that should be it!

Josh | 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 the Shopify Help Center or the Shopify Blog

Web-Stat
Shopify Partner
10 1 1

Josh,

 

I think we got this working now, thanks to your patience. The webhooks created OK on all the other accounts.

 

However, what still bothers me is that calls to:

 

https://novedge.myshopify.com/admin/api/2019-07/webhooks/687546630189.json

 

return {"errors":"Not Found"}

 

So the webhook may be created but it is invisible to:

 

/admin/api/2019-07/webhooks/687546630189.json

/admin/api/2019-07/webhooks.json
/admin/api/2019-07/webhooks/count.json

 

I tested all 3.

 

It may be that the hooks are working. I just don't know yet. We will see if our script is getting called or not...

 

Olivier

 

Josh
Shopify Staff
1134 84 233

This is an accepted solution.

Hey again Olivier

 

Happy I was able to help! That's.... interesting that you can't see the webhook still though to say the least.

 

I can definitely see the webhook exists on that shop, and it's also tied to an API permission related to your Web-Stat app. Unfortunately outside of that though I can't really test the API responses to see this myself without API access to the shop. All signs point to your webhook being set up working normally though, but if you still run into issues for some reason don't hesitate to post back here and we can find a way to work through this. 

Josh | 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 the Shopify Help Center or the Shopify Blog

akshuklait
Shopify Expert
6 0 2

Hello Josh, 

can you please elaborate this webhook in detail, like

-> WHEN THIS WEBHOOK TRIGGERS

-> WHAT DATA COMES WITH THIS TRIGGER

mutation {
  webhookSubscriptionCreate(topic:APP_SUBSCRIPTIONS_UPDATE,webhookSubscription:{callbackUrl:"https://execute-api.us-east-2.amazonaws.com/beta/webhook",format:JSON}){
   userErrors{
    field,
    message
  } ,
    webhookSubscription{
      callbackUrl,
      createdAt,
      id,
      topic,
      updatedAt
    }
  }
}

I had supposed it will give data when any app updates billing or add new purchase or un-installs app, then charge canceled data will be fired.
waiting for positive response

estrats
Tourist
6 0 5

It would be nice to be able to create this webhook through the REST API as well.

Seems strange to have to integrate an entirely new technology stack just for a single webhook creation request.

Vint1980
Shopify Partner
1 0 0

Totally agree. Also having only GraphQL way to subscribe brakes normal webhooks through configuration way in shopify_app rails gem.