I am using godaddy api for access the domains. I am refered, https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplace
I want to add CNAME in a doamin in Godaddy.
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "sso-key {key}:{secret}");
var requestURl = "https://api.godaddy.com/v1/domains/mydomain.com/";
string body = "{\"data\": \"xxxxx.azurewebsites.net\",\"name\": \"xxxx\",\"type\": \"CNAME\"}";
var stringContent = new StringContent(body, Encoding.UTF8, "application/json");
var response = client.GetAsync(requestURl).GetAwaiter().GetResult(); ;
if (response.StatusCode == HttpStatusCode.Created)
{
}
}
But I got error code 422. Any idea about why these error?
Finally got answer,
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "sso-key {key}:{secret}");
var requestURl = "https://api.godaddy.com/v1/domains/mydomain.com/";
var data = new
{
data= "xxxxx.azurewebsites.net",
name = "xxxx",
type = "CNAME",
ttl =3600
};
var body = JsonConvert.SerializeObject(data);
var stringContent = new StringContent("["+body+"]", Encoding.UTF8, "application/json");
var responseMessage = await client.PatchAsync(new Uri(requestURl), stringContent);
if (response.StatusCode == HttpStatusCode.Created)
{
}
}