Question

Why am I not getting the Subscription Id in my Unsubscribe endpoint using Rest Hook?

  • 1 March 2021
  • 7 replies
  • 52 views

Badge

I have defined Reshooks for subscribe and unbsubscribe. The subscribe endpoint returns the targeturl as a response. I use this url in postman which returns me the subscription id. I then pause My Zap which calls my Unsubscribe Endpoint but the Id is coming as null. Any idea what is wrong here?

Below is my code for Susbcribe Resthook

const options = {
  url: 'baseurl/api/subscription/subscribe',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-API-KEY': bundle.authData.API_Key
  },
  params: {
    'API_Key': bundle.authData.API_Key,
    'url': bundle.targetUrl
  },
  body: {
    'hookUrl': bundle.targetUrl
  }
}

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;
  });

Below is the subscribe api endpoint. I receive the value in the url parameter successfully when I turn on my Zap.

[HttpPost]
        public async Task<string> Subscribe(string url)
        {
                       
            DocumentDBRepository<SubscriptionModel>.Initialize();

            await DocumentDBRepository<SubscriptionModel>.CreateItemAsync(new SubscriptionModel() { type = "Subscribe", response = url});
            return "success";
        
        }

I then trigger the zappier hook url using Postman and I get following response.

{

    "id": "9476aacc-d162-4ed3-8616-db4353657e2e",

    "request_id": "603d52b6-26ac-4b8e-871f-b0ed9d4d1a90",

    "attempt": "603d52b6-26ac-4b8e-871f-b0ed9d4d1a90",

    "status": "success"

}

I then pause my Zap which calls the Unsubscribe endpoint but the Id comes null.

Below is the Code for Unsubscribe Resthook

 

const options = {
  url: 'https://claritywebapi101.azurewebsites.net/api/UnSubscription/UnSubscribe',
  method: 'DELETE',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  params: {
    'id': bundle.subscribeData.id
  },

  body: {
    'hookUrl': bundle.subscribeData.id
  }
}

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;
  });

 

Here is my Unsubscribe api endpoint. Here the id parameter is coming as null when I pause my Zap. Why?

 [HttpDelete]
        
        public async Task<string> UnSubscribe(string id)
        {
            
            await DocumentDBRepository<SubscriptionModel>.CreateItemAsync(new SubscriptionModel() { type = "Unsubscribe", response = id });

            return "Unsubscribed successfully" + id;
        }


7 replies

Userlevel 6
Badge +9

Would you mind posting a sample response from your subscribe API request. The first thing I’d look at is whether the subscription ID is actually in a field called `id` or if it needs to be referenced by a different name?

Badge

I get below url as a response from the subscribe API Endpoint

https://hooks.zapier.com/hooks/standard/9271652/390a032bfc4e4af99330d3324d7a731a/

I trigger this in POSTMAN which sends me  below response

{

    "id": "c71ebe00-83ec-4f4d-80b0-3b43e77fd584",

    "request_id": "603d69f9-e5ba-46cf-931e-4045b4d05800",

    "attempt": "603d69f9-e5ba-46cf-931e-4045b4d05800",

    "status": "success"

}

I then use the “id” as a parameter to call the unsubscribe api endpoint. where the paramter value is null. THe parmeter name is “id” same as what I have configured in the URL Parmas for the unsubscribe endpoint

Userlevel 6
Badge +9

That looks like the response from Zapier to you, when you post a hook message.  I’m looking to see the response from your server to Zapier when you make the subscribe request.  It’s that response where the subscription id should be provided by your service, added to the authData context, and passed to your unsubscribe function.  

Badge

Currently, I do not have a service setup. I am using postman to trigger the zapier hook url and this is the response I get from Postman.

 

{

    "id": "c71ebe00-83ec-4f4d-80b0-3b43e77fd584",

    "request_id": "603d69f9-e5ba-46cf-931e-4045b4d05800",

    "attempt": "603d69f9-e5ba-46cf-931e-4045b4d05800",

    "status": "success"

}

Userlevel 6
Badge +9

That is not the subscription id you need to unsubscribe.  The subscription id is generated by your API and is the id that your unsubscribe implementation needs to identify the subscription in your service that it’s meant to stop.  

In other words if you don’t have your subscribe service set up, your unsubscribe implementation will be impossible to test.

Also, to be clear https://hooks.zapier.com/hooks/standard/9271652/390a032bfc4e4af99330d3324d7a731a/ is not the subscribe endpoint - that’s the hook endpoint.  A subscribe endpoint is hosted on your server and is used to establish a hook subscription for the Zap with your service.  A hook endpoint is where your server sends data when a new event occurs.  The response you see there is our capture endpoint responding and saying it got your message, and will forward the payload to the Zap. 

Badge

@Zane 

As mentioned in my first post, 

Below is the subscribe api endpoint hosted on my server. I receive the value in the url parameter successfully when I turn on my Zap.

[HttpPost]
        public async Task<string> Subscribe(string url)
        {
                       
            DocumentDBRepository<SubscriptionModel>.Initialize();

            await DocumentDBRepository<SubscriptionModel>.CreateItemAsync(new SubscriptionModel() { type = "Subscribe", response = url});
            return "success";
        
        }

Here I am just storing the hookurl sent by Zapier to the database. What Id am I suppose to return from here? 

Badge

I will be writing a windows service to read only the hook url from the database and then trigger that url using httpclient. I do not have the setup for this yet so I used  the postman client to execute the hook url returned by zapier which returns the id in the response object. I then paused that zap which calls the unsubscribe endpoint of my service but then the Id is null in it.

Reply