0

Evening all,

I just have a quick questions about bulk importing via the rest api. I've tried various methods to automate looping through a file and adding the results to Parse backend without success. One example:

curl -X POST \ -H "X-Parse-Application-Id: Removed" \ -H "X-Parse-REST-API-Key: Removed" \ -H "Content-Type: application/json" \ --data '{

"requests": [
  {
    "method": "POST",
    "path": "/1/classes/testnew",
    "body": {
      @Posts.json
    }
  }
]

}' \ https://api.parse.com/1/batch

I've tried many other Curl commands and also checking the network tab in parse when uploading a .json file, it looks like when you click the upload it is using the form multipart command to upload the data in a .json file. Does anyone know of a way to automate uploading of data from a .json file into parse without having to manually execute the batch/individual calls as described in the rest api documentation via cUrl?

Any help would be seriously appreciated :-).

Thanks,

Gerard

2 Answers 2

0

it seems parse doesn't provide desired function . you can still write a small python script quick fix.

{
  "all_players": [
          {
              "score": 1337,
              "playerName": "Sean Plott"
          },
          {
              "score": 1338,
              "playerName": "ZeroCool"
          }]
}
import urllib2
import json
import pprint
def frame_request():
  f=open('hello.json','r')
  data = json.load(f) 
  flag=1;
  req = '{ "requests": ['
  for d in data["all_players"]:
    if flag:
      flag=0
    else:
      req=req+','
    req=req + '{ "method": "POST", "path": "/1/classes/GameScore", "body":' + json.dumps(d) + ' }'
  req=req+']}'
  return req
Sign up to request clarification or add additional context in comments.

Comments

0

Add -k or --insecure command with curl to handle your https link.

Linux supports single quote for data value, but windows doesn't. If you are from windows based OS, then --data should be something like below:

--data "{sample:\"json-data\"}"

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.