1

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?

3 Answers 3

1

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));
Sign up to request clarification or add additional context in comments.

3 Comments

This is the issue I'm having, its still not working for me, I am now getting {"error":"unauthorised"} - even though I have checked the ID and keys.
It would be very helpful if you provided a complete example. I am also getting {"error":"unauthorised"} when trying this. IDs and keys are in place.
So I should go sign up for a dev key, read through a ton of docs, just to provide a 'complete example' for something that wasn't even within the scope of this question? Don't think so...
1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.