By Ivan Denkov
Hey there,
I have strange problem here.
I started writing script yesterday for updating a domain name, and it was working fine. But today I am getting error:
string(81) "{"id":"unprocessable_entity","message":"Record type is not included in the list"}" {"type":"A","name":"home","data":"162.10.66.0"}
This is the code:
$ch = curl_init($request_uri);
$headers = array(
'Content-Type:application/json',
'Authorization: Bearer ' . file_get_contents('token.txt') );
$rawdata = array(
'type' => 'A',
'name' => 'sub',
'data' => '162.10.66.0',
'priority' => null,
'port' => null,
'weight' => null
);
$postdata = json_encode($rawdata);
$ch = curl_init(); // initiate curl
$url = "https://api.digitalocean.com/v2/domains/mydomain.org/records";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch); // execute
curl_close ($ch); // close curl handle
var_dump($output); // show output
echo $postdata;//show what I am posting
There is no difference how I format the json POST request - it never detects the type and returns that error.
Any help will appreciated.
Thanks, Ivan
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!
Hi hozza,
At the end I think I used exec to run shell command through php, but later I gave up on php and I just have shell script which I use to update the DNS, here it is if that is going to help you:
#!/bin/bash
#Description: Update IP address for A record on Digital Ocean API v2.
#Author: Ivan Denkov
TOKEN="47537ab13b726ae38bc90181778678678567jhffjhgfh"
RECORD_ID="0000000"
DOMAIN_NAME="domain.com"
#Retrieve current public IP
NIP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
#Retrieve record IP
CIP=$(curl -X GET -H 'Content-Type: application/json' -H 'Authorization: Bearer '$TOKEN'' "https://api.digitalocean.com/v2/domains/"$DOMAIN_NAME"/records/"$RECORD_ID"" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["domain_record"]["data"]')
#echo [$(date +"%d-%m-%Y-%T")] "DO WAN IP: " $CIP >> log.txt
#Compare past WAN IP and with current WAN IP
if [ "$NIP" != "$CIP" ]; then
curl -X PUT -H 'Content-Type: application/json' -H 'Authorization: Bearer '$TOKEN'' -d '{"data":"'"$NIP"'"}' "https://api.digitalocean.com/v2/domains/"$DOMAIN_NAME"/records/"$RECORD_ID
else
echo "IP is the same!"
fi
exit 0;
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.