Linking a repository via API

Is this article still valid?

I’m trying to link a repo via API with no such luck. No errors from the API either. Also, this example seems out of touch with the API docs. Also “build_settings” and “repo” seem almost identical in the docs.

Here’s an example:

let site = await client.createSite({
    name: `my-awesome-site`,
    repo: {
      provider: 'github',
      id: 123456789,
      repo: 'my/repo',
      private: true,
      branch: 'dev',
      cmd: './build arg',
      dir: 'build/',
      deploy_key_id: '5ffbd7aa2b73fc74319161a4'
    }
  });

Could you please show me the real layout of the data and the URL you contact and the method you use?

Of course you can elide your real ID and actual repo path, and please don’t post your access token in any format, but I’d like to see it laid out as a URL since that is what I’ll use to reproduce. Here’s an example that works (if you fill in real details). I assert that it matches the article well enough, but more usefully & how I got it so fast: it also matches “what our UI does” as our best API advice described in this article.

POST https://api.netlify.com/api/v1/MY_TEAM_SLUG/sites
with body:

{"account_slug":"MY_TEAM_SLUG",
 "repo":
  {"provider":"github",
   "installation_id":X,
   "id":Y,
   "repo":"MY_GH_LOGIN/MY_REPO_PATH",
   "private":false,
   "branch":"master"
 },
 "default_hooks_data":{}
}

That’s for using the installation_id mentioned in sub-point 2; using deploy keys is a pain in the butt since you have to get them into GitHub so we recommend what is now default on our service and has been for almost 2 years - using the GitHub app.

Anyway, hopefully that pattern and my description of how I got it will help you out with your own call, but if not, please give me the data in that format to help troubleshoot!

“Of course you can elide your real ID and actual repo path, and please don’t post your access token in any format, but I’d like to see it laid out as a URL since that is what I’ll use to reproduce”

I did that. "repo": "my/repo". Maybe this will help.

let site = await client.createSiteInTeam({
    account_slug: 'vi**e',
    repo: {
      provider: 'github',
      installation_id: 989**55,
      id: 299**7238,
      repo: 'ph**y/v***ee',
      private: true,
      branch: 'dev'
    },
    default_hooks_data: {}
  });

Still no luck. No errors from the API. It just creates a site with no repo attached.

Hmm, that isn’t really what I asked for.

I need:

the HTTP method you are using
the URL you are visiting

I’d suggest debugging this as pure URL’s and JSON data rather than within code. Once you get a payload and call that work on their own, you can adapt that into code.

OK I gave you an example of your own SDK which can easily be resolved from the docs. Netlify API documentation

Yes, and I am asking you to do it without that SDK so we can see if there’s a bug in using the raw method.

Good call. That actually worked. Thanks for your time. Seems there’s a bug in the node library.