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

Enroll users in a course. Help!

$
0
0
by anne anne.  

Hi!! I want to enroll users in a moodle course with de API. I use this function, but not working sad I use other function to create users, it has the same format and it is working perfectly. Please, I need help. Thank!!!

Error: string(636) " enrol_manual_enrol_usersroleid5userid36courseid3" string(43) "Moodle error: Unknown error Fault code: 404"


  function enrollUser($user_id, $course_id) {
       
 $params = array(array(array('roleid'=>'5', 'userid'=>$user_id, 'courseid'=>$course_id)));
       $request = xmlrpc_encode_request('enrol_manual_enrol_users', $params, array('encoding'=>'UTF-8'));
       $context = stream_context_create(array('http' => array(
      'method' => "POST",
      'header' => "Content-Type: text/xml",
      'content' => $request
    )));

    $path = $this->server.$this->dir."/webservice/xmlrpc/server.php?wstoken=".$this->token;
    $file = file_get_contents($path, false, $context);
    $response = xmlrpc_decode($file);
     
    if ($response && xmlrpc_is_fault($response)) {
      $this->error = "Moodle error: " . $response[faultString]." Fault code: " . $response[faultCode];
      return false;
    }

    return true;
  }


Re: Enroll users in a course. Help!

Re: Enroll users in a course. Help!

$
0
0
by anne anne.  

But.. that example is to create users, its works perfectly like my other function.

I dont know how to adapt it to my case sad

Moodle API REST POST Error

$
0
0
by Helder Carvalho.  

Hi guys,

I'm having problems setting up the moodle API Rest web services, I've got no problems performing GET Requests, but when I perform POST Requests I get the following error:

'<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="webservice_access_exception">
<ERRORCODE>accessexception</ERRORCODE>
<MESSAGE>Access control exception</MESSAGE>
<DEBUGINFO>Access to the function core_course_create_categories() is not allowed.
There could be multiple reasons for this:
1. The service linked to the user token does not contain the function.
2. The service is user-restricted and the user is not listed.
3. The service is IP-restricted and the user IP is not listed.
4. The service is time-restricted and the time has expired.
5. The token is time-restricted and the time has expired.
6. The service requires a specific capability which the user does not have.
7. The function is called with username/password (no user token is sent)
and none of the services has the function to allow the user.
These settings can be found in Administration &gt; Site administration
&gt; Plugins &gt; Web services &gt; External services and Manage tokens.</DEBUGINFO>
</EXCEPTION>
'

Web services are enabled with REST protocol. I've set 2 users with API tokens and all permissions enabled, including the "USE REST PROTOCOL" and they are both failing. 

Re: Using angular-js with moodle for frontend.

$
0
0
by Joey Andres.  

Thanks. But we are still in 2.8. Either way, we made the decision to stick with Slim for now to do the routing.

Re: REST Web service - Missing required key in single structure: groups

$
0
0
by Alex Legg.  

Plugin permissions were incorrect.

Re: How to get all assignments for a course.

$
0
0
by Ryan VanAlstine.  

Has anyone found a solution for this yet?  I'm running into the same issue.  

Re: Enroll users in a course. Help!


Re: Enroll users in a course. Help!

$
0
0
by anne anne.  

But.. that example is to create users, its works perfectly like my other function.

I dont know how to adapt it to my case sad

Moodle API REST POST Error

$
0
0
by Helder Carvalho.  

Hi guys,

I'm having problems setting up the moodle API Rest web services, I've got no problems performing GET Requests, but when I perform POST Requests I get the following error:

'<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="webservice_access_exception">
<ERRORCODE>accessexception</ERRORCODE>
<MESSAGE>Access control exception</MESSAGE>
<DEBUGINFO>Access to the function core_course_create_categories() is not allowed.
There could be multiple reasons for this:
1. The service linked to the user token does not contain the function.
2. The service is user-restricted and the user is not listed.
3. The service is IP-restricted and the user IP is not listed.
4. The service is time-restricted and the time has expired.
5. The token is time-restricted and the time has expired.
6. The service requires a specific capability which the user does not have.
7. The function is called with username/password (no user token is sent)
and none of the services has the function to allow the user.
These settings can be found in Administration &gt; Site administration
&gt; Plugins &gt; Web services &gt; External services and Manage tokens.</DEBUGINFO>
</EXCEPTION>
'

Web services are enabled with REST protocol. I've set 2 users with API tokens and all permissions enabled, including the "USE REST PROTOCOL" and they are both failing. 

Get user id from a username

$
0
0
by anne anne.  

Hello! I have a form and I need the user id to enrol a user into a course.

The user will put his name in the form, and I store his name as: $name=$_POST[user];

Which is the id of the user $name??

I need it here: $enrolled = $moodle->enrollUser($user_id, $course_id);

Thank you!! :D

Re: Get user id from a username

$
0
0
by Michael Hughes.  

Just to clarify:

"The user will put his name" is the "user will put his username"and not their propername (terminology is everything).

If it is username then you can do a look up on it, but this is complicated if you have multiple authentication methods:

$user = $DB->get_record('user', array('username' => $name));

This will work but you get strange effects if there are 2 accounts with the same username but different authmethods, so you should also include "auth". For instance the following will restrict it to users that use the manual auth method:

$user = $DB->get_record('user', array('username' => $name, 'auth' => 'manual));

The question is, is the user already logged in? Because if this is all happening within Moodle, you can pick up the current user's record via the $USER super variable, so you don't need to ask them for details...(just a thought).

Also please never do: $name=$_POST[user]; without validating the user input!

If your page is within moodle you should be doing either

$name = required_param('user', PARAM_ALPHA)

or 

$name = optional_param('user', '', PARAM_ALPHA);

Hope this helps.

Enroll group of users to course from web services?

$
0
0
by marcel montel.  

Hi!


I am looking to create users, add them to a group and then add that group to a course, all via the web services.

I am already creating new users through the web services api. Looking at the documentation it seems like the following would do the trick:

core_group_create_groups() -- create my group
core_group_add_group_members() -- after i inject a user, i can add him/her to the group

Now, which web service (if available?) is used to enroll a group of users to a course?, or should i be looking at cohorts instead?


Please help



create USER via REST or XML-RPC fails with "invalidrecord Can not find data record in database table external_functions"

$
0
0
by Bla Blub.  

Hi,

I want to connect an external website with a moodle-system. I've already set up the webService and created a token to get access.

I've followed http://www.rumours.co.nz/manuals/using_moodle_web_services.htm set up but in contrast i wanted to realise the connection via REST as in https://github.com/moodlehq/sample-ws-clients/find/master

My approach is to have a moodle class which will handle the data exchange. In first place i just wanted to try to create some new hard coded Users via the webService but it fails with the Moodle-Response:

"invalidrecord Can not find data record in database table external_functions. "

Which seems to me as if i the call was successfully but moodle has a problem to find the "core_user_create_users" function. I've checked the local moodle Database and in the table external_functions is an entry for "core_user_create_users" so i'm kind of confused where moodle doesn't know what to do.


The Attached files contain my set up...

main.php gets called when a new User is registering to my other WebSite. There I'll create an object of my moodle class and start a request to my local moodle. 

i've checked if my request is reaching the local moodle and indeed it does.. Does anyone know whats going on here, what's that for an error...? Or are there different approaches for my purpose which i could try?

Thanks in advance for any help!

Re: Create assignment or Create Grade via Web Service

$
0
0
by Mike Warner.  

Hi Jared,

did you figure this out?  I've been poring over the API docs, but can't see how to create a grade column (or an assignment) from a remote LMS. 

Thanks,

Mike


Re: Grade API Plugins

$
0
0
by Mike Warner.  

Hi Andy,

I know that it's been over a year, but I'm am investigating the ability to push grades from a non-Moodle LMS to Moodle.   Did you get this working?

Thanks,

Mike

Re: How to get course contents through to webservice ?

$
0
0
by Eseosa I.  

Hey Kathir, 


There is an exposed function to retrieve course related data 'core_course_get_contents.'


Modified from here: https://gist.github.com/jleyva/9687810


...

<?php

$token='<token_here>';


$domainname='<moodle domain url>';


$courseid=<course id>;



// 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
$restformat= ($restformat=='json')?'&moodlewsrestformat='.$restformat:'';
/// REST CALL
header('Content-Type: text/plain');
require_once('./curl.php');
$curl=newcurl;
$functionname='core_course_get_contents';
$params=array(
'courseid'=>$courseid
);
$serverurl=$domainname.'/webservice/rest/server.php'.'?wstoken='.$studenttoken.'&wsfunction='.$functionname;
$resp=$curl->post($serverurl.$restformat, $params);
$resp=json_decode($resp); var_dump($resp); ...



Regards,

-E

Save mod_assign_save_submission usign HTML form

$
0
0
by Manex Etxabe.  

I would like to save an online text assigment, using a simple HTML form. I would like to save for each user logged in, but the API always saves in Admin user's assigment.

The function is mod_assign_save_submission.

Any idea?

How to use Moodle restful web services in Android app

$
0
0
by Manideep Manda.  

I want to access the Moodle restful web services in my native android app.

Following are the steps that I have done with:

Step-1

 Administration > Site administration > Plugins > Web services   and enabled the web service's.

Step-2

Administration > Site administration > Plugins > Web services> Manage Protocols and enabled the rest protocol.

Step-3

Administration > Site administration > Plugins > Web services> Manage >Manage Token and created token with validity date.

After performing the above 3 steps ,I have no idea how to proceed further.

Idealy my requirement  is  access the restful web services from my  moodle instance:

like:

URL:http://localhost/........

json : json data 

etc....

so I would use the restful web service in my native android app.


Please suggest me the further steps to be followed to access the restful web services 


 


Issue while trying to access Moodle restful web service

$
0
0
by Manideep Manda.  

URL:

http://localhost/moodle/webservice/rest/server.php/?wstoken='c05f1bf389c771a41736aed9443a9620'&wsfunction='core_course_get_courses'

content type: application/json

method: GET


Result:

<?xml version="1.0" encoding="UTF-8" ?>

<EXCEPTION class="moodle_exception">

    <ERRORCODE>invalidtoken</ERRORCODE>

    <MESSAGE>Invalid token - token not found</MESSAGE>

</EXCEPTION>


I am getting the following exception if I try to access moodle restful api, I have done all the initial setup required to access the restful api's .


I any one have solution for this please let me know through this post.

Viewing all 2364 articles
Browse latest View live


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