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;
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:
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