Clear cache with webhook

I wonder if there is a way to trigger a build with cached clear other than the button in the app.

I’d like to run a request to a webhook everyhour, or via a link so we can manually refresh the cash. Maybe there is an environment variable I am not aware of?

2 Likes

Hi @regisphilibert,

There isn’t a webhook for it, but you should be able to using our API. I recommend checking the dev tools when you click that deploy button and you can see the API call that our app makes to trigger a build with clear cache.

2 Likes

Perfect! Thanks @futuregerald.

2 Likes

You’re welcome, Buddy!

Hi @futuregerald ,

Are there any plans on having an option for a webhook to clear the cache before building?

For some reason, my build only works when the cache is cleared & I want to be able to set up a Contentful <> Netlify integration using the webhook.

Thanks!

As @futuregerald mentioned, there is no webhook but there is an API endpoint for it. Perhaps you could set up a Lambda function that calls this API and then the build hook?

I can’t seem to find the query params for clearing cache on a build/deploy? Also not sure whether to use the build or deploy API?

Kindly

Hey @nikolajfrey,

Here you go:

fetch('https://api.netlify.com/api/v1/sites/<site-id>/builds', {
  body: {
    clear_cache: true
  },
  headers: {
    authorization: 'Bearer <token>',
    'content-type': 'application/json'
  },
  method: 'post'
})
1 Like

Could you tell me where I can get the authorization token? I can get it from dev tools when I click the deploy button, but I’m not sure how long it can be kept.

Hey @josie

As outlined in this documentation you can generate a code in your user settings via https://app.netlify.com/user/applications#personal-access-tokens

Thanks very much!!!

Big help :love_you_gesture:

We also need to send a message/title along with the build. Can’t find any info on accepted parameters in the body payload? Like the “clear_cache”.

Would appreciate any pointers!

Hey @Skaevt_Reklamebureau,

Could you clarify what exactly are you trying to use message for? From what I’m aware, only deploys from Git with a commit message get a message displayed in the UI.

@hrishikesh

In our setup - multiple API’s trigger builds (when external data changes and needs to be fetched in our jamstack) and therefor it would be very helpful to have that printed out within the Netlify deployment UI. Example: Triggered by Shopify

It’s actually been exactly like that when using build hooks, however it’s not possible to forcefully clear cache and that unfortunately needs to happen.

Hey @Skaevt_Reklamebureau,

As far as I’m aware, this is not currently possible. But, we’re trying to confirm this with our engineers and would let you know as soon as we have more information.

1 Like

Hey @Skaevt_Reklamebureau,

As per the confirmation we’ve received, it’s not possible to set a title when using API to trigger build unfortunately.

1 Like

Oh that’s unfortunate. We’ll setup our own log then.
Thanks a lot for taking the time. Appreciate it!