providing json payload

Re: providing json payload (solved)

by Paul Gatewood -
Number of replies: 0
In case it helps anyone, I finally got this working.

I had to install the plugin
    Web service protocols: RESTful protocol.

Once I had installed it, from here:
     https://moodle.org/plugins/webservice_restful
I tried a call, using one of the very helpful examples as a guide/template.

No matter what I tried I kept getting
    No Authorization header found in request

The "issues" page on the development site:
had several postings about this.

This particular issue:
mentioned that the download link on the moodle site (the link I used, above)
is to an older version and that a newer version has fixed this.

So from the github site I downloaded the latest as a zip file and used that
to install the plugin (overwriting the previous one from the moodle site).

Then it worked.

Below is an exact example I used, except I have replaced the actual token with TOKEN
and the actual password with PASSWORD.
(this was executed in a Windows environment)

curl -i --globoff                         ^
     -X POST                              ^
     -H "Content-Type: application/json"  ^
     -H "Accept: application/json"        ^
     -H "Authorization: TOKEN"            ^
     -d "{\"users\":[{\"username\":\"testuser02\",\"password\":\"PASSWORD\",\"firstname\":\"first_name_02\",\"lastname\":\"last_name_02\",\"email\":\"testuser02@dev.null\"}]}" ^
      "http://10.0.0.121/webservice/restful/server.php/core_user_create_users"

The response came back:

[{"id":5,"username":"testuser02"}]