yoopies / francetravail-php
France Travail (francetravail.io) API client built on top of Guzzle
Requires
- php: ^8.2
- ext-json: *
- guzzlehttp/guzzle: ^6.5|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.5|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
PHP client for the francetravail.io partner APIs, built on top of Guzzle.
Supported APIs
| API | Client | Version |
|---|---|---|
| Suivre mes offres transférées (SMOT) | FranceTravail\SmotClient |
v1 |
Requirements
- PHP 8.2+
- Guzzle 6.5 or 7
Installation
composer require yoopies/francetravail-php
Authentication
Every client uses the OAuth2 client credentials flow on the partner realm
(https://entreprise.francetravail.fr/connexion/oauth2/access_token?realm=/partenaire).
The access token is requested lazily, cached in memory and renewed before it expires. If the API
rejects a token (HTTP 401), a new token is requested and the call is retried once.
use FranceTravail\SmotClient; $client = new SmotClient('clientId', 'clientSecret'); // Optional arguments: custom Guzzle client, API URL, token URL and scopes $client = new SmotClient('clientId', 'clientSecret', $guzzleClient, $apiUrl, $tokenUrl, $scopes);
SMOT — Suivre mes offres transférées
Reports about the offers files sent through AOM. France Travail recommends calling them daily, a few hours after the offers file was sent.
use FranceTravail\Model\Smot\ReportRequest; // Date range (dateDebut / dateFin); same day = whole day. Partner codes are optional filters. $request = new ReportRequest(new DateTimeImmutable('-7 days'), new DateTimeImmutable(), ['YOOPIES']); $request = ReportRequest::forDay(new DateTimeImmutable('yesterday'));
Movements report (POST /rapport/mouvements)
use FranceTravail\Model\Smot\Enum\MovementStatus; // One page (page starts at 1, 1 to 10 000 items per page, 1 000 recommended) $report = $client->report->movements($request, page: 1, perPage: 1000); $report->pagination?->totalPages; // Or every page foreach ($client->report->iterateMovements($request) as $movement) { $movement->partnerOfferReference; // referenceOffrePartenaire $movement->franceTravailOfferReference; // referenceOffreFT $movement->status; // ?MovementStatus (null if unknown to this SDK) $movement->rawStatus; // raw API string foreach ($movement->anomalies as $anomaly) { $anomaly->code; // e.g. 9006 $anomaly->label; $anomaly->isRejection(); } }
File non-compliances report (POST /rapport/nonConformitesFichiers)
$report = $client->report->fileNonCompliances($request); foreach ($client->report->iterateFileNonCompliances($request) as $nonCompliance) { $nonCompliance->partnerOfferReference; $nonCompliance->anomaly?->label; }
An empty result (HTTP 204) returns an empty report (isEmpty(), pagination === null).
Errors
| Exception | When |
|---|---|
FranceTravail\Exception\AuthenticationException |
Token cannot be obtained |
FranceTravail\Exception\ApiException |
HTTP status >= 400 or invalid JSON (getStatusCode(), getResponseBody(), getDecodedResponseBody()) |
FranceTravail\Exception\FranceTravailException |
Base class, also network errors |
InvalidArgumentException |
Invalid input (pagination, date range...) |
Development
composer install
composer test # PHPUnit
composer cs # PHP-CS-Fixer dry run