Question

Using GET in webhook to find usage data in Stripe and add it to Sheets - with a changing URL


Userlevel 1

When retrieving subscription usage data, using metered billing in Stripe, I have to call an URL containing the Subscription Item ID. How do I set up a webhook where I merge the ID into the URL and make it know that it should start with one ID, get the data, and then continue merging the url with the next ID, get the data and so forth?


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

14 replies

Userlevel 7
Badge +14

Hi @Danny Fabricius Fogel 

Good question.

App APIs can be used in Zaps with the Webhooks app.

What Stripe API endpoint are you trying to use? (Provide the link to the documentation.)

 

Userlevel 1

Thanks! Heres the link:-)

https://stripe.com/docs/api/usage_records/subscription_item_summary_list

 

Userlevel 7
Badge +14

@Danny Fabricius Fogel 

Can you provide more examples about the data you are trying to use as part of the Stripe API request so we have more context?

Userlevel 1

This is the URL:

https://api.stripe.com/v1/subscription_items/si_HxZw9nI5cF9mQu/usage_record_summaries

si_HxZw9nI5cF9mQu” is an example of a Subscription Item ID (SI ID).

This is what I get back:

“{
  "object": "list",
  "url": "/v1/subscription_items/si_HxZw9nI5cF9mQu/usage_record_summaries",
  "has_more": false,
  "data": [
    {
      "id": "sis_1DKJ5IBXVOy2SlndSwCc4aBk",
      "object": "usage_record_summary",
      "invoice": "in_1DKIYGBXVOy2SlndfBkBDtwi",
      "livemode": false,
      "period": {
        "end": 1539321672,
        "start": null
      },
      "subscription_item": "si_Dlqmz3K16t9Vdb",
      "total_usage": 123
    },
    {...},
    {...}
  ]
}”

 

The data I need is the “total_usage” and I need that for every single subscription we have on a weekly basis.

I have the SI ID’s in Stripe and Sheets.

I have no idea how to make Zapier find the SI ID and merge it with the URL and make a call per SI ID we have and return the usage data to Sheets.

 

Userlevel 7
Badge +14

@Danny Fabricius Fogel 

You can combine static values and dynamic variables in Zap fields.

This can be used to create dynamic URLs for the Webhook GET request.

Example:

 

Userlevel 7
Badge +14

@Danny Fabricius Fogel 

If you are trying to create a looping Zap that goes thru all the rows of a GSheet, then check out this related topic:

 

Userlevel 1

Thanks, but how do I get the dynamic value before activating the webhook. I need a trigger and I need to get the SI ID in Google Sheets, so I can merge the dynamic values into the static values.

Userlevel 1

@Danny Fabricius Fogel

If you are trying to create a looping Zap that goes thru all the rows of a GSheet, then check out this related topic:

 

Sounds great but what do I write in the required Lookup value, when it should just go through one row at a time?

Userlevel 7
Badge +14

@Danny Fabricius Fogel 

In the Guide it indicates you’ll need a dedicated column that is used as part of the Lookup. (e.g. Done = TRUE/FALSE)

See step 2 and Step 5

 

Userlevel 1

Got it! So now everything seems fine, except I’m not sure how to make it circle back to the trigger. Which data do I use from the final step POST webhook in the CATCH webhook trigger to get it started again? Which fields do i need to update in the POST and CATCH webhooks?

Userlevel 7
Badge +14

@Danny Fabricius Fogel 

In the last Webhook, you need to POST to the Webhook URL from the Zap trigger step.

Best to include a timestamp as a parameter to make the request unique.
https://zapier.com/help/create/customize/insert-the-time-your-zap-runs-into-a-field

Userlevel 1

Amazing! And to restart it I then create a Zap that changes the “Done” column in Sheets back to “no” and then activate the trigger e.g. once a week with a scheduled Zap?

Userlevel 7
Badge +14

@Danny Fabricius Fogel 

Yes once the process is finished you could configure a Zap to change all the DONE=YES to DONE=NO to reset for the following week.

OR you could do this manually (might be a more efficient use of Tasks)

Userlevel 1

Thanks:-)