Oushodh PHP SDK
The official PHP client for the Oushodh API.

What Oushodh is
Oushodh serves Bangladesh medicine data over a REST API: brands, generics, prices and makers. Make a key in the member
portal at app.oushodh.dev, and read the docs at oushodh.dev/docs.
The SDK needs PHP 8.2 or newer. Its one runtime dependency is Guzzle 8.
Install
Install it with Composer from Packagist:
composer require oushodh/oushodh-php
Quickstart
Sign up at app.oushodh.dev/sign-up with your email or Google. A new account starts
free: one key on a test app, 1,000 requests a month and 10 a minute. On the API keys page, add a test app, then make a
key for it. A key starts with oush_ and is shown once. Keep it on your server: never put it in a web page or an app.
A production app needs a plan; plans start at $5 a month (pricing).
export OUSHODH_API_KEY=oush_...
use Oushodh\Client;
$oushodh = new Client(); // reads OUSHODH_API_KEY
$result = $oushodh->search('paracetamol', limit: 5);
foreach ($result->items as $medicine) {
echo $medicine->id, ' ', $medicine->productName, "\n";
}
$medicine = $oushodh->getMedicine('MED-012933');
echo $medicine->productName, ': ', $medicine->prices->unit?->amount, " BDT a unit\n";
new Client('oush_...') takes the key directly. With no key and no OUSHODH_API_KEY, it throws an
InvalidArgumentException.
| Method |
Route |
Returns |
meta() |
GET /v1/meta |
Meta |
listMedicines(limit:, cursor:, updatedSince:, q:, generic:, form:, manufacturer:) |
GET /v1/medicines |
Page |
medicines(limit:, cursor:, updatedSince:, q:, generic:, form:, manufacturer:) |
GET /v1/medicines, every page |
Generator of Medicine |
search($q, limit:) |
GET /v1/medicines/search |
SearchResult |
getMedicine($ref) |
GET /v1/medicines/{ref} |
MedicineDetail |
lookupMedicines($refs) |
POST /v1/medicines/lookup |
LookupResult |
listManufacturers(limit:, cursor:, updatedSince:) |
GET /v1/manufacturers |
ManufacturerPage |
manufacturers(limit:, cursor:, updatedSince:) |
GET /v1/manufacturers, every page |
Generator of Manufacturer |
getManufacturer($id) |
GET /v1/manufacturers/{id} |
Manufacturer |
imageUrl($file) |
none |
the picture’s address |
getImage($file) |
GET /v1/images/{file} |
the picture’s bytes |
meta() names your account and counts the medicines your plan reads. Call it to check that a key works.
getMedicine() takes an ID in any profile, an old ID or a UUID. The answer always carries the medicine’s current ID,
and its monograph.
Fields keep their API names in camel case: product_name is $medicine->productName. A value no source gives is
null. Every model also has raw, the object as the API sent it, so a field added after this version is still
there: $medicine->raw['new_field'].
Paging
listMedicines() returns one page: items, next and total. Pass next back as cursor for the next page.
next is null on the last page. limit is 1 to 500, and 100 when you leave it out.
$page = $oushodh->listMedicines(limit: 500);
while (true) {
foreach ($page->items as $medicine) {
// ...
}
if ($page->next === null) {
break;
}
$page = $oushodh->listMedicines(limit: 500, cursor: $page->next);
}
medicines() does the same for you. It yields every medicine and follows next to the end:
foreach ($oushodh->medicines(limit: 500) as $medicine) {
echo $medicine->id, ' ', $medicine->productName, "\n";
}
Search has no cursor. To page through every match, use medicines(q: ...).
Filters
listMedicines() and medicines() take three more filters. Each is sent only when you set it, and they combine with
q:
generic: only medicines with this generic name, written as genericName gives it, any case. It lists the
medicines with that generic name.
form: only medicines in this dosage form, written as dosageForm gives it, any case.
manufacturer: only medicines of this manufacturer, by its ID ($medicine->manufacturer?->id). A division’s medicines
count under its company.
foreach ($oushodh->medicines(generic: 'Paracetamol', form: 'Tablet') as $medicine) {
echo $medicine->id, ' ', $medicine->productName, "\n";
}
Looking up many medicines
lookupMedicines() takes 1 to 100 IDs, old IDs or UUIDs, and answers in one call. items keeps the order of the
refs. Each item has the ref as sent, and either a medicine or null with an error: not_found (no medicine
has this ID) or ambiguous (a display ID in more than one profile: send the UUID). A lookup leaves out the
monograph; use getMedicine() for that. The client does not check the count: the API answers 400 for none or for
more than 100.
$result = $oushodh->lookupMedicines(['MED-012933', 'MED-999999']);
foreach ($result->items as $item) {
echo $item->ref, ': ', $item->medicine?->productName ?? $item->error?->code, "\n";
}
Each ref counts as one request against your minute and month, so a batch fits in what is left or is refused whole.
Manufacturers
A manufacturer is a company under its DGDA register name. A medicine’s manufacturer is the whole Manufacturer
(or null when it has none), the same object getManufacturer() answers: $medicine->manufacturer?->name. names
lists its divisions and other spellings (role is division or name).
$maker = $oushodh->getManufacturer($medicine->manufacturer->id);
echo $maker->name, ': ', $maker->medicines, " medicines\n";
foreach ($oushodh->manufacturers(limit: 500) as $maker) {
// ...
}
listManufacturers() pages like listMedicines() (items, next, total) and takes updatedSince.
about is a short profile (paragraphs, reviewed) or null; reviewed is false while no person has checked the
text. An unknown ID throws a NotFoundException.
Keeping a copy in sync
Copy every medicine once, then fetch only what changed.
- The first sync pages through every medicine and keeps the newest
lastUpdated.
- Each later sync passes that time as
updatedSince and pages to the end. It gets the medicines changed at or after
that time, oldest change first.
$since = loadLastSync(); // null on the first sync
foreach ($oushodh->medicines(limit: 500, updatedSince: $since) as $medicine) {
saveMedicine($medicine->uuid, $medicine);
if ($since === null || $medicine->lastUpdated > $since) {
$since = $medicine->lastUpdated;
}
}
saveLastSync($since);
updatedSince takes a string such as 2026-11-08T09:30:00Z, or a DateTimeInterface. The client sends a
DateTimeInterface in UTC, to the whole second.
- “At or after” means a change in the same second is never missed. The medicine that set the time comes back once
more, so save by
uuid.
- Store
uuid as the key: it never changes. Show id to people.
- Medicines are never deleted and IDs are never reused, so a sync never has to remove one.
Images
productImage is the address of the medicine’s picture, or null. images lists every picture, productImage
first. An address under /v1/images/ is a copy Oushodh keeps. It needs no key, so an <img> tag can show it, and it
never changes. Any other address belongs to the source, and it can move or be removed.
getImage() takes the file name, not the whole address, and sends no key:
$url = $medicine->productImage;
if ($url !== null && str_starts_with($url, $oushodh->imageUrl(''))) {
$jpeg = $oushodh->getImage(basename($url));
}
imageUrl($file) builds the address of a file, such as
50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c.jpg.
Errors
Every error is an Oushodh\Exception\OushodhException. It has status, the HTTP status, and errorCode, an
Oushodh\ErrorCode. Match on the class or on errorCode, never on the message: the message is for people and may
change.
| Class |
Status |
errorCode |
BadRequestException |
400 |
BadRequest |
AuthenticationException |
401 |
Unauthorized |
PlanException |
403 |
PlanExpired |
NotFoundException |
404 |
NotFound |
RateLimitException |
429 |
RateLimited or QuotaExceeded |
ServerException |
5xx |
Internal |
ConnectionException |
none |
none: no answer came back |
When an error body is not JSON, errorCode is null and the message is HTTP <status>. The key never appears in an
error message.
use Oushodh\ErrorCode;
use Oushodh\Exception\NotFoundException;
use Oushodh\Exception\PlanException;
try {
$medicine = $oushodh->getMedicine('MED-999999');
} catch (NotFoundException) {
// No medicine has that ID.
} catch (PlanException $e) {
if ($e->errorCode === ErrorCode::PlanExpired) {
// The account has no active plan.
}
}
Retries and rate limits
Your plan sets how many requests each key may make in a minute (60 a minute on Developer). It also sets how many
requests your account may make in a month. See Rate limits.
An account with no plan is on the free tier: test apps only, one key, 10 requests a minute and 1,000 a month for the
whole account. On a plan, a test app’s keys run at 10 a minute and share 5,000 requests a month.
- Over the minute’s limit, the API answers
429 rate_limited. The Retry-After header says how many seconds to wait.
The client waits that long and tries again, up to maxRetries times. After that it throws a RateLimitException
with the seconds in retryAfter.
- When the month’s requests are used up, the API answers
429 quota_exceeded until the next month. The client never
retries it. It throws a RateLimitException at once, and retryAfter counts the seconds to the next month.
- After a
5xx or a network error, the client backs off and tries again, up to maxRetries times. It waits 0.5 s,
then 1 s, and so on, plus a random part.
- The client never retries a
400, 401, 403 or 404: the same request gets the same answer.
Every route is a read, lookupMedicines() (a POST) included, so a retry is always safe.
Plans
Every plan reads every medicine: lists, search, lookups by ID, images and updated_since sync. Plans differ in
requests a month, requests a minute per key, the number of API keys, and how many production apps the licence allows
(Developer 1, Team up to 5, Agency unlimited, Custom as agreed in writing). The production-app limit is a licence
term: the API does not enforce it.
A 403 plan_expired (ErrorCode::PlanExpired) means the account’s plan has ended, or a production app’s key has no
plan: the free tier runs test apps only.
Configuration
Pass options to the constructor as named arguments:
$oushodh = new Client(apiKey: 'oush_...', timeout: 10.0, maxRetries: 3);
| Option |
Default |
What it does |
apiKey |
OUSHODH_API_KEY |
Your API key. |
baseUrl |
https://api.oushodh.dev |
Where the API is. |
timeout |
30.0 |
Seconds to wait for one answer. |
maxRetries |
2 |
Retries after a 429 rate_limited, a 5xx or a network error. |
http |
a new Guzzle client |
Your own Guzzle client, or a Guzzle handler such as a MockHandler. |
In your own tests, pass a Guzzle MockHandler as http, so no request leaves your machine:
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
$mock = new MockHandler([
new Response(200, [], '{"client":"acme","id_profile":"default","medicines":1,"last_import":null}'),
]);
$oushodh = new Client('oush_test_123', http: $mock);
Development
The dev tools need PHP 8.4 or newer.
composer install
composer test
composer analyse
composer lint
composer test runs PHPUnit, composer analyse runs PHPStan and composer lint runs PHP CS Fixer. The tests use a
Guzzle MockHandler. They never call the API.
Licence
MIT. Copyright Oushodh. See LICENSE.
评论