Download the PHP package heano/basin-php without Composer
On this page you can find all versions of the php package heano/basin-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download heano/basin-php
More information about heano/basin-php
Files in heano/basin-php
Package basin-php
Short Description A small, framework-agnostic PHP client for the Basin (usebasin.com) forms API.
License MIT
Homepage https://github.com/heanohq/basin-php
Informations about the package basin-php
basin-php
A small, framework-agnostic PHP client for the Basin forms API.
- Works with any PSR-18 HTTP client, such as Guzzle or Symfony HttpClient.
- Typed exceptions for auth, not-found, validation, rate-limit and outage errors.
- Defensive parsing: copes with Basin's list wrappers, string page numbers and missing metadata.
- Strips secrets Basin returns in plain text (see What gets removed).
- PHP 8.2+, no other dependencies beyond the PSR interfaces.
It isn't an official Basin package. It's the API client from Basin for Craft, with the Craft parts taken out. The plan is for that plugin to depend on this package.
Installation
You also need a PSR-18 client and PSR-17 factories. If you don't have one already, Guzzle provides both:
Getting started
Create an API key in your Basin account and keep it in an environment variable rather than in code.
Timeouts, proxies and retries belong to the HTTP client, so set them there. A fifth argument, baseUrl, defaults to https://usebasin.com/api/v1/; change it only to point at a proxy or a mock server.
Usage
Projects and forms
updateForm() only changes the fields you pass. Basin ignores field names it doesn't know, without an error, so check the spelling against Basin's API docs.
Creating and deleting forms
Without notification_emails, a new form's notifications go to the Basin account owner. Any other address has to confirm by email before it gets notifications: until then it's listed in notification_emails_pending and the form emails nobody else.
Editing a form's settings
getForm() leaves out email settings (see below). To build a settings editor, use getFormSettings(), which keeps them:
The result contains people's email addresses, so don't cache or log it.
Some settings return 200 but aren't saved by Basin's API, so they need changing in Basin itself: allowed_domains, content_blacklist, valid_email_filter and block_burner_emails (checked November 2026).
Submissions
Unknown filters and orders throw an InvalidArgumentException before anything is sent, because Basin ignores an unknown filter_by and returns everything, spam included. For the same reason, updateSubmission() only accepts read, spam and trash.
Paging
Basin returns 100 items per page. Each list method takes a page number and returns a ListPage:
Attachments
Each attachment in a submission has an id. Download it through Basin's authenticated proxy:
The PSR-7 response is returned as is, so the body can be streamed if your HTTP client supports it (Guzzle's stream option, for example). The method also accepts the last segment of an attachment's attachment_proxy_url.
Errors
Every API error extends Heano\Basin\Exception\ApiException. The exception code is the HTTP status, and messages never contain the API key.
| Exception | When |
|---|---|
AuthException |
401 or 403, or no API key was given |
NotFoundException |
404 |
ValidationException |
422. Basin's messages are joined into the exception message, and $e->messages lists them one by one |
RateLimitException |
429. $e->retryAfter holds the seconds to wait, if Basin said |
ApiUnavailableException |
5xx, timeouts and connection failures |
ApiException |
Anything else, including responses that aren't valid JSON |
What gets removed
Basin's API returns some data in plain text that most applications never need and shouldn't store, log or show. The client removes it from every response before it reaches your code:
- Forms:
turnstile_secret; every email and notification setting (which hold people's addresses); andform_webhooks, whose URLs often contain secrets. It's replaced withwebhook_count.getFormSettings()keeps the email settings, and still removes the rest. - Submissions: attachment
public_urls, which work for anyone who has them. UsedownloadAttachment()instead.
Endpoints covered
| Method | Endpoint |
|---|---|
listProjects() |
GET /projects |
getProject() |
GET /projects/{id} |
listForms() |
GET /forms |
getForm() |
GET /forms/{id} |
getFormSettings() |
GET /forms/{id} |
createForm() |
POST /forms |
updateForm() |
PUT /forms/{id} |
deleteForm() |
DELETE /forms/{id} |
listSubmissions() |
GET /submissions |
getSubmission() |
GET /submissions/{id} |
updateSubmission() |
PATCH /submissions/{id} |
deleteSubmission() |
DELETE /submissions/{id} |
refireWebhooks() |
POST /submissions/{id}/refire_webhooks |
downloadAttachment() |
GET /attachments/{id} |
There's deliberately no "request anything" method. Basin's API documentation covers the rest of the API.
Development
No PHP locally? Use Docker:
The tests use mocked HTTP and never call Basin. Fixtures are scrubbed responses from a test account.
Licence
MIT. See LICENSE.
All versions of basin-php with dependencies
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0