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

Re: Adding activity to courses using API

$
0
0
by Samuel Than.  

Just started to dwell in the same question, was wondering what was the outcome of this ?

cheers. 


Re: Adding activity to courses using API

$
0
0
by Colin Matheson.  

I was able to make a plugin to add a quiz to a course page

https://github.com/cytochromec/moodle-block-quizlet_import

The code that actually adds the quiz starts on line 234 of quizlet_import.php (pasted below)


//create an object with all of the neccesary information to build a quiz
$myQuiz=newstdClass();
$myQuiz->modulename='quiz';
$myQuiz->name=$title;
$myQuiz->introformat=0;
$myQuiz->quizpassword='';
$myQuiz->course=$id1;
$myQuiz->section=$sectionNum;
$myQuiz->timeopen=0;
$myQuiz->timeclose=0;
$myQuiz->timelimit=0;
$myQuiz->grade=$Points;
$myQuiz->sumgrades=$Points;
$myQuiz->gradeperiod=0;
$myQuiz->attempts=1;
$myQuiz->preferredbehaviour='deferredfeedback';
$myQuiz->attemptonlast=0;
$myQuiz->shufflequestions=0;
$myQuiz->grademethod=1;
$myQuiz->questiondecimalpoints=2;
$myQuiz->visible=1;
$myQuiz->questionsperpage=1;
$myQuiz->introeditor=array('text'=>'A matching quiz','format'=>1);

//all of the review options
$myQuiz->attemptduring=1;
$myQuiz->correctnessduring=1;
$myQuiz->marksduring=1;
$myQuiz->specificfeedbackduring=1;
$myQuiz->generalfeedbackduring=1;
$myQuiz->rightanswerduring=1;
$myQuiz->overallfeedbackduring=1;

$myQuiz->attemptimmediately=1;
$myQuiz->correctnessimmediately=1;
$myQuiz->marksimmediately=1;
$myQuiz->specificfeedbackimmediately=1;
$myQuiz->generalfeedbackimmediately=1;
$myQuiz->rightanswerimmediately=1;
$myQuiz->overallfeedbackimmediately=1;

$myQuiz->marksopen=1;

$myQuiz->attemptclosed=1;
$myQuiz->correctnessclosed=1;
$myQuiz->marksclosed=1;
$myQuiz->specificfeedbackclosed=1;
$myQuiz->generalfeedbackclosed=1;
$myQuiz->rightanswerclosed=1;
$myQuiz->overallfeedbackclosed=1;

//actually make the quiz using the function from course/lib.php

$myQuiz2= create_module($myQuiz);
//print_object($myQuiz2);

//get the last added random short answer matching question (which will likely be the one we just added)
$result=$DB->get_records('question',array('qtype'=>'randomsamatch'));
$keys=array_keys($result);
$count=count($keys);

//add the quiz question
quiz_add_quiz_question($result[$keys[$count-1]]->id, $myQuiz2, $page=0, $maxmark=null);

Course Contents on mobile app

$
0
0
by jai sankar.  

I just want to know how to get course contents using webservice. I know the function "core_course_get_contents" Which returns the title and page views as link say

http://localhost/....mod/page/view.php?id=

How should i get the original contents(html) from that using token.
Can i have to modify the code to get the content? Not sure how was it used on moodle mobile

Thanks
Jai

Re: Course Contents on mobile app

$
0
0
by Juan Leyva.  

The function core_course_get_contents returns:

Sections

 - Modules in each section (activities or resources)

 -- If the module is a resource it returns a list of the files used by this resource in the "contents" attribute

That attribute is an array of files, there you will have a fileurl attribute that is the downloadURL for the file (if you are using Web Services you should append the WS token)

Example of URL returned:

http://xxmoodle.net/mobile/moodle25/webservice/pluginfile.php/29/mod_resource/content/3/MontBlancE.pdf?forcedownload=1

How you need to modify the URL to download the file:

http://xxmoodle.net/mobile/moodle25/webservice/pluginfile.php/29/mod_resource/content/3/MontBlancE.pdf?forcedownload=1&token=ABCDEFG...

Here you have a sample response of that WS:

https://github.com/moodlehq/moodlemobile/blob/master/emulator/core_course_get_contents.json

Cheers, Juan

Re: Adding activity to courses using API

$
0
0
by Samuel Than.  

Interesting. Thanks for sharing.. will give that idea a spin...wink

How to create own function in moodle

$
0
0
by Nakul W.  

Hi!

Can anybody let me know the steps to create new functions in a moodle?

Re: Course Contents on mobile app

$
0
0
by jai sankar.  

Thanks juan.  I found it out thru documentation.

 BTW, is there option exists to download/view the activities via webservice..

Thanks

Jai

Re: Problem with core_files_upload Web Sevice

$
0
0
by Damyon Wiese.  

The context id is not required (best to leave it out really)

For private files the itemid is not needed either.

The error you are getting is because the

contextlevel must be set to 'user' and the instanceid must be the id of the user

Here is an alternative way to upload files:

https://docs.moodle.org/dev/Web_services_files_handling

Re: How to get a list of courses for the teacher?

$
0
0
by Juan Leyva.  

You should:

First: core_enrol_get_users_courses for returning all the courses

Next: Get all the participants of that courses using the function: core_enrol_get_enrolled_users (passing as argument withcapability a capability your teachers must have)

And then iterate the courses/users and discard the courses where the user was not returned by the enrolled_users funciton

Re: Problem with core_files_upload Web Sevice

$
0
0
by Amith Ram.  

Thanks a lot.

It solved my issue.

One more Query , can i upload a file for a course  through the same service?


Re: Problem with core_files_upload Web Sevice

$
0
0
by Amith Ram.  

One More problem i noticed is that, i am getting a responce after uploading the file like 

"http://localhost:8099/pluginfile.php/24/user/private/sample.txt"

But,when i click on this link,i am getting file not found Error .

How to Upload a File and Map it to Course

Re: Moodle API to get Course Completion Data

$
0
0
by Ryan Chausse.  

Seconded. Is there any example code for this? Relevant service/function?


Any relevant information would be much appreciated. Thank you very much.


-Ryan Chausse

API access error for core_user_get_users

$
0
0
by Jury Gerasimov.  

My Moodle installation on "Site administration - Plugins - Web services - External services - Functions" lists all the function available for external API - to be exact, to the service "Moodle mobile web service".

The list has only 20% from all the functions described in API documentation. For example, it has moodle_user_get_users_by_id function which returns a correct result when called from API. But when I try to call the function I need - core_user_get_users - which is not listed on that page, I get webservice_access_exception as result.

There are on buttons or links which could add API access rights to the required functions.

I don't say the API rights system is overcomplicated (while it is) - please anyone tell me how to make API calls for core_user_get_users done right?

Web Services

$
0
0
by Brendan Flynn.  

What is the difference between using the web services like REST, Soap, OSLC etc and Web RTc. I am doing a project for college, where i have a simulated network of wind turbines and a user front end to show their performances. I need to consider which web services will work best for this project and i need it to be near real time. Do I need to consider Web RTC, would it be too expensive, or should i just stick to Web services and protocol


External Database authentication via Webservices

$
0
0
by Amer Hamade.  

Hello,

We are trying to develop an application which will create and manage moodle users. 

What we are looking for is a plugin in moodle that allows it to authenticate against external web services  provided by this custom application.


The user puts his credentials on Moodle.

Moodle will contact the external database via webservices for authentication.


Appreciate the help!

thnx,

amer

Re: Get user token in SSO environment

$
0
0
by Vignesh SP.  

Dear Johan Reinalda,


is there a solution for this? if you have found a solution can you please share that knowledge?

i have a similar requirement and your reply will help me.


Thanks

Vignesh

Re: REST Service core_course_create_courses

$
0
0
by Jerry Ahern.  

Hi Joshua,

I'm having trouble with this REST service too. I haven't written any code yet, I'm trying to call the web service directly using a Chrome extension called Postman (see screenshot).

I've followed the instructions precisely to enable the service: 

  • enabled the web service
  • enabled the REST protocol
  • created a user and set their capability
  • created a service and assigned the correct function and user
  • created a token for the user

However, when passing in my wstoken, wsfunction (core_course_create_courses) and moodlewsrestformat (json), and the following values:

  • courses[0][fullname] = "Get Started with Moodle"
  • courses[0][shortname] = "01MOOD"
  • courses[0][categeoryid] = "101" (the category 101 does exist)

I'm getting this error: Missing required key in single structure: courses.

Can you tell me how you got past this error? What other errors did you resolve? I know this was a while ago but I can't seem to find much information (on forums or otherwise) about core_course_create_courses.

Thanks in advance,

Jerry

Debugging web services - How ?

$
0
0
by julian robinson.  

Hi All

I'm working on querying course data from a 3rd party web portal and am having trouble getting the course contents for some courses.

I've enabled the REST endpoint, added the necessary functions to it, got a user token and its working with a simple course I've created through the Moodle UI. However another course which has been imported through the backup/restore process is returning a "cannotgetcoursecontents" exception with no other detail. 

Now I'm not too familiar with Moodle, or PHP, but I've tried a couple of things that looked promising, but cant seem to get any more info.

I've tried enabling php logging in the config.php file using :

ini_set ('log_errors', 'on');
ini_set("error_log", "/tmp/php-error.log");
ini_set ('error_reporting', E_ALL);

This is logging errors encountered when browsing Moodle, but nothing is recorded when calling the web service...

In the I've tried changing the define('NO_DEBUG_DISPLAY', true); line to define('NO_DEBUG_DISPLAY', false);  in the /webservice/rest.server.php file in the hopes that this caused the web services to write to the above log file. Nope. 

I've also enabled/disabled debugging in the Moodle site settings, nothing.

Am I missing something here? Is it possible to debug the web service call and narrow down what's going wrong, rather than a generic "it broke" error ??

Any help is much appreciated. 

Cheers,



Re: WSOD when trying to access soap webservice

$
0
0
by Amer Hamade.  

Hello,


Facing the same problem. 

Any hint is appreciated.


thnx,

amer

Viewing all 2364 articles
Browse latest View live


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