cancel
Showing results for 
Search instead for 
Did you mean: 

webhook_refresh please help

TekkyRex
Deputy Chef I
Deputy Chef I

Hi all,

I’m running into an issue with a webhook trigger in a Workato custom connector. The goal is that every time the webhook refreshes, it should:

  1. Create a new destination

  2. Create a new subscription for that destination

  3. Delete the old destination (which should also remove the old subscription)

Currently, the refresh creates the new destination and subscription correctly, but the old destination is not being deleted, leaving dangling resources. Interestingly, when stopping the recipe, the webhook_unsubscribe deletes the old destination properly.

Here’s a simplified version of my code:

 
# Subscribe lambda
webhook_subscribe: lambda do |webhook_url, connection, _input, _recipe_id|
  # Create initial destination
  destination = call("create_destination", { namespace: "MyConnector.Project", url: webhook_url })

  # Create subscription for that destination
  subscription = post("api/v1/webhook/subscriptions/project", {
    "destinationId" => destination["id"],
    "triggers" => ["Created", "Updated"]
  })

  [
    {
      subscription_id: subscription["id"],
      destination_id: destination["id"],
      webhook_url: webhook_url
    },
    1.minute.from_now
  ]
end,

# Refresh lambda
webhook_refresh: lambda do |webhook_subscribe_output|
  # 1. Create new destination
  new_destination = call("create_destination", {
    namespace: "MyConnector.Project",
    url: webhook_subscribe_output["webhook_url"]
  })

  # 2. Create new subscription
  new_subscription = post("api/v1/webhook/subscriptions/project", {
    "destinationId" => new_destination["id"],
    "triggers" => ["Created", "Updated"]
  })

  # 3. Prepare return value
  refreshed_output = [
    {
      subscription_id: new_subscription["id"],
      destination_id: new_destination["id"],
      webhook_url: webhook_subscribe_output["webhook_url"]
    },
    1.minute.from_now
  ]

  # 4. Attempt to delete old destination (should also delete old subscription) this is a method to call the delete endpoint in the api
  call("delete_destination", webhook_subscribe_output["destination_id"])

  # 5. Return new subscription info
  refreshed_output
end

 

1 ACCEPTED SOLUTION

TekkyRex
Deputy Chef I
Deputy Chef I

For anyone having the same issue, I've found a workaround to force workato to call the delete endpoint. This is a weird workaround and hoping they address this.

    delete_destination = delete("api/v1/webhook/destinations/#{id}")
      
    puts delete_destination  # This is needed to force Workato to call the delete request

 

View solution in original post

1 REPLY 1

TekkyRex
Deputy Chef I
Deputy Chef I

For anyone having the same issue, I've found a workaround to force workato to call the delete endpoint. This is a weird workaround and hoping they address this.

    delete_destination = delete("api/v1/webhook/destinations/#{id}")
      
    puts delete_destination  # This is needed to force Workato to call the delete request