You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe
The file in webservices/api/example/add_courses_session.php is actually to add users not courses
To Reproduce
Steps to reproduce the behavior:
I checked both the latest download zip file and the repository on Github Both are wrong
Expected behavior
API to add course to a Session but adds users
Screenshots
The file in webservices/api/example/add_courses_session.php is actually to add users not courses
Desktop (please complete the following information):
OS: Mac
Browser all
**Server
OS: windows
Version of Chamilo: 1.11.x
Version of PHP: 7.4
Additional context
Add any other context about the problem here.
The file in webservices/api/example/add_courses_session.php is actually to add users not courses
Test example to user API v2.php.
Using Guzzle' HTTP client to call the API endpoint and make requests.
Change URL on the first lines of createUser() below to suit your needs.
*/
use GuzzleHttp\Client as Client;
// set your URL, username and password here to use it for all webservices in this test file.
$webserviceURL = 'http://MYDOMAIN/main/webservices/api/';
$webserviceUsername = 'EMS';
'password';
@return string
*/
function authenticate()
{
global $webserviceURL;
global $webserviceUsername;
global $webservicePassword;
$client = new Client([
'base_uri' => $webserviceURL,
]);
@return int
*/
function addUsersToSession($apiKey)
{
global $webserviceURL;
global $webserviceUsername;
$client = new Client([
'base_uri' => $webserviceURL,
]);
$response = $client->post(
'v2.php',
[
'form_params' => [
// data for the user who makes the request
'action' => 'add_users_session',
'username' => $webserviceUsername,
'api_key' => $apiKey,
// data for users and session
'id_session' => 1,
'list_users' => [
'5',
'6',
'7',
],
],
]
);
if ($response->getStatusCode() !== 200) {
throw new Exception('Entry denied with code : '.$response->getStatusCode());
}
Describe
The file in webservices/api/example/add_courses_session.php is actually to add users not courses
To Reproduce
Steps to reproduce the behavior:
I checked both the latest download zip file and the repository on Github Both are wrong
Expected behavior
API to add course to a Session but adds users
Screenshots
The file in webservices/api/example/add_courses_session.php is actually to add users not courses
Desktop (please complete the following information):
**Server
Additional context
Add any other context about the problem here.
The file in webservices/api/example/add_courses_session.php is actually to add users not courses
See content of the example file.
`<?php
/* For licensing terms, see /license.txt */
require_once DIR.'/../../../../vendor/autoload.php';
/**
Test example to user API v2.php.
Using Guzzle' HTTP client to call the API endpoint and make requests.
Change URL on the first lines of createUser() below to suit your needs.
*/
use GuzzleHttp\Client as Client;
// set your URL, username and password here to use it for all webservices in this test file.
$webserviceURL = 'http://MYDOMAIN/main/webservices/api/';
$webserviceUsername = 'EMS';
'password';
/**
Make a request to get the API key for admin user.
@throws Exception
@return string
*/
function authenticate()
{
global $webserviceURL;
global $webserviceUsername;
global $webservicePassword;
$client = new Client([
'base_uri' => $webserviceURL,
]);
$response = $client->post('v2.php', [
'form_params' => [
'action' => 'authenticate',
'username' => $webserviceUsername,
'password' => $webservicePassword,
],
]);
if ($response->getStatusCode() !== 200) {
throw new Exception('Entry denied with code : '.$response->getStatusCode());
}
$jsonResponse = json_decode($response->getBody()->getContents());
if ($jsonResponse->error) {
throw new Exception('Authentication failed because : '.$jsonResponse->message);
}
return $jsonResponse->data->apiKey;
}
/**
@param $apiKey
@throws Exception
@return int
*/
function addUsersToSession($apiKey)
{
global $webserviceURL;
global $webserviceUsername;
$client = new Client([
'base_uri' => $webserviceURL,
]);
$response = $client->post(
'v2.php',
[
'form_params' => [
// data for the user who makes the request
'action' => 'add_users_session',
'username' => $webserviceUsername,
'api_key' => $apiKey,
// data for users and session
'id_session' => 1,
'list_users' => [
'5',
'6',
'7',
],
],
]
);
if ($response->getStatusCode() !== 200) {
throw new Exception('Entry denied with code : '.$response->getStatusCode());
}
$jsonResponse = json_decode($response->getBody()->getContents());
if ($jsonResponse->error) {
throw new Exception('Users not assigned to session because : '.$jsonResponse->message);
}
return $jsonResponse->data[0];
}
$apiKey = authenticate();
//adding users with id 5, 6, 7 to session with id 1
if (addUsersToSession($apiKey)) {
echo 'Users successfully added';
}
`
The text was updated successfully, but these errors were encountered: