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

core_user_create_users and core_user_update_users are missing some core fields

$
0
0

by Nicholas Stefanski.  

I was looking to start using Moodle's existing webservices to create new users from an external source, but I noticed that the core_user webservices are missing several fields for users, including phone1, institution, department, and maildisplay. Maybe one of the core developers could weigh in here, are there any plans to add these fields in? If there's not a lot of bandwidth among the core developers to do this right now, would you accept pull requests for these additions? smile


Re: Example of web services token from external application

$
0
0

by Arshad Syed.  

1. First check in moodle site you have enable WEB services or not

how to enable:

1=>site adm->plugins->web services->overview->click on "Enable web services"-> Enable web services "Mark Checkbox".

2=>site adm->plugins->web services->manage Protocols->Enable (which ever protocol you want).

3=>site adm->plugins->web services-> manage tokens->click Add button->select user you want to give access for APIs-> It will generates token(use for accessing APIs).


How to get token:

https://www.yourmoodle.com/login/token.php?username=USERNAME&password=PASSWORD&service=SERVICESHORTNAME


How to use web services:

http://www.yoursite.com/webservice/rest/server.php?wstoken=7c6b2cba5c27e8eabbb8cd8c69c8e5c0&wsfunction=core_completion_get_activities_completion_status&courseid=7&userid=5&moodlewsrestformat=json;

'header' => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST'


Regards

Arshad Syed

https://www.3esofttech.com/

moodle database connection gets aborted by using 25 or more concurrent users

$
0
0

by Navneet Srivastava.  

moodle database connection gets aborted by calling webservice "core_user_create_users

for creating more than 25 concurrent users

could some one please help me



How to fill in Custom Field value using core_user_create_users?

$
0
0

by biboy atienza.  

We defined a custom field on User Profile as below:

Editing profile field: Customer
Short name (must be unique) : customer
Name : Customer


Using this, It will create a user but will NOT supply any value on the custom field Customer:
https://our-sandbox.mrooms.net/webservice/rest/server.php?wstoken=OUT_TOKEN_HERE&wsfunction=core_user_create_users&moodlewsrestformat=xml&users[0][username]=biboyatienza@gmail.com&users[0][password]=00.00.0000&users[0][firstname]=biboy&users[0][lastname]=atienza&users[0][email]=biboyatienza@gmail.com&users[0][city]=Manila&users[0][country]=Philippines&users[0][customfields][0][type]=Customer&users[0][customfields][0][value]=Customer1

I am using this to fetch user details aside from using the Dashbord (https://our-sandbox.mrooms.net/user/editadvanced.php?id=547&course=1)
https://our-sandbox.mrooms.net/webservice/rest/server.php?wstoken=OUT_TOKEN_HERE&wsfunction=core_user_get_users&moodlewsrestformat=xml&criteria[0][key]=id&criteria[0][value]=547


Am I missing something here? Hope someone can help me.




Re: core_user_create_users and core_user_update_users are missing some core fields

$
0
0

by biboy atienza.  

Nicholas,

Are you also populating a Custom Field/s on creating a new user using core_user_create_users?
I am failing on filling it up. sad

System context on api-client role causes the site admin pages to error

$
0
0

by Lorenzo Arribas.  

Hello,


I've set up a moodle installation and configured the web service following the official docs (e.g. https://docs.moodle.org/34/en/Using_web_services).


The API works fine when I create and use a token for theadmin user. But I can't get it to work with a dedicated user and a dedicated role. That role has all the capabilities necessary for the functions I want to invoke (as far as I can see).




 However, when I use the dedicated user's token, the API tells me this 



I've read somewhere that the `webservice/rest:use` capability must be set for the system context too. However, when I activate that option here...


This happens: errors (and stacktraces in debug mode) for all site administration pages afterwards:




I'd appreciate some expert help. I wouldn't want to risk using a god-mode user for our API client.

Thank you in advance for your time smile

Re: How to fill in Custom Field value using core_user_create_users?

$
0
0

by biboy atienza.  

 I made it works, by simple using lowercase of the custom field.

https://our-sandbox.mrooms.net/webservice/rest/server.php?wstoken=OUT_TOKEN_HERE&wsfunction=core_user_create_users&moodlewsrestformat=xml&users[0][username]=biboyatienza@gmail.com&users[0][password]=00.00.0000&users[0][firstname]=biboy&users[0][lastname]=atienza&users[0][email]=biboyatienza@gmail.com&users[0][city]=Manila&users[0][country]=Philippines&users[0][customfields][0][type]=customer&users[0][customfields][0][value]=Customer1


Additional info:
If you have more than 1 custom fields, be sure to adjust the array index like below: 
&users[0][customfields][0][type]=customer
&users[0][customfields][0][value]=Customer1

&users[0][customfields][1][type]=customeremail
&users[0][customfields][1][value]=customer@email.com

&users[0][customfields][2][type]=customerphone
&users[0][customfields][2][value]=+6325217788

So the link would be :

https://our-sandbox.mrooms.net/webservice/rest/server.php?wstoken=OUT_TOKEN_HERE&wsfunction=core_user_create_users&moodlewsrestformat=xml&users[0][username]=biboyatienza@gmail.com&users[0][password]=00.00.0000&users[0][firstname]=biboy&users[0][lastname]=atienza&users[0][email]=biboyatienza@gmail.com&users[0][city]=Manila&users[0][country]=Philippines&users[0][customfields][0][type]=customer&users[0][customfields][0][value]=Customer1&users[0][customfields][1][type]=customeremail&users[0][customfields][1][value]=customer@email.com&users[0][customfields][2][type]=customerphone&users[0][customfields][2][value]=+6325217788


Hope this will help someone else.


br,

biboyatienza




Re: enrol_manual_enrol_users moodle_exception


After Moodle Upgrade getting webservice error

$
0
0

by Muhammad Ammar` Ijaz.  

After i migrated from moodle 3.1 to moodle 3.4 i am getting an error " Coding error detected, it must be fixed by a programmer: Cannot find file with external function implementation" when i click on webservice functions .I have create anew service as well but error remains the same


core_user_get_users_by_field return blank array

$
0
0

by José Ayrám.  

Hi!

I've configured a webservice in a production website, but when I do a call to core_user_get_users_by_field function this returns a blank array except for the webservice user/role.

What permissions or things  I must configure to get the right information for all users?


Best regards.

Re: Should I use Core webservice API in a custom webservice API?

$
0
0

by Arshad Syed.  

There are some API which are supported with moodle_mobile_app and external app.

But some core APIs are not supported with moodle_mobile_app , they can be use external API services but creating custom services by adding core_api's

site adm->plugins->webservices->external services->custom services (click add button).

then add 

site adm->plugins->webservices->manage tokens-> click 'add' button->create your token by adding your custom service name and users to access this API.

so now you have your custom APIs with moodle core_API function, use this APIs in your external application by calling

http://www.yourmoodlesite.com/webservice/rest/server.php?wstoken=718e4ee5732cf9393401d9095e97e9a8&wsfunction=core_completion_get_activities_completion_status&courseid=1&userid=1&moodlewsrestformat=json

I hope this is what you are expecting. if not reply for post.

Regards

Arshad Syed

http://www.3esoftttech.com

Use Moodle with GET webservices

$
0
0

by Fabien Popup.  

Hello,

Is there a way to use Moodle webservices with GET and not in POST ?

Thanks for your help.


Fabien

Re: Use Moodle with GET webservices

Login WS

$
0
0

by Fabien Popup.  

Hello,

I find a sample of the login WS on StackOverflow. I didn't find it in the API documentation (Home > Site administration > Plugins > Web services > API Documentation). 

Why ? 

Is there some other webservices that aren't in this documentation ?


Thank you for your help.

Fabien

Re: Use Moodle with GET webservices


Re: Token WS

$
0
0

by Fabien Popup.  

It's not login WS, but token WS instead.

Re: Can not find data record in database table external_functions

$
0
0

by Arshad Syed.  

Your webservice is unable to recognize the please try this

folder structure

moodleroot->local->wstemplate->db->service.php

moodleroot->local->wstemplate->externallib.php

moodleroot->local->wstemplate->version.php


services.php

$functions = array(
         'local_wstemplate_hello_world' => array(
                                 'classname' => 'local_wstemplate_external',
                                  'methodname' => 'hello_world',
                                  'classpath' => 'local/wstemplate/externallib.php',
                                  'description' => ' Hello world ws example ',
                                  'type' => 'read',
                                  'capabilities' => '',
                                 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
                    ),
       'local_wstemplate_create_groups' => array(
                                  'classname' => 'local_wstemplate_external',
                                  'methodname' => 'create_groups',
                                    'classpath' => 'local/wstemplate/externallib.php',
                                  'description' => 'creating groups in moodle courses',
                                  'type' => 'read',
                                  'capabilities' => '',
                                   'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
                                  ),
                                
             );

// We define the services to install as pre-build services. A pre-build service is not editable by administrator.
$services = array(
'groups plugin webservices' => array(
'functions' => array ('local_wstemplate_hello_world','local_wstemplate_create_groups'),
                'restrictedusers' => 0,
                'shortname'=>'myservice',
                 'enabled'=>1,
                 'shortname' => 'local_groups_ws'
                   )
);

In externallib.php

<?php

require_once ($CFG->libdir.'/externallib.php');

class local_wstemplate_external extends external_api { 

    /**

     * Returns description of method parameters

     * @return external_function_parameters

     */

    public static function create_groups_parameters() {

        return new external_function_parameters(

            array(

                'groups' => new external_multiple_structure(

                    new external_single_structure(

                        array(

                            'courseid' => new external_value(PARAM_INT, 'id of course'),

                            'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),

                            'description' => new external_value(PARAM_RAW, 'group description text'),

                            'enrolmentkey' => new external_value(PARAM_RAW, 'group enrol secret phrase'),

                        )

                    )

                )

            )

        );

    }

    public static function create_groups_returns() {

        return new external_multiple_structure(

            new external_single_structure(

                array(

                    'id' => new external_value(PARAM_INT, 'group record id'),

                    'courseid' => new external_value(PARAM_INT, 'id of course'),

                    'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),

                    'description' => new external_value(PARAM_RAW, 'group description text'),

                    'enrolmentkey' => new external_value(PARAM_RAW, 'group enrol secret phrase'),

                )

            )

        );

    }

    /**

     * Create groups

     * @param array $groups array of group description arrays (with keys groupname and courseid)

     * @return array of newly created groups

     */

    public static function create_groups($groups) { //Don't forget to set it as static

        global $CFG, $DB;

        require_once("$CFG->dirroot/group/lib.php");

 

        $params = self::validate_parameters(self::create_groups_parameters(), array('groups'=>$groups));

 

        $transaction = $DB->start_delegated_transaction(); //If an exception is thrown in the below code, all DB queries in this code will be rollback.

 

        $groups = array();

 

        foreach ($params['groups'] as $group) {

            $group = (object)$group;

 

            if (trim($group->name) == '') {

                throw new invalid_parameter_exception('Invalid group name');

            }

            if ($DB->get_record('groups', array('courseid'=>$group->courseid, 'name'=>$group->name))) {

                throw new invalid_parameter_exception('Group with the same name already exists in the course');

            }

 

            // now security checks

            $context = get_context_instance(CONTEXT_COURSE, $group->courseid);

            self::validate_context($context);

            require_capability('moodle/course:managegroups', $context);

 

            // finally create the group

            $group->id = groups_create_group($group, false);

            $groups[] = (array)$group;

        }

 

        $transaction->allow_commit();

 

        return $groups;

    }


 /**

     * Returns description of method parameters

     * @return external_function_parameters

     */

    public static function hello_world_parameters() {

        return new external_function_parameters(

                array('welcomemessage' => new external_value(PARAM_TEXT, 'The welcome message. By default it is "Hello world,"', VALUE_DEFAULT, 'Hello world, '))

        );

    }


    /**

     * Returns welcome message

     * @return string welcome message

     */

    public static function hello_world($welcomemessage = 'Hello world, ') {

        global $USER;


        //Parameter validation

        //REQUIRED

        $params = self::validate_parameters(self::hello_world_parameters(),

                array('welcomemessage' => $welcomemessage));


        //Context validation

        //OPTIONAL but in most web service it should present

        $context = get_context_instance(CONTEXT_USER, $USER->id);

        self::validate_context($context);


        //Capability checking

        //OPTIONAL but in most web service it should present

        if (!has_capability('moodle/user:viewdetails', $context)) {

            throw new moodle_exception('cannotviewprofile');

        }


        return $params['welcomemessage'] . $USER->firstname ;;

    }


    /**

     * Returns description of method result value

     * @return external_description

     */

    public static function hello_world_returns() {

        return new external_value(PARAM_TEXT, 'The welcome message + user first name');

    }


}


version.php

<?php

$plugin->version = 20111012042;
$plugin->requires = 2010112400; // Requires this Moodle version - at least 2.0
$plugin->component = 'local_wstemplate';
$plugin->cron = 0;
$plugin->release = '1.0 (Build: 2011101202)';
$plugin->maturity = MATURITY_STABLE;

core_enrol_get_enrolled_users doesn't include firstaccess and lastaccess.

$
0
0

by Zadok Lindt.  

core_enrol_get_enrolled_users appears to include firstaccess and lastaccess for the user account rather than for that individual subject.  Is there a way to get a list of the firstaccess and lastaccess time for every student in a course?

Re: How to check username policy before calling core_users_create_user

$
0
0

by Albert Leatherman.  

Hi Jeff, do you know if there is a way to display the username policy on the signup page, just as the password policy is displayed (see attached pic)? Thanks.


error when adding external functions to a web service.

$
0
0

by Rama Bodapati.  

When I try to add external functions to a web service.

I get these errors.

Can anyone direct me about what this error/s is about.

Any plugin that is missing or some missing files



Coding error detected, it must be fixed by a programmer: Cannot find file with external function implementation
    line 87 of /lib/externallib.php: coding_exception thrown
    line 199 of /admin/webservice/forms.php: call to external_api::external_function_info()
    line 204 of /lib/formslib.php: call to external_service_functions_form->definition()
    line 60 of /admin/webservice/service_functions.php: call to moodleform->__construct()

Viewing all 2361 articles
Browse latest View live


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