Vercel DNS SDK - cannot create CNAMES

I’m attempting to create a CNAME DNS record using the Vercel SDK.

The docs show that you call vercel.dns.createRecord({}) with a property called https to create a CNAME, but this doesn’t work.

Instead, it looks like a propery called requestBody is required:

vercel.dns.createRecord({
        domain: 'mydomain.com',
        teamId: 'my-team-slug',
        requestBody: {
        type: 'CNAME',
        name: 'subdomain',
        value: 'target.example.com'
        }
      })

But this complains that missing attribute name is required.

Trawling through the source code, which has many different options for requestBody, the only thing that I could think of, and the only thing that AI could suggest also, was to drop requestBody as follows:

vercel.dns.createRecord({
        domain: 'mydomain.com',
        teamId: 'my-team-slug',
        type: 'CNAME',
        name: 'subdomain',
        value: 'target.example.com'
      })

But this complains that requestBody is required. I’ve run out of ideas.

How do I use this SDK to create a CNAME?

Hey @dsrbl,

Can you share the documentation you are looking at for this? I am currently looking through this doc but I do not see an example of the createRecord (which itself is probably something that should be there. I will raise this with the SDK team).

Also just to clarify, the teamId is not the slug for your team but the team_12345 from your Team > Settings page.

I do see the requestBody is required, so your first snippet looks correct. I would definitely like to see the errors you are seeing locally if you have screenshots of them?

The domains part of the SDK is relatively new to me, but I am more than happy to take a look at whats up.

Hi @miguelcabs I’m facing the same issue — it complains that the name attribute is required, but I’m actually sending it.

const result = await vercel.dns.createRecord({
domain: “my-domain.dev”,
teamId: “team_XJxxxxxxxx”,
slug: " my-org-slug",
requestBody: {
comment: “testing”,
name: “test”,
ttl: 60,
type: “A”,
value: “03.228.48.138”,
})

I’ve tried several different approaches, but nothing has worked.
I also tried the example in this doc: Create a DNS record - Vercel API Docs, but it throws this error:

Error: API error occurred: {“error”:{“code”:“bad_request”,“message”:“Invalid request: should NOT have additional property https.”}}

Apologies Miguel I just spotted this reply!

Thanks for the feedback on teamId, I understood these were interchangeable - I can’t remember what in the docs led me to believe that, however.

I’ll grab the errors for you and post them here.

Hi @miguelcabs, here’s the call I’m making:

vercel.dns.createRecord({
  domain: 'beyonk.dev',
  teamId: 'team_xxx',
  requestBody: {
    type: 'CNAME',
    name: 'by-1417.beyonk.dev',
    value: 'by-1417.b-cdn.net'
  }
})

and the exact error I’m receiving is:

API error occurred: {"error":{"code":"bad_request","message":"Invalid request: missing required property `name`."}}

I updated teamId to be my team id, but this did not fix the error.

Thank you!