Deploy previews setting via netlify API

I’m using the API to setup a site with ‘createSiteInTeam’.

“Automatically build deploy previews for all pull requests” is enabled by default. Can I set this to “Don’t build deploy previews for pull requests” via the api?

Hello @sanscheese, that is definitely possible via our API. Since our UI uses our API, I recommend that you take a look at how our UI does it. You can check out the following post on how to do that: [Support Guide] Understanding and using Netlify's API.

1 Like

Hey Dennis,

Good advice! However, I’m still not able to disable deploy preview via the Netlify API when creating a new site.

I used Postman to examine the JSON of a single Netlify site in two states - deploy previews enabled and disabled. This helped me find the key-value pair apparently responsible for this setting:

"build_settings": {
    "skip_prs": true
}

The above JSON indicates a site with deploy previews disabled (i.e. “skip previews”).

However, when I feed that into the body of my API calls, it has no effect on the newly created site and deploy previews are still always on.

Here’s the body of attempt 1:

{
  "name": "prevent deploy previews",
  "custom_domain":"REDACTED",
  "notification_email": "REDACTED",
  "managed_dns": true,
  "repo":{
	"provider":"github",
	"id": REDACTED,
	"repo":"REDACTED",
	"private":true,
	"branch":"development",
	"cmd":"npm run build",
	"dir":"build/",
	"base": "front-end/",
	"deploy_key_id":"REDACTED",
	"skip_prs": true
  }
}

Here’s the body of attempt 2:

{
  "name": "prevent deploy previews 2",
  "custom_domain":"REDACTED",
  "notification_email": "REDACTED",
  "managed_dns": true,
  "repo":{
	"provider":"github",
	"id": REDACTED,
	"repo":"REDACTED",
	"private":true,
	"branch":"development",
	"cmd":"npm run build",
	"dir":"build/",
	"base": "front-end/",
	"deploy_key_id":"REDACTED"
  }
  "build_settings":{
	"skip_prs": true
  }
}

Neither of those worked, and the Netlify API schema for createSite doesn’t appear to have any reference to the skip_prs option. So I’m at a loss for how to generate a new site via the Netlify API with deploy previews disabled.

This is starting to cause major problems for our organization, because we’re programmatically generating dozens of new sites each week. And with all these sites generating deploy previews, we’re getting a massive deployment queue each time we have a new PR, which is causing delays in our development pipeline.

Hoping you or someone on here can provide a viable means of disabling deploy previews via the Netlify API! Thanks for your help!

Best,
-Noah

As the article Dennis linked mentions, our open-api spec is not completely up to date, and thus following our UI’s methods closely is the way to go.

So - you shouldn’t need postman to test our UI as a start; you should be watching our UI as you set the “skip PR’s” flag, and using THAT call instead. For me it looks like this:

HTTP PUT https://api.netlify.com/api/v1/sites/YOUR_SITE_ID

with a body of:

{build_settings: {branch: "master", allowed_branches: [], skip_prs: true}}

This is an example of “master” being my production branch, and me allowing builds on all branches, but the data will vary if you limit builds to certain branches or use a different production branch :slight_smile:

2 Likes

Thanks Chris.

Didn’t realize I could see the API calls right in the Network tab of my browser’s dev tools. Just assumed those API calls were proxied! But that’s much easier than Postman, so should be good to go moving forward.

We were already able to implement that PUT request on our project! :+1:

Hi @noerbot , @fool,
can I set this {“skip_prs”: true} while creating the site?
I wanted to set this attribute while creating the site and save the cost of extra PUT request like
HTTP POST https://api.netlify.com/api/v1/sites
I have tried it setting this payload
{build_settings: {branch: "master", allowed_branches: ["master" ], skip_prs: true}}
but I’m still getting this

hi there @BilalShabbir - sorry to be slow to reply. we are still hoping to get some answers for you on this!

Hi @perry, please do, I am hoping for your reply too…

Hi @perry, any update on my query?

Hi, @BilalShabbir. I’ve done extensive testing of this and it isn’t possible to set that setting with the original site creation API call. It does take a second API call to change that after the site exists.

If there are other questions about this, please let us know.

3 Likes

Hi @luke, thanks for your reply. I appreciate your effort.
BTW if you see response from both APIs, its same, so this feature should be available in the original site creation api (POST).
anyway thanks for your response

1 Like