Create / update site with a given name

I try to create a new site with a post request using: POST https://api.netlify.com/api/v1/sites
with body:

{
    "name": "whateversitename"
}

I get a new site, but with a random name.

If I try to update the site using: PATCH https://api.netlify.com/api/v1/sites/<site-id>

with body:

{
    "name": "whateversitename"
}

And I get a 200 back, but not a name change.

I even tried with body:

{
    "name": "whateversitename",
    "url": "http://whateversitename.netlify.app",
    "admin_url": "https://app.netlify.com/sites/whateversitename",
    "ssl_url": "https://whateversitename.netlify.app"
}

but nothing happens!

How can I rename a site using the API, or directly create a correctly named site?

Hey @svdoever! :wave:t2:

Try a PUT instead of a PATCH :slight_smile: should work for updating the site name.

Not sure you can specify a name on new site creation though, I think the plumbing may be made to assign a random name at the onset.

Hope that helps!


Jon

I tried this, didn’t work
Is there another way to go about this, or maybe a link to an article that can help out please

@Mainkind I’m not sure if you’re trying to “create a site with a given name” or “update the name of a site” as you haven’t mentioned, but there’s this blog article for site creation:

In case you haven’t already been browsing the documentation…

The createSite documentation is here:

The updateSite documentation is here:

Hi @Mankind , what happens when you try to update this?

Here is the payload:
{ name: "sitenamebymankind" }

To this endpoint: https://api.netlify.com/api/v1/sites/{{site_id} - {PUT & PATCH}

Then it returns a 200 Ok response, with an object containing all the details of the site with the old name, nothing changes

hi @Mankind

You seem to be running the right steps. We tested this and it works with both PUT and PATCH.

Can you please walk me through the steps you’re taking to achieve this?

Feel free to add screenshots if that helps!