PHP client for LORIS REST API. Authentication via JWT.
composer require aces/loris-php-api-client<?php
require_once __DIR__ . '/vendor/autoload.php';
use LORISClient\Configuration;
$baseUrl = 'https://your-loris.ca';
$apiVersion = 'v0.0.4-dev'; // v0.0.3 | v0.0.3-dev | v0.0.4-dev | v0.0.4
$config = Configuration::getDefaultConfiguration()
->setHost("{$baseUrl}/api/{$apiVersion}");use LORISClient\Api\AuthenticationApi;
use LORISClient\Model\LoginRequest;
use GuzzleHttp\Client;
$authApi = new AuthenticationApi(new Client(), $config);
$response = $authApi->login(new LoginRequest([
'username' => 'user',
'password' => 'pass'
]));
$config->setAccessToken($response->getToken());use LORISClient\Api\InstrumentManagerApi;
use SplFileObject;
$api = new InstrumentManagerApi(new Client(), $config);
// Install instrument (LINST or REDCap CSV)
$api->installInstrument(new SplFileObject('instrument.linst'));
// Get expected CSV headers
$headers = $api->getInstrumentDataHeaders('CREATE_SESSIONS', 'demographics');
// Upload data - CREATE_SESSIONS (creates missing candidates/sessions)
$result = $api->uploadInstrumentData(
'CREATE_SESSIONS',
'demographics',
null,
new SplFileObject('data.csv')
);
// Upload data - VALIDATE_SESSIONS (requires existing candidates/sessions)
$result = $api->uploadInstrumentData(
'VALIDATE_SESSIONS',
'demographics',
null,
new SplFileObject('data.csv')
);
// Check result
if ($result->getSuccess()) {
echo $result->getMessage();
foreach ($result->getIdMapping() ?? [] as $map) {
echo "{$map->getExtStudyId()} → {$map->getCandId()}\n";
}
}| Method | HTTP | Endpoint | Description |
|---|---|---|---|
login() |
POST | /login |
Get JWT token |
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
installInstrument() |
POST | /instrument_manager |
Install LINST/REDCap instrument |
getInstrumentDataHeaders() |
GET | /instrument_manager/instrument_data |
Get expected CSV headers |
uploadInstrumentData() |
POST | /instrument_manager/instrument_data |
Bulk upload CSV data |
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
getCandidates() |
GET | /candidates |
List all candidates |
getCandidate() |
GET | /candidates/{candid} |
Get candidate details |
createCandidate() |
POST | /candidates |
Create new candidate |
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
getVisit() |
GET | /candidates/{candid}/{visit} |
Get visit details |
createVisit() |
PUT | /candidates/{candid}/{visit} |
Create new visit |
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
getVisitInstruments() |
GET | /candidates/{candid}/{visit}/instruments |
List visit instruments |
getInstrumentData() |
GET | /candidates/{candid}/{visit}/instruments/{instrument} |
Get instrument data |
putInstrumentData() |
PUT | /candidates/{candid}/{visit}/instruments/{instrument} |
Replace instrument data |
patchInstrumentData() |
PATCH | /candidates/{candid}/{visit}/instruments/{instrument} |
Update instrument data |
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
getProjects() |
GET | /projects |
List projects |
getProject() |
GET | /projects/{project} |
Get project details |
getProjectInstruments() |
GET | /projects/{project}/instruments |
List project instruments |
| Method | HTTP | Endpoint | Description |
|---|---|---|---|
getSites() |
GET | /sites |
List sites |
| Model | Usage |
|---|---|
LoginRequest |
Authentication credentials |
CandidateCreateRequest |
New candidate data |
VisitCreateRequest |
New visit data |
InstrumentDataRequest |
Instrument data update |
| Model | Usage |
|---|---|
LoginResponse |
JWT token |
CandidateObject |
Candidate details |
CandidatesResponse |
List of candidates |
VisitObject |
Visit details |
InstrumentData |
Instrument data (Meta + Data) |
InstrumentDataResponse |
Bulk upload result (success, message, idMapping) |
IdMapping |
PSCID → CandID mapping |
ProjectResponse |
Project with instruments |
SitesResponse |
List of sites |
ErrorResponse |
Error message |
SuccessResponse |
Success confirmation |
# Using local OpenAPI Generator
./generate.sh
# Clean regenerate
./generate.sh --cleanThe script:
- Reads
schema.ymlandopenapi-config.json - Generates PHP client to
lib/
| Action | Behavior |
|---|---|
CREATE_SESSIONS |
Creates candidates/sessions if missing |
VALIDATE_SESSIONS |
Fails if candidate/session doesn't exist |