Can't update record with APIv2

Posted November 8, 2014 2.3k views

Hi there I’m using this script to update a record in “data” field, but it wont change anything .

PUBLIC_IP=`curl -s`                                                                                                                                
echo "TOKEN $TOKEN"  
echo "IP $IP"                                                                                                                                                           
curl -X PUT -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -d '{"data":"$IP"}' "$DOMAIN/records/$RECORD" 
curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" "$DOMAIN/records/$RECORD"                     

It gives me this error

{"id":"unprocessable_entity","message":"IP address did not match IPv4 format (e.g."}{"domain_record":{"id":3304482,"type":"A","name":"periquita","data":"","priority":null,"port":null,"weight":null}}

And if I execute withour qoutes around $IP, like this:

curl -X PUT -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -d '{"data":$IP}' "$DOMAIN/records/$RECORD" 

goes straigt but no changes.

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.

1 answer

You need to escape the quotes in the JSON string so that they don’t get parsed by bash:

curl -X PUT -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -d '{\"data\":\"$IP\"}' "$DOMAIN/records/$RECORD" 
  • NO, i still get old IP record :/

  • Sorry, my bad, in order for bash to parse the variable ($IP), you have to use double quotes:

    curl -X PUT -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -d "{\"data\":\"$IP\"}" "$DOMAIN/records/$RECORD" 
Submit an Answer