MMuzammilQ MMuzammilQ - 3 years ago 61
reST (reStructuredText) Question

Want to manage mongoldb user on CodeIgniter using Parse Rest API

Database: Mongodb
Backend Framework: CodeIgniter

Want to manage default User table from backend. I am using ParseRestAPI but as you all know Mongodb does not allow to update user without session. So is there any way i can manage users created by App and delete/create new users.

Answer Source

Yes you can do that with the Parse Rest API

For exmaple to delete a user: Use the DELETE http verb and call something like that:

Note: You need to pass the Session Token or Master Key

 curl -X DELETE \
  -H "X-Parse-Application-Id: YOURAPPID" \
  -H "X-Parse-REST-API-Key: YOURAPIKEY" \
  -H "X-Parse-Session-Token: SESSIONTOKEN" \
  -H "X-Parse-Master-Key: YOURMASTERKEY" \
  https://api.example.com/1/users/<objectId>

In php you can write:

$ch = curl_init('https://api.example.com/1/users/<objectId>');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");                                                                     

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'X-Parse-Application-Id: YOURAPPID',
    'X-Parse-REST-API-Key: YOURAPIKEY', 
    'X-Parse-Master-Key: YOURMASTERKEY'                                                                 
);                                                                                                                   

$result = curl_exec($ch);

To create a user call the API like that (I use curl for example)

        curl -X POST \
        -H "X-Parse-Application-Id: YOUAPPID" \
        -H "X-Parse-REST-API-Key: YOURAPIKEY" \
        -H "Content-Type: application/json" \
        -d '{ "objectId": "", "updatedAt": "", "createdAt": "", "name": "John Doe", "pass": "toto42" }' \
        https://api.example.com/1/classes/User/
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download