Report this

What is the reason for this report?

Unable to create domain Record "API Error: Name can not be just a TLD"

Posted on March 17, 2020

I want to create sub-domains using NodeJS. I used the following Node.JS script but while I ran it I got the above error.

const express = require("express");
const router = express.Router();

var DigitalOceanAPI = require('doapi');
var api = new DigitalOceanAPI({token: 'my_token'});

router.post("/register", function (req, res, next)
{
  var name = req.body.name;
  var type = req.body.type;
  var data = req.body.data;
  var domain_name = req.body.domain_name;

  if(!name)
  {
    return res.status(400).send("name is empty");
  }  

  if(!type)
  {
    return res.status(400).send("type is empty");
  }  

  if(!data)
  {
    return res.status(400).send("data is empty");
  }


    api.domainRecordNew(domain_name, {
        type : req.body.type, 
        name : req.body.name,
        data : req.body.data,
        }).then(function (droplets)
    {
        res.json(droplets);
    });

}) 

module.exports = router;


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi,

It sounds like that you are not using the correct endpoint.

You have to use this endpoint: https://api.digitalocean.com/v2/domains/example.com/records.

And you have to pass the following information:

{
  "type": "A",
  "name": "subdomain",
  "data": "123.123.123.123",
  "priority": null,
  "port": null,
  "ttl": 1800,
  "weight": null,
  "flags": null,
  "tag": null
}

For more information you can take a look at the official documentation on how to create a new DNS record here:

https://developers.digitalocean.com/documentation/v2/#create-a-new-domain-record

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.