PHPackages                             zulkarnen/moodleapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. zulkarnen/moodleapi

ActiveLibrary[API Development](/categories/api)

zulkarnen/moodleapi
===================

A library for interacting with Moodle via REST API.

v1.1.8(7mo ago)015[1 issues](https://github.com/zulkarnen-force/moodle-api/issues)PHP

Since Oct 19Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/zulkarnen-force/moodle-api)[ Packagist](https://packagist.org/packages/zulkarnen/moodleapi)[ RSS](/packages/zulkarnen-moodleapi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (12)Used By (0)

**Moodle API PHP Library**
==========================

[](#moodle-api-php-library)

**Requirement**
---------------

[](#requirement)

- [Elearning Plugin](https://github.com/zulkarnen-force/Moodle-Plugin)

**Overview**
------------

[](#overview)

The **Moodle API PHP Library** is a simple PHP library built to interact with the Moodle REST API, providing functions to fetch user details, manage user accounts, retrieve course grades, and more. It is designed to easily integrate into PHP applications like CodeIgniter, Laravel, or any plain PHP project.

This library relies on the llagerlof/moodlerest package to communicate with Moodle's Web Services API.

**Installation**
----------------

[](#installation)

### **Via Composer**

[](#via-composer)

First, make sure Composer is installed. Then, add the library to your project:

```
composer require zulkarnen/moodleapi
```

**Usage**
---------

[](#usage)

### **Initializing the Library**

[](#initializing-the-library)

To use this library, you need to instantiate the MoodleApi class with your Moodle API token and server address.

```
use Zulkarnen\MoodleApi;

$token = 'your_moodle_api_token';
$moodleBaseUrl = 'http://your-moodle-site.com';
$moodleApi = new MoodleApi($token, $moodleBaseUrl);
```

### **Authentication (Getting the Token)**

[](#authentication-getting-the-token)

While the new usage example shows fetching the token via a separate GetToken class (which uses Zulkarnen\\MoodleAuth), the MoodleApi class itself provides a convenience method for obtaining the token using Moodle credentials:

```
