my problem is that I can’t create a CNAME record in DNS for my domain. I want to create subdomains through code using axios queries. But for some reason, I am constantly being told that the domain does not exist or the wrong zone file.
Code:
const axios = require('axios');
class Domains {
constructor(domain, apiKey, apiSecret) {
this.domainName = domain;
this.apiKey = apiKey;
this.apiSecret = apiSecret;
this.apiBaseUrl = 'https://api.ote-godaddy.com/v1';
}
async createSubdomain(subdomain) {
const headers = {
headers: {
Authorization: `sso-key ${this.apiKey}:${this.apiSecret}`
}
};
try {
const newRecord = [
{
type: "CNAME",
data: this.domainName,
ttl: 600
}
];
const putResponse = await axios.put(`${this.apiBaseUrl}/domains/${this.domainName}/records/CNAME/${subdomain}`, newRecord, headers);
if (putResponse.status === 200) {
console.log(`Subdomain ${subdomain}.${this.domainName} successfully created`);
console.log('Server response:', putResponse.data);
} else {
console.error(`Error creating subdomain: ${putResponse.status}`);
}
} catch (error) {
console.error('An error occurred:', error.response ? error.response.data : error.message);
}
}
}
module.exports = Domains;
I need to create automatically the subdomain for my domain via node.js script (axios or whatever stands for requests).