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

Re: External application interaction with Moodle 1.9.13

$
0
0

by Mary Cooch.  

Andrew - the link Rahul gave is for Moodle sites later than 1.9, which is why you can't see it. Moodle 1.9 is nearly ten years old. I do understand that some plugins have held you back from upgrading. You would need to see if you can find someone who can upgrade the plugins for you if you are unable to do it yourself.


Re: External application interaction with Moodle 1.9.13

$
0
0

by Andrew Go.  

Thank you for your feedback!


Need some time for explore.

Re: Problem in core_files_upload API

$
0
0

by Thiago Cristiano.  

Hi, did you solve it?
I have the same problem and I have not found a solution...

i can't create user via webservice.

$
0
0

by sadaf sadafian.  

i use this code 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>V6</title>

</head>


<body>


<?php

//load curl.php

require_once('curl.php');


function randomPassword() //according to Moodle password requirements

{

$part1 = "";

$part2 = "";

$part3 = "";

    //alphanumeric LOWER

$alphabet = "abcdefghijklmnopqrstuwxyz";

    $password_created = array(); //remember to declare $pass as an array

    $alphabetLength = strlen($alphabet) - 1; //put the length -1 in cache

    for ($i = 0; $i < 3; $i++) 

{

        $pos = rand(0, $alphabetLength); // rand(int $min , int $max)

        $password_created[] = $alphabet[$pos];

    }

$part1 = implode($password_created); //turn the array into a string

//echo"<br/>part1 = $part1";


//alphanumeric UPPER

$alphabet = "ABCDEFGHIJKLMNOPQRSTUWXYZ";

    $password_created = array(); //remember to declare $pass as an array

    $alphabetLength = strlen($alphabet) - 1; //put the length -1 in cache

    for ($i = 0; $i < 3; $i++) 

{

        $pos = rand(0, $alphabetLength); // rand(int $min , int $max)

        $password_created[] = $alphabet[$pos];

    }

$part2 = implode($password_created); //turn the array into a string

//echo"<br/>part2 = $part2";


//alphanumeric NUMBER

$alphabet = "0123456789";

    $password_created = array(); //remember to declare $pass as an array

    $alphabetLength = strlen($alphabet) - 1; //put the length -1 in cache

    for ($i = 0; $i < 2; $i++) 

{

        $pos = rand(0, $alphabetLength); // rand(int $min , int $max)

        $password_created[] = $alphabet[$pos];

    }

$part3 = implode($password_created); //turn the array into a string

//echo"<br/>part3 = $part3";

$password = $part1 . $part2 . $part3 . "#";

return $password;

}


function getCDate()

{

$format = "Ymd";

$fulldate = date($format);

//echo"<br/>fulldate = $fulldate";

return $fulldate;

}


function enrol($user_id, $course_id) 

{

$role_id = 5; //assign role to be Student

$domainname = 'http://demo2.lmskaran.com'; //paste your domain here

$wstoken = 'f7298eeaa8ce6110590876c********'; //here paste your enrol token 

$wsfunctionname = 'enrol_manual_enrol_users';

$enrolment = array( 'roleid' => $role_id, 'userid' => $user_id, 'courseid' => $course_id );

$enrolments = array($enrolment);

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

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

$serverurl = $domainname . "/webservice/rest/server.php?wstoken=" . $wstoken . "&wsfunction=" . $wsfunctionname;

$curl = new curl;

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

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

print_r($resp);

}


function getUserDetails()

{

$firstname = "TestUser";

$lastname = "TestUser";

$email  = "TestUser@zzz.gr";

$city = "Thessaloniki";

$country  = "EL";

$description= "ZZZ";

//assign username

//get first two letters of name and surname

//$strlength_user = strlen($firstname);

//$strlength_pass = strlen($lastname);

$rest_firstname = substr($firstname, 0, 2);

$rest_lastname  = substr($lastname, 0, 2);

$part1 = $rest_firstname . $rest_lastname;

$part1 = strtolower($part1);

//echo"<br/>part1 = $part1";

$dt = getCDate();

$part2 = substr($dt, -4);

//echo"<br/>part2 = $part2";

$username = $part1 . "." . $part2;

echo"<br/>Username = $username";

//assign password

$password = randomPassword();

echo"<br/>Password = $password";

//call WS core_user_create_user of moodle to store the new user

$domainname = 'http://www.demo2.lmskaran.com';

$wstoken = 'e560c275cdc59b15b323193********'; //here paste your create user token 

$wsfunctionname = 'core_user_create_users';

//REST return value

$restformat = 'xml'; 

//parameters

$user1 = new stdClass();

$user1->username = $username;

$user1->password = $password;

$user1->firstname = $firstname;

$user1->lastname = $lastname;

$user1->email = $email;

$user1->auth = 'manual';

$user1->idnumber = 'numberID';

$user1->lang = 'en';

$user1->city = $city;

$user1->country = $country;

$user1->description = $description;

$users = array($user1);

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

//REST call

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

$serverurl = $domainname . "/webservice/rest/server.php?wstoken=" . $wstoken . "&wsfunction=" . $wsfunctionname;

$curl = new curl;

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

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

print_r($resp);

//get id from $resp

$xml_tree = new SimpleXMLElement($resp);

echo '</br>' ; 

echo 'رسپ این پایینی users' ; 

echo '</br>' ; 

print_r($users);

echo '</br>' ; 

echo '</br>' ; 

echo 'رسپ این پایینی params' ; 

echo '</br>' ; 

print_r($params);

echo '</br>' ; 

echo '</br>' ; 

echo 'رسپ این پایینی restformat' ; 

echo '</br>' ; 

print_r($restformat);

echo '</br>' ; 

print_r($xml_tree);

echo '</br>' ;   

print_r($xml_tree);

$value = $xml_tree->MULTIPLE->SINGLE->KEY->VALUE;

$user_id = intval(sprintf("%s",$value));

echo"<br/>user_id number = $user_id";

//enrol_manual_enrol_users 

//for($i = 64; $i < 70; $i++) //where 64,65,66,67,68,69 are the six ids of the six courses of phase 1

for($i = 7; $i < 8; $i++)

{

echo "\nThe user has been successfully enrolled to course " . $i;

$course_id = $i;

echo '</br>' ; 

enrol($user_id, $course_id);

}

}


getUserDetails();


?>

</body>

</html>+




but when i  want to run this code, it can not create user and say this error:

codingerror

Invalid call to role_assign(), userid can not be empty


i,m using this help:

https://moodle.org/mod/forum/discuss.php?d=319039

please help me

Custom Webservice not showing in admin panel

assignment_id in URL doesn't match with database??

$
0
0

by Jülide Dursun.  

Hi everyone,


I am sending grades from an excel-sheet to moodle via web services. I'm calling the user_id, grade_value, a comment and the assignment_id. It is really strange, but the assignment_id in the URL does not match with the assignment_id in the database. When I use the assignment_id of the URL, the grades are not sent from excel sheet to moodle. So I always have to check the assignment_id in the database, which is awkward.

What do I have to do to make assignment_id in URL and database same??

Can anyone help please?


Re: assignment_id in URL doesn't match with database??

$
0
0

by Christopher Molnar.  

Do you know when this changed? It has broken all of my grade scripts using the web services API.


assignmentid does not match displayed assignment ID

$
0
0

by Christopher Molnar.  

The assignment ID in the database does not seem to match the assignment id displayed on the URL and thus it is almost impossible to use the webservices API to put grades into assignments.


Happy Diwali

$
0
0

by Saanvi Agarwal.  

Wishing someone special on Diwali? What about sending quotes instead of simply written words? Diwali Mentions have a greater positive impact on other persons and can give you much respect in other's eye.

happy diwali image download

Re: Problem in core_files_upload API

$
0
0

by Thiago Cristiano.  

Hi, did you solve it?
I have the same problem and I have not found a solution...

Rest API for authentication

$
0
0

by Muhammad Umair Gillani.  

Dear All,

I am developing a Mobile application and i want to access Moodle in my application.

i want to know is there any api which i can hit to authenticate user?

e.g

url is moodle/login/index.php and i want to pass username and password as parameter and get response whether the user is logged on server or user entered invalid credentials.


if credentials are correct i want to open Moodle then which should not ask for login from user.


any help will be appreciated. Thanks


REST API: check if user exists?

$
0
0

by Spencer Smart.  

Hi, I'm successfully using the REST API to create users and enrol them on existing courses.

However, I'm unable to find a call that checks to see if the user already exists on the Moodle setup. When I try to add a user that already exists, the response is more like an error message and doesn't return any indication that the user is there or not. It's only by testing and elimination that I've established what is happening!

I've created a workaround using a separate database to store user info (not at all ideal from many perspectives) using calls to retrieve users that are already enrolled in courses, but that doesn't work if a user is registered on Moodle but not enrolled on any course.

Can anyone suggest please either a call to the API that will retrieve user details of an unenrolled user or a way of just retrieving their UID? 

I'm sure the function is out there somewhere and I'm just being stupid...

Many thanks for your time! 

Re: No API to create an assignment/module

$
0
0

by Fred Tibbitts.  

I also need to be able to create assignments via the web service API.  Is there any work-around for this? 

ตอบ: No API to create an assignment/module

$
0
0

by Techspace IT Outsource.  

smile

IT Outsource Services

Re: How to read completion criteria API to get course data.


Update user data problem

$
0
0

by Mohammed Essaid MEZERREG.  

I am trying to use core_user_update_users function but I am getting this error with all users?

string(98) "{"exception":"moodle_exception","errorcode":"usernotfullysetup","message":"User not fully set-up"}"

array(1) {

  [0] =>

  string(98) "{"exception":"moodle_exception","errorcode":"usernotfullysetup","message":"User not fully set-up"}"

}

Is there special configuration of this function, I tried this with 5 servers and they all returned the same message?

The user of the external webservices has all capabilities and can do everything.

Re: REST API: check if user exists?

$
0
0

by Mohammed Essaid MEZERREG.  

We created our solution for this, a local plugin and added external service to it, one of them is for checking the existence of the user through it's more custom to our needs and what we are willing to achieve, but you can always try this solution because it's the ideal one till We have an official function for it.

The common thing between our service and yours is :


just put this inside your externallib.php file, for starter you can put it directly in externallib.php file under the /user root directory in moodle. And don't forget to declare it in services.php file, you can find it under /lib/db/services.php if you put the function in the user folder externallib.php file. Or the services.php under /db in your plugin.

Re: REST API: check if user exists?

$
0
0

by Spencer Smart.  

Hi, many thanks for the detailed reply. Unfortunately, our installation is hosted and the provider won't allow any third-party content (apart from their own  code...) to be installed on the setup. Frustrating that I can't even give it a try!

Thanks for your time and help though, really is appreciated.smile

Re: REST API: check if user exists?

$
0
0

by Mohammed Essaid MEZERREG.  

Well you can still use the plugin installation interface in Moodle to install your tiny little plugin. Just clone the template provided by the Moodle team in github and put these stuff in it, zip it and upload it to your moodle as a plugin.

https://github.com/moodlehq/moodle-local_wstemplate

Re: REST API: check if user exists?

$
0
0

by Spencer Smart.  

Hi, thanks for reply, much appreciated.

Again, unfortunately our installation doesn't allow us to install plugins either, it really is locked down tight so we can't make any significant changes and certainly none to core setup. I think supplier wants to keep integrity of site, which is kind of understandable.

I'm going to do an alternative workaround that sits in front of the API that will eliminate the need for the call. Not the perfect fix, but best I can do as far as I can see.

Thanks again,

Viewing all 2366 articles
Browse latest View live


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