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

"No permission to create web service token for the service" with custom service

$
0
0
by Brian Yanosik.  

I've gone through the forums and google and can't seem to get this working.

I've followed the documentation to create a new custom webservice with only a handful of functions. I modified the authenticated role to allow for a token to be created but I still receive this error.

I would gather I'm missing something minor. Are there any gotchas?


Re: "No permission to create web service token for the service" with custom service

$
0
0
by Brian Yanosik.  

turns out the user was a site admin which prevented the token from being created.

Web Service function to allow user to update their own profile

$
0
0
by Brian Yanosik.  

Is there a function or a way to allow a user (via REST API/Token) to update their own profile and no one elses?

Freeze context API

Re: Web Service function to allow user to update their own profile

$
0
0
by Mayank Tyagi.  

Yes, there are core webservice functions to achieve this. But it's not a good idea. If you want to restrict user to update his own profile then you need to create token for each user or you need to apply capabilities present in system.

Re: Django with Moodle

$
0
0
by Mayank Tyagi.  

Hi Robert,

For this you can create your custom webservice in moodle. Even moodle have events triggered when assignment submitted. Its up to you what logic you want to implement.

core_role_assign_roles to asssign mentor role

$
0
0
by Doug Stevens.  

Hi all, I've written a PHP cron script to synchronize students and parents against our SIS.  I've managed to get all of it working except assigning parents to students (done on the site via "Assign roles relative to this user".  If I do this manually via our moodle site, it works perfectly, however when I run the code below there are no role assignments created nor are there any errors flagged to the console, the apache error logs, nor the PHP cli logs.  

For the code below:

roleid = 9 is assigned to a system level role with a user context called "Parent".  This shows up in the "Assign roles relative to this user" in the student's preferences.

Via a var_dump I can confirm that both $moodlelookup and $parentlookup below both provide the correct moodle userids which are stored in $role correctly.

In the userlogs for the API token's user the method call shows as "unknown method".

Can anyone spot my mistake?

Thanks!

Doug

----Code below----

$roles=array();

foreach($parentstudent as $thiskid)

    {

        $role['roleid']=9;

        $role['userid']=(int)$parentidlookup[$thiskid['parent']]; //Recover Parent's moodle userid                                         

                                                                  //Both of these Confirmed by using in Moodle profile                     

        $role['instanceid']=(int)$moodlelookup[$thiskid['student']]; //Recover Student's moodle userid                                     

        $role['contextid']=(int)30;

        $role['contextlevel']="user";

        array_push($roles,$role);

    }


unset($resp);

try{

    $params=array();

    $params['assignments']=$roles;

    $resp=$clientm->core_role_assign_roles($params);

}catch(Exception $e){

    echo $e."\n";

    }

var_dump($resp);

Re: Svar: Re: How to get courses in a category and any subcategories with courses

$
0
0
by Brian Merritt.  

I haven't tried to use the path key, but with parent and all categories it should be possible to get all subcategories programatically.

Re: core_role_assign_roles to asssign mentor role

$
0
0
by Doug Stevens.  

Just a bit more info:

A var_dump of $params above reveals what I believe are the correct arguments.  I can confirm that the userid and instanceid are the correct parent and student users in Moodle:

 

array(1) {

  ["assignments"]=>

  array(530) {

.

.

.

    [209]=>

    array(5) {

      ["roleid"]=>

      int(9)

      ["userid"]=>

      int(37597)

      ["instanceid"]=>

      int(34248)

      ["contextid"]=>

      int(30)

      ["contextlevel"]=>

      string(4) "user"

    }

.

.

.

  }

}


Cannot find Create_token function for external web services

$
0
0
by Trevor Peck.  

For my moodle cloud site, when trying to set up an external web service, I cannot seem to find the create_token function when enabling functions for my webservice, and this seems absolutely necessary for any other functions I want to use with this external service. Has anyone else had this issue?


Thank you for the help.

core_user_create_users custom field not add

$
0
0
by Eliseo Montenegro.  

Hi 













Hi everyone,
I am trying to create a user using api core_user_create_users with custom fields with the following array. the user is created but the custom field is not loaded, does anyone know why he does not load it? Thanks for your time!
Array
(
    [username] => nnnnn@gmail.com
    [password] => A123789456A
    [firstname] => nnnnn
[lastname] => nn [email] => lesenda.gaston@gmail.com [idnumber] => A123789456A [customfields] => Array ( [0] => Array ( [type] => dir [value] => 02 ) ) )

Re: Cannot find Create_token function for external web services

$
0
0
by Eliseo Montenegro.  

hi,
do you try on Home/ Site administration/ Plugins/ Web services/ Manage tokens?

Re: core_user_create_users custom field not add

$
0
0
by Doug Stevens.  

I've found success using core_user_update_users if that helps. 

core_grades_update_grades: componet and activityid for manual grade item

$
0
0
by Roberto Bravo Diaz.  

Hello.

I'm trying to update a student manual grade item using the webservice but the 'core_grades_update_grades' function requires component and activityid, a manual grade item don't have activityid and I don't know the string I have to use as component/module for a manual grade item (someone of the mdl_modules?).

Does anyone know if it is possible to modify the values of a manual grade item using a webservice?

I can update a scorm grade without problem.

Regards,

Roberto.

Re: core_role_assign_roles to asssign mentor role

$
0
0
by Doug Stevens.  

So some interesting results, I seem to be able to make the method work for a system role but not for a user level role.  This seems like a new issue since we moved to Moodle 3.7.   Any ideas?
 
//This worksforeach($parentidlookupas$thisone){// echo "Adding ".$thisone."\n";$role['roleid']=10;//Defines what the parent can access generally. Based on student role$role['userid']=$thisone;$role['contextlevel']="system";$role['contextid']=1;array_push($roles,$role);}unset($resp);try{$resp=$clientm->core_role_assign_roles($roles);}catch(Exception$e){echo$e."\n";}
The above fills $roles with below and works:
 
array(527) {
  [0]=>
  array(4) {
    ["roleid"]=>
    int(10)
    ["userid"]=>
    int(24844)
    ["contextlevel"]=>
    string(6) "system"
    ["contextid"]=>
    int(1)
  }
//Doesn't flag error but doesn't work either.  Confirmed that the $role parameters are correct by browsing databaseunset($roles);unset($role);unset($resp);$roles=array();foreach($parentstudentas$thiskid){$role['roleid']=9;//A user level role assigning a parent to student.$role['userid']=$parentidlookup[$thiskid['parent']];//Recover Parent's moodle userid$instanceid=$moodlelookup[$thiskid['student']];//Recover Student's moodle userid$thisid=$context_lookup[array_search($instanceid,array_column($context_lookup,1))][0];echo"Found ".$instanceid." with contextid=".$thisid."\n";$role['contextid']=(int)$thisid;$role['instanceid']=(int)$instanceid;$role['contextlevel']='user';array_push($roles,$role);}unset($resp);try{$resp=$clientm->core_role_assign_roles($roles);}catch(Exception$e){echo$e."\n";}var_dump($resp);
The above fills $roles with below and doesn't work. Here userid is parent, instanceid is student and contextid is the context that matches instanceid.
array(534) {
  [0]=>
  array(5) {
    ["roleid"]=>
    int(9)
    ["userid"]=>
    int(37393)
    ["contextid"]=>
    int(36887)
    ["instanceid"]=>
    int(19846)
    ["contextlevel"]=>
    string(4) "user"
  }
 

Which web service api/endpoint allows getting Gradebook setup information

$
0
0
by Zadok Lindt.  

Which webservice api/endpoint allows fetching the Gradebook setup information, such as weights? 


i.e.:


回复: core_grades_update_grades: componet and activityid for manual grade item

$
0
0
by spoony liu.  

Can you tell me how to  to update a student activity grade item using 'core_grades_update_grades' function?

thank you!

Re: login and registration form

$
0
0
by Birju Modhwadia.  

Can I add a login and registration form on my own website Coupon Code Cart? I was much time try for it but I unable to do this. can anyone help me?

Re: 回复: core_grades_update_grades: componet and activityid for manual grade item

$
0
0
by Roberto Bravo Diaz.  

Hi Spoony Liu.

Look this screenshot


Saving files as submission to assignment

$
0
0
by Jozef K.  

Hello, i have problem to save file as submissions to assignment through web services.
I cannot save submission for specific user. I can only save submission for user, that call webservices. How can i rework web service chain below? It is even possible?

I have used with this specific order:
1, core_files_upload (this will save draft of file to moodle)
mymoodle/webservice/rest/server.php?component=user&filearea=draft&itemid=0&filepath=/&contextlevel=user&instanceid=9280&wstoken=xxxxxxxxxxxxxxxxxxx&wsfunction=core_files_upload&moodlewsrestformat=json&filename=aa.txt&filecontent=ZHNhZGE=

2, mod_assign_get_assignments (this will get id of assigments for courses for user)
mymoodle/webservice/rest/server.php?wstoken=xxxxxxxxxxxxxxxxxxx&wsfunction=mod_assign_get_assignments&moodlewsrestformat=json

3,mod_assign_save_submission (this will save submission as i want)
mymoodle/webservice/rest/server.php?wstoken=xxxxxxxxxxxxxxxxxxx&wsfunction=mod_assign_save_submission&moodlewsrestformat=json&assignmentid=8&plugindata[onlinetext_editor][text]=aaa&plugindata[onlinetext_editor][format]=1&plugindata[onlinetext_editor][itemid]=889967549&plugindata[files_filemanager]=889967549

4, file is uploaded and saved in submission


I have found that i can create for every user ws token (but i dont have passwords and dont want to, cause it is not practical).
P.S. Im not .php dev, so i'll hope i can use only ws.

Thanks for help!!
Jozef K.

Moodle 3.7 (for now)

Viewing all 2361 articles
Browse latest View live


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