PHP SDK

A fully-typed client for modern PHP.

Install

$composer require usgm/sdk

Requires PHP 8.1+.

Initialize

1<?php
2
3use Usgm\UsgmClient;
4
5$usgm = new UsgmClient(apiKey: getenv('USGM_API_KEY')); // never hard-code the key

Usage

1<?php
2
3// List mail
4$page = $usgm->mails->list(isRead: false);
5foreach ($page->data as $mail) {
6 echo $mail->id . ' ' . $mail->sender . PHP_EOL;
7}
8
9// Fetch one item
10$mail = $usgm->mails->get('80421');
11
12// Mark it read
13$usgm->mails->update('80421', isRead: true);
14
15// Create a folder and file the mail into it
16$folder = $usgm->folders->create(name: 'Taxes', color: 'blue');
17$usgm->mails->update('80421', folderId: $folder->id);

Error handling

1<?php
2
3use Usgm\Exceptions\UsgmException;
4
5try {
6 $usgm->mails->get('does-not-exist');
7} catch (UsgmException $err) {
8 error_log($err->code . ' ' . $err->statusCode . ' ' . $err->requestId);
9 throw $err;
10}

Transient 429 and 5xx responses are retried automatically with exponential backoff. See Errors for the full problem+json contract.