Quantcast
Channel: Web services
Viewing all 2366 articles
Browse latest View live

Can we use existing function of quiz web service in my custom web service for quiz

$
0
0

by Preethi Nadar.  

Hi,

Can anyone help me?

Is there any way to use inbuilt Quiz web service function in my custom web service for quiz.


Re: Quiz: review attempts

$
0
0

by Preethi Nadar.  

Hi, Ricardo,

Did you find any solution to your problem?

If yes please share I would like to know as I am also facing the similar issue.



Cross-domain request to access WS in javascript

$
0
0

by Michel DENIS.  

Hi,

Please could you tell me whether, and how, do Moodle's Web Services deal with javascript requests from a cross-domain perspective (CORS or other way) ? :

- anything special to enter in the remote, client javascript code ?

- anything special to add or configure in the Moodle server and/or its Web server ?

- does one of you have an exemple of such plain javascript piece of code accessing remote Moodle web services ?

Many thanks in advance,

-michel

core_course_get_categories query returns records 'like' parameter

$
0
0

by Robert Duncan.  

Hi,

 I am using the Web service API to create courses and categories - I first need to create the 'categories' and then I need to query Moodle to find out what the auto_increment 'id' of the parent category. I am using Powershell to build some test queries and its working well. One issue that I have had to put in a work around for is; the API seems to return all records that partially match the query string.

e.g.


criteria[0][key]=  'idnumber'

criteria[0][value'= 'DDM'


Returns all categories with a category ID that begins with DDM - for  subcategories  or categories with idnumbers like DDM1, DDM2, there records will be returned also. (in other words it doesn't seem to be an = operator under the covers).

Any pointers on how to return a single category would be greatly appreciated.



I also want to point out that when we want to create a subcategory we must give the 'parent' - this is an auto_increment Moodle counter. It would be far easier if we could create subcategories by defining the parent categories 'idnumber' i.e. data which we already know about.

Consider I have a 'category' and 'sub category' or more formally a 'course' and 'course instances'  the relational logic for these entities should not be based an arbitrary moodle 'parent' integer.  I know this will be required for links etc. but it should be abstracted away from Moodle integrations.

Further, If we consider that an institution can have many schools, courses, instances, locations and modes of study - then this schema becomes very difficult to reflect the same segregation/hierarchy 

we can only depict a basic relationship of nested elements

-> Category (parent 0, id 5)

   -->Sub Catecory (parent 5, id 6)

        --->Sub, Sub Category (parent 6, id 7)

+-------------------+--------------+------+-----+---------+----------------+
| Field             | Type         | Null | Key | Default | Extra          |
+-------------------+--------------+------+-----+---------+----------------+
| id                | bigint(10)   | NO   | PRI | NULL    | auto_increment |
| name              | varchar(255) | NO   |     |         |                |
| idnumber          | varchar(100) | YES  |     | NULL    |                |
| description       | longtext     | YES  |     | NULL    |                |
| descriptionformat | tinyint(2)   | NO   |     | 0       |                |
| parent            | bigint(10)   | NO   | MUL | 0       |                |
| sortorder         | bigint(10)   | NO   |     | 0       |                |
| coursecount       | bigint(10)   | NO   |     | 0       |                |
| visible           | tinyint(1)   | NO   |     | 1       |                |
| visibleold        | tinyint(1)   | NO   |     | 1       |                |
| timemodified      | bigint(10)   | NO   |     | 0       |                |
| depth             | bigint(10)   | NO   |     | 0       |                |
| path              | varchar(255) | NO   |     |         |                |
| theme             | varchar(50)  | YES  |     | NULL    |                |
+-------------------+--------------+------+-----+---------+----------------+
14 rows in set (0.00 sec)

Using OAuth2 to connect to Web Services

$
0
0

by Ryan Carpenter.  

I'm trying to connect my Moodle plugin to a web service that uses OAuth2 for user/client authentication.  The idea is for a Moodle administrator to be given a client ID and client secret, then enter those into Moodle so that the Moodle instance acts as a client application for other Moodle users to reach the web services.  Unfortunately, the documentation only seems to hint that such a use case is possible, without giving any details on implementation.


Importantly, web service doesn't use OAuth2 yet; I'm trying to make certain that I'll be able to connect Moodle to it before I invest the time in fully testing testing that change.  For now, I've been using this Node.js/Sails.js project to stand in as a simple API server/OAuth2 Server.  I've tested it in Postman and it seems to be working.

The problem is that Moodle seems to be asking for different details than the OAuth2 server generates.  Moodle's New Issuer form also looks quite different from Postman's New Token form.  For instance, it's not clear to me what Callback URL the auth server should use when it finishes granting authorization to the Moodle Admin.

Is there any other documentation on OAuth2 Services?  Anyone out there who's used them for a web service (rather than Open ID for user login)?  Thanks in advance.

core_user_get_users not returning users created with core_user_create_users

$
0
0

by alejandro alves.  

If I try to search for a user I just created with a WS it does not return it. Also I noticed that if I search by unexisting fields, for example, asdasdad, it returns the user associated with the token. Why? shouldn't it return an error? $token = 'XXXXX'; $domainname = 'XXXX'; $functionname = 'core_user_create_users'; // REST RETURNED VALUES FORMAT $restformat = 'json'; //Also possible in Moodle 2.2 and later: 'json' //Setting it to 'json' will fail all calls on earlier Moodle version //////// moodle_user_create_users //////// /// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION $user1 = new stdClass(); $user1->username = 'testusername4'; $user1->password = 'testpassworD*1'; $user1->firstname = 'testfirstname1'; $user1->lastname = 'testlastname1'; $user1->email = 'testemail1@moodlsde.com'; $user2 = new stdClass(); $user2->username = 'testusername5'; $user2->password = 'testpassworD*2'; $user2->firstname = 'testfirstname2'; $user2->lastname = 'testlastname2'; $user2->email = 'testemail2@moodleas.com'; $user2->timezone = 'Pacific/Port_Moresby'; $users = array($user1, $user2); $params = array('users' => $users); /// REST CALL header('Content-Type: text/plain'); $serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl; //if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2 $restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:''; $resp = $curl->post($serverurl . $restformat, $params); //print_r($resp); $criteria = array( 'key' => 'username','value' => 'testusername4' ); $params = array( 'criteria' => array($criteria)); $serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction=core_user_get_users'; $ret = $resp = $curl->post($serverurl . $restformat, $params); print_r($ret);

Re: core_user_get_users not returning users created with core_user_create_users

$
0
0

by alejandro alves.  

sorry just noticed the format problem


If I try to search for a user I just created with a WS it does not return it. Also I noticed that if I search by unexisting fields, for example, asdasdad, it returns the user associated with the token. Why? shouldn't it return an error?

$token = 'XXXXX'; $domainname = 'XXXX';

$functionname = 'core_user_create_users'; // REST RETURNED VALUES FORMAT

$restformat = 'json'; //Also possible in Moodle 2.2 and later: 'json'

//Setting it to 'json' will fail all calls on earlier Moodle version

//////// moodle_user_create_users ////////

/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION

$user1 = new stdClass();

$user1->username = 'testusername4';

$user1->password = 'testpassworD*1';

$user1->firstname = 'testfirstname1';

$user1->lastname = 'testlastname1';

$user1->email = 'testemail1@moodlsde.com';

$user2 = new stdClass();

$user2->username = 'testusername5';

$user2->password = 'testpassworD*2';

$user2->firstname = 'testfirstname2';

$user2->lastname = 'testlastname2';

$user2->email = 'testemail2@moodleas.com';

$user2->timezone = 'Pacific/Port_Moresby';

$users = array($user1, $user2);

$params = array('users' => $users);

/// REST CALL

header('Content-Type: text/plain');

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl;

//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2

$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';

$resp = $curl->post($serverurl . $restformat, $params);

$criteria = array( 'key' => 'username','value' => 'testusername4' );

$params = array( 'criteria' => array($criteria));

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction=core_user_get_users';

$ret = $resp = $curl->post($serverurl . $restformat, $params);

print_r($ret);

core_files_upload - nofile - 3.2.2

$
0
0

by Alvaro Devotto.  

Hi, i try upload a file into a course, but don't work. The web service requires that the parameter "component" is equal to "user" and that "filearea" is equal to "draft". Assign these parameters, and put the value "course" in "contextlevel" and the course id in "instanceid".

But, I get the error "nofile", I checked the moodle code, I could not understand how to save a file in a course using webservice, so that a student can download it from moodle.


My client WS

  • "wstoken"- [My Token]
  • "wsfunction"- "core_files_upload"
  • "component"- "user" (only can be this, or the ws produces error)
  • "filearea"- "draft" (only can be this, or the ws produces error)
  • "itemid"- "0"
  • "filepath"- "/"
  • "filename"- [filename + extension] (example: report.pdf)
  • "filecontent"- [base64 file]
  • "contextlevel"- "course"(i try put the file here)
  • "instanceid"- "13"(in this course id)


Return:

nofile File not specified


Thanks for your help


Re: Cross-domain request to access WS in javascript

$
0
0

by Juan Leyva.  

Hi,

CORS is supported only by the REST simple server (REST protocol using tokens for authentication). I think it is supported since Moodle 3.1.

You don't have to do anything special.

You can check the Mobile app code (although is a large base code, they are standard AJAX/XHR requets using Angular http service)

Juan

Web Service User Cannot Change Another User's Preferences

$
0
0

by Jesse Kuschel.  

Hello - I'm encountering an error regarding web services and I'm not sure if I'm missing something or if what I want to do is not allowed.  I have created a new web service with a few of the functions from core_users.  I'm access that service via REST successfully, and I can create users, delete users, and search for users.  This tells me my token authentication and data formats are correct.  My final goal is to be able to update the "auth" method for another user via Web Services using the "core_user_set_user_preferences" function. 

When I make a call to this service, the response back Warning Code is "nopermission" and the message states "You are not allowed to change the preference auth for user 12".  I am able to log into the Moodle web interface with this same web service account and modify the auth preference for user 12.

The contents of my POST request is "preferences[0][name]=auth&preferences[0][value]=manual&preferences[0][userid]=12".

Is this something I cannot do through web services?  My ultimate goal here is to be able to disable login (setting auth to "nologin") from a 3rd-party system via REST.

Thank you for assistance.

Re: Using OAuth2 to connect to Web Services

$
0
0

by Damyon Wiese.  

What is are describing sounds similar to the repository code for 3.3. Look at repository/googledocs as an example. 

There are 2 cases with when accessing a service with OAuth:

1. You want to access on behalf of the logged in user

2. You want to access on behalf of some kind of system user with magic privileges (without giving those privileges to the logged in user). 


Case 2 is what we use the "system account" for. Again - see the examples in that repository/googledocs which mixes both kinds of access.


Re: Using OAuth2 to connect to Web Services

$
0
0

by Ryan Carpenter.  

That sounds helpful; I'll check it out.  The system account sounds like the right way to go.

Thanks!

Using core_user_create_users In Python Script

$
0
0

by Sofiane beni.  

Hi,


I'm using Moodle 3.3.1 and in try to create an User withPython Script.

My Moodle web services configuration is good (i think).

But the user is not created, i have no error, nothing, just this line in my Apache logs :

[06/Sep/2017:16:24:32 +0200] "POST /webservice/rest/server.php?wstoken=XXXXXXXXXXX&wsfunction=core_user_create_users&moodlewsformat=json HTTP/1.1" 200 430 "-""python-requests/2.18.4


Here my Python Script :

#!/bin/python3.6

import requests

token = 'XXXXXXXXXXXXXXX'
function = 'core_user_create_users'

url = 'http://localhost/webservice/rest/server.php?wstoken={0}&wsfunction={1}&moodlewsformat=json'.format(token,function)

users = {'users[0][email]': 'test@mydept.edu',
        'users[0][firstname]': 'Test',
        'users[0][lastname]': 'Test1',
        'users[0][createpassword]': 1,
        'users[0][username]': 'Testst'}
requests.post(url,data=users)


Thank you in advance for your help.

Example of web services token from external application

$
0
0

by sai prasad.  

I'm trying to find an example for webservices token based call from external application, could anyone give me an example of that, my external application is in asp.net, I'm not familiar with PHP so please provide me with an example .


i have also tried using user key authentication web service but the only problem is how to call from external application through webservice??


i was trying this below:

https://myserver/MoodleN/webservice/rest/server.php?wstoken=506d602cf47a74de6e819123244b4141&wsfunction=testwebservice&moodlewsrestformat=jsonplease help?

Re: Dynamic Tokens for API


Re: Ats: Re: Login webservice

$
0
0

by sai prasad.  

hey hi, were you able to succeed with your asp.net integration with moodle?


i mean kind of singlesignon??? let me know plz

Login/token.php error

$
0
0

by Aniket Sankpal.  

I am trying to generate token for Moodle mobile service but getting an error:

{"error":"Invalid login, please try again","errorcode":"invalidlogin","stacktrace":"* line 104 of \/login\/token.php: moodle_exception thrown\n","debuginfo":"\nError code: invalidlogin","reproductionlink":"http:\/\/mymoodle.com\/"}

Actually, I have created a user with type oauth2.

Does any one know how to generate service token for google and facebook user?

Using Moodle 3.3.1


Blob is not saving in DB with Java web service in Win 10 (office 2016) with Chinese Language.

$
0
0

by Abhijeet Choudhary.  

Blob is not saving in DB with Java web service in Win 10 with Chinese Language.

our Application support only IE-11 and Office 32 bit.

our Application is working on IE-11 with MS Office only (office 10 or later version). our Application is working properly in every where.

but in china/japan (with their language) its not working. in china while user type something in Our application office viewer and save then its not save , BLOB file is not save to DB (Oracle) with JAVA Web service.

Client using Win10 64 bit and Office 2016 32 bit.

if client using new machine with same configuration then working fine, but after few days again facing issue, might be due to some updates (not sure).

more info:-

 “Microsoft SOAP Toolkit 3.0 with Office 2016 is used in our product .Please let us, “Is reinstallation of SOAP Toolkit or office 2016 would resolved this issue?” As this is happening only a system which is running with windows 10 Chinese language pack”.

Thanks,

Abhijeet Choudhary


Re: Cross-domain request to access WS in javascript

$
0
0

by Michel DENIS.  

Thank you Juan, that's good news for me. I will also check the code.

Have a nice day,

-michel

Web services enrolment - changing enrolment description

$
0
0

by samuel h.  

I want to enrol students using the web services function enrol_manual_enrol_users. I can do this successfully but the comment next to a student says

"Manual enrolments enrolled Sat 26 August 2017 06:00 AM".

This is not entirely true as it was enrolled by web services. Is there a way of changing the message so that is says something like "Web Services enrolments enrolled Sat 26 August 2017 06:00 AM"? Other enrolment plugins will have a different message e.g "External database enrolments enrolled Sat 26 August 2017 06:00 AM" for the External database enrolment plugin.

There is no way of knowing whether an enrolment was created manually by a human or by web services as far as I am aware. Is there a way to distinguish between web services enrolment and actual manual, human-initiated enrolment?

Viewing all 2366 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>