Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Evening folks,

I am attempting to load data from a .json file into parse.com backend. I can get the rest api to load manually added json as per the example provided from Parse.com from the terminal on my Mac:

curl -X POST \
  -H "X-Parse-Application-Id: removed" \
  -H "X-Parse-REST-API-Key: removed" \
  -H "Content-Type: application/json" \
  -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
  https://api.parse.com/1/classes/Test

This works fine.

How can I read a saved .Json file with only these three parameters(Json is validated fine) and send the data to my Parse backend? "score":1337,"playerName":"Sean Plott","cheatMode":false

I believe I have the option to use PHP/Jquery etc. however I have not used any of these languages extensively and a quick code example would be very much appreciated.

Thanks,

Gerard

share|improve this question
    
You can try curl -X POST -H "X-Parse-Application-Id: removed" -H "X-Parse-REST-API-Key: removed" -H "Content-Type: application/json" -d @file.json https://api.parse.com/1/classes/Test –  Prashant Borde Jan 26 '14 at 13:15
    
Hi Prashant, thanks for the answer, this curl just adds one row to the Parse class with it empty, I'm going to have a quick look at your PHP solution. If the file is set as -d @file.json it should parse and add each result from the code above right? –  user1461716 Jan 31 '14 at 4:20

1 Answer 1

up vote 0 down vote accepted

Here is pure PHP solution:

$url = 'https://api.parse.com/1/classes/Test';
$fields_string = file_get_contents('file.json');

//open connection
$ch = curl_init();

//set the url, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
/* End of first request */
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.