[Support Guide] Linking a repository via API

Hi you can manage your deploys (turning them off) or private your site if you don’t want a deploy to showcase. Here is some documentation how to accomplish this.

The documentation you linked is to manage the deploys from the UI, but I’m creating and managing the sites programmatically, so I’m looking for a way to avoid deploying automatically when the site is created through the REST API.

You can first create a site (simply creating a site should not trigger a deploy) → Add environment variables → then connect a repo.

That worked. Thanks!

glad to hear it! thanks for writing back in and sharing this with the community. cheers! :rocket:

Why can’t we put together in a dedicated document page? There are inconsistent attribute names like repo_id or id which is shown in the API reference. I followed the same step, but can’t seem to link the git repo in Netlify. I was able to create site but no git attached.

{
  "name": "igendoc-documentation",
  "account_slug": "tungxd96",
  "repo": {
    "branch": "main",
    "cmd": "npm run build",
    "installation_id": 52****01,
    "dir": "build",
    "is_private": false,
    "provider": "github",
    "repo": "igendoc-web-client/tungxd96-igendoc-documentation-web",
    "id": 825****54,
    "repo_id": 825****54,
    "deploy_key_id": "6689d************3508e27"
  },
  "default_hooks_data": null,
  "build_settings": {
    "installation_id": 52558801,
    "dir": "build",
    "cmd": "npm run build"
  }
}

it worked only if i created a site first, waited for about 30 seconds, then updated site with repo. Is this expected? It’s unpredictable because you don’t know how long you have to wait before updating your site with repo.

The steps in the original post should still work. Did you try to compare the data you were sending against the data Netlify UI sends?

curl worked just fine, but not RestTemplate in spring java. Payload that worked in curl

{
    "name": "random-120937",
    "repo": {
      "id": 12309***12,
      "provider": "github",
      "repo": "your_repo",
      "branch": "main",
      "private": false,
      "installation_id": 52****31,
        "dir": "build",
        "cmd": "npm run build"
    }
  }

Hi, @tungxd96. That proves that your Java code is not sending an identical request to what curl is sending. You’ll need to debug your Java code until it matches the curl format at which point it will work.

We don’t provide technical support for Java apps so debugging that Java code is up to you to do.

1 Like

Thanks. I solved it in Java. I used @JsonProperty annotations for the snake_case names while maintaining camelCase for the attribute names. However, RestTemplate serialization kept the camelCase names, so I had to serialize the request body to a string to use the snake_case convention from @JsonProperty, and it worked.

hi thanks for writing back in and sharing your solution with the community!