Question

Why I'm not gettin subscribe id from unsubscribe methos using REST hooks

  • 5 October 2020
  • 6 replies
  • 654 views

Userlevel 1

This is my Subscribe API response output:
{
  "id": 64,
  "name": "Order updated",
  "status": "active",
  "topic": "order.updated",
  "resource": "order",
  "event": "updated",
  "hooks": [
    "woocommerce_update_order",
    "woocommerce_order_refunded"
  ],
  "delivery_url": "https://hooks.zapier.com/fake-subscription-url",
  "date_created": "2020-10-05T07:37:29",
  "date_modified": null
}

But when I’m trying to get subscribe id (Like 64,) Then i am getting empty/undefined id error message.

 params: {
    'webhook_id': bundle.subscribeData.id,

Please help me how to get subscribed id in unsubscribe method


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

6 replies

Userlevel 1

I had the same issue, the documentation is not clear about this at all, but nothing is actually saved in the bundle during a test request.

See here the comment of Zapier staff on Github

I guess the 'solution’ is to test with a static id until you're ready to test a full Zap.

Userlevel 7
Badge +12

Hi @Saharshmittal and @Harley 

Can you post the bit of code that performs the API subscription so I can figure out why it’s not working for you?

Thanks!

Userlevel 7
Badge +9

I recommend just creating a Zap and testing your Resthook’s end to end that way, right away.  Open up the monitoring UI (from the left rail) and watch logs there to troubleshoot. On the whole this is faster and gives you a completely accurate view of the behavior of the system and the transaction.

The test component in the UI for rest hook API config is limited.  When a resthook is created from the actual Zap editor there is an orchestrated interaction with the platform - a listener is set up, state is saved and passed from one invocation to the next, etc.  The test component is not actually doing any of that stuff, and just gives you the ability to test each of those requests in isolation, without getting passed any state from prior requests, as you are seeing.  

It has some utility, but it’s a common source of confusion, so sorry about that.  We’re actually about to remove the test component from the UI for resthooks until we can actually make the behavior reflect the full behavior of the platform.  

Soon to be irrelevant, but more on the tester here: https://platform.zapier.com/docs/faq#how-do-i-define-rest-hooks-and-use-the-embedded-tester-with-them

Userlevel 1

Hi @Saharshmittal and @Harley 

Can you post the bit of code that performs the API subscription so I can figure out why it’s not working for you?

Thanks!

This is my Subcribe code:

const options = {
  url: 'https://'+bundle.authData.kwk_username+'.kwikfunnels.com/kwik-api/create-webhook-subscription',
  method: 'POST',
  headers: {

  },
  params: {
    'consumer_secret': bundle.authData.cs_secrete,
    'consumer_key': bundle.authData.cs_key,
    'name': "Order updated",
    'topic': "order.updated",
    'delivery_url': bundle.targetUrl
  }
}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const not_parsed = response.content.slice(1);
    console.log(not_parsed);
    output = z.JSON.parse(response.content.slice(1));
    

    // You can do any parsing you need for results here before returning them

    return output;
  });


This is my unSubscribe code:

const options = {
  url: 'https://'+bundle.authData.kwk_username+'/kwik-api/remove-webhook-subscription',
  method: 'DELETE',
  headers: {
    'X-KWK-USERNAME': bundle.authData.kwk_username,
    'X-CS-KEY': bundle.authData.cs_key,
    'X-CS-SECRETE': bundle.authData.cs_secrete
  },
  params: {
    'consumer_secret': bundle.authData.cs_secrete,
    'consumer_key': bundle.authData.cs_key,
    'webhook_id': bundle.subscribeData.id,
    'kwk_username': bundle.authData.kwk_username,
    'cs_key': bundle.authData.cs_key,
    'cs_secrete': bundle.authData.cs_secrete
  },
  body: {

  }
}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = response.json;

    // You can do any parsing you need for results here before returning them

    return results;
  });


 

Userlevel 7
Badge +9

What does the payload of the subscribe response look like? I notice you call the field “webhook_id” in the unsubscribe.  That’s making me think maybe that’s what the field holding the id is called in the subscription response and perhaps that’s the name you should be trying to reference rather than “id”?

You must map zapier hooks into your API using targetUrl instead subscriptionData. subscriptionData is empty in both cases.