Show
Note: Version number is bumped because a new web service is added into the Mobile app service and also in a component.
Enable "Mobile services": Plugins ► Web Services ► External services
Create a Token for one user (student account):
Click on Site administration ► Plugins ► Web services ► Manage tokens
Next, do a couple of curl requests for creating devices .
First call, just copy and paste the request (you need to replace the wstoken and the URL of your moodle instance)
Second call, change the pushid and appid parameters with random values (different to the current ones)
You also need to replace the wstoken and the URL of your moodle instance
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'appid=commoodlemobile&name=occam&model=Nexus&platform=Android&version=4&pushid=237823&uuid=ABCDEF&wsfunction=core_user_add_user_device&wstoken=1b9b8bd8d01acbf452c2bd77ca0d2925' --compressed
Check that the two devices have been created in your local database (table prefix_user_devices)
Now we are going to delete an non existent device, do the following request just replacen your token and URL
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data '&uuid=ZYXFDEASDFSDASDFDD&wsfunction=core_user_remove_user_device&wstoken=1b9b8bd8d01acbf452c2bd77ca0d2925' --compressed
You should see and output like this one
{"removed":false,"warnings":[{"item":"ZYXFDEASDFSDASDFDD","warningcode":"devicedoesnotexist","message":"The device doesn't exists in the database"}]}
Now, try to remove the first device you created (remember to use your site and token):
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodl: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data '&uuid=ABCDEF&appid=commoodlemobile&wsfunction=core_user_remove_user_device&wstoken=1b9b8bd8d01acbf452c2bd77ca0d2925' --compressed
You should see and output like this one
{"removed":true,"warnings":[]}
And now, remove the second device, as you can see we only indicate the uuid
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'uuid=ABCDEF&wsfunction=core_user_remove_user_device&wstoken=1b9b8bd8d01acbf452c2bd77ca0d2925' --compressed
You should see and output like this one
{"removed":true,"warnings":[]}
If you do the curl request again, you should see removed: false and a warning