Reputation: 345
I am having trouble converting this curl to something that I can post with in PHP. The API is as follows from Parse:
curl -X POST \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"username": "cooldude6", "password": "p_n7!-e8", "phone": "415-392-0202"}' \
https://api.parse.com/1/users
In particular how would I pass line 5 an array of post values?
Upvotes: 1
Views: 2663
Reputation: 588
Here you can find a PHP library for Parse.com wich handles all the REST Api functions with Parse.com https://github.com/FredvanRijswijk/parse.com-php-library
Upvotes: 1
Reputation: 3725
If you're getting "error unauthorized" I suspect you're passing the literal values ${APPLICATION_ID} and ${REST_API_KEY}.
Those are stand-in values for keys specific to your account. These keys are in your app dashboard. Recently, the documentation page at http://parse.com/docs/rest.html will also automatically replace ${APPLIACTION_ID} and ${REST_API_KEY} with your real keys if you are logged in.
Upvotes: 0
Reputation: 360732
Something like this?
<?php
$headers = array(
'X-Parse-Application-Id' => ${APPLICATION_ID},
'X-Parse-REST-API-Key', ${REST_API_KEY}
'Content-type: application/json'
);
$data = array(
'username' => "cooldude6",
'password' => "p_n7!-e8",
'phone': '415-392-0202',
'postfield1' => $_POST['postfield1'],
etc...
);
... connect to curl ...
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
Upvotes: 1