Search code examples
classparse-platformschemacommand-line-interface

Parse: Creating a New Class Programmatically


Is it possible to create a new Class programmatically (i.e. not from the dashboard) via any of the API's or the Parse CLI?

The REST API appears to have functionality to fetch, modify and delete individual Schemas (classes) but not to add them. (https://parse.com/docs/rest/guide#schemas).

Hoping for something like the following:

curl -X ADD \
-H "X-Parse-Application-Id: XXXXXX" \
-H "X-Parse-Master-Key: XXXXXXXX" \
-H "Content-Type: application/json" \
https://api.parse.com/1/schemas/City

Solution

  • You seem to have skipped the part which deals with adding schema in the documentation. To create a new class, according to documentation, You use following method in cURL:

    curl -X POST \
      -H "X-Parse-Application-Id: Your APP Id" \
      -H "X-Parse-Master-Key: Your master key" \
      -H "Content-Type: application/json" \
      -d ' 
        {
          "className": "Your Class name goes here", 
          "fields": {
            "Your field name here": {
              "type": "Your field's data type e.g. String, Int etc. Add multiple fields if you want"
            }
          }
        }' \
      https://api.parse.com/1/schemas/[Your class name]
    

    Or in Python:

    import json,httplib
    connection = httplib.HTTPSConnection('api.parse.com', 443)
    connection.connect()
    connection.request('POST', '/1/schemas/Game', json.dumps({
           "className":"[Your class name]","fields":{"Your field name":{"type":"your field's data type"} }
         }), {
           "X-Parse-Application-Id": "7Lo3U5Ei75dragCphTineRMoCfwD7UJjd1apkPKX",
           "X-Parse-Master-Key": "ssOXw9z1ni1unx8tW5iuaHCmhIObOn4nSW9GHj5W",
           "Content-Type": "application/json"
         })
    result = json.loads(connection.getresponse().read())
    print result