Working with a RESTful API (for Rackspace's API for domain records) and I have encountered something for the first time. That is, sending an request as a JSON file and not the usual key-value paired data.
In my case, I am supposed to send a string in JSON format, WITHOUT a key corresponding to it. All the examples I have encountered with cURL always assumes the request page expects one. Besides, it seems that the CURLOPT_POSTFIELDS
option expects an array (read: key-value pair), anyway.
I am able to set the necessary headers (the Content-Type, and other authentication headers), but I am seriously stuck on putting up the necessary JSON string into the request.
How can I do this?
EDIT:
Here is the API Documentation:
POST https://dns.api.rackspacecloud.com/v1.0/1234/domains/2725233/records
Accept: application/json
X-Auth-Token: ea85e6ac-baff-4a6c-bf43-848020ea3812
Content-Type: application/json
Content-Length: 725
{
"records" : [ {
"name" : "ftp.example.com",
"type" : "A",
"data" : "192.0.2.8",
"ttl" : 5771
}, {
"name" : "example.com",
"type" : "A",
"data" : "192.0.2.17",
"ttl" : 86400
}, {
"name" : "example.com",
"type" : "NS",
"data" : "dns1.stabletransit.com",
"ttl" : 3600
}, {
"name" : "example.com",
"type" : "NS",
"data" : "dns2.stabletransit.com",
"ttl" : 3600
}, {
"name" : "example.com",
"priority" : 5,
"type" : "MX",
"data" : "mail.example.com",
"ttl" : 3600
}, {
"name" : "www.example.com",
"type" : "CNAME",
"comment" : "This is a comment on the CNAME record",
"data" : "example.com",
"ttl" : 5400
} ]
}