Netlify golang API CreateSite Call Returning 422 Error

Hello everyone,

I’m encountering a 422 Unprocessable Entity error when using the Netlify API to create a new site. Here’s the code snippet I’m working with:

newSite, err := client.CreateSite(ctx, &models.SiteSetup{
    Site: models.Site{
        AccountSlug:  "my slug",
        Name:         deployment.Netlify,
        CustomDomain: fmt.Sprintf("%s.app.mdfriday.com", deployment.Domain),
        Ssl:          true,
    },
}, true)  // Setting configureDNS to true

The Issue

Each time I call CreateSite, I get a 422 Unprocessable Entity error. I’ve verified that AccountName and AccountSlug are valid, and CustomDomain appears to follow the correct format (for example, example.app.mdfriday.com). I set Ssl: true to enable HTTPS and configured configureDNS as true.

What I’ve Tried

  1. Removing the Ssl field, but the error persists.
  2. Only setting the Name field, without CustomDomain or any additional fields, but still encountering the same error.
  3. Confirming that all parameters align with the API documentation.

Questions

  • Could the 422 error be related to the Ssl or CustomDomain fields?
  • Are there any specific requirements for creating a site that might not be immediately apparent in the documentation?
  • Does configureDNS set to true require any other conditions or dependencies?

Thanks in advance for any guidance or advice you can offer!

1 Like

I found the reason: it was because the site name for deployment was already taken; changing the name resolved the issue.

BTW: I upgrade pkg to v2: github.com/netlify/open-api/v2 v2.34.0

1 Like

Hi, @sunwei welcome to the Netlify community! Thanks for writing in and sharing you found your solution!