Download the PHP package select-co/sage200-api-client without Composer
On this page you can find all versions of the php package select-co/sage200-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sage200-api-client
Sage 200 API Client (PHP)
A lightweight PHP client for the Sage 200 REST API. It wraps Guzzle with sensible defaults (auth headers, site/company headers, JSON, error handling), provides a request/response abstraction, and includes a fluent OData query builder for constructing query strings.
- Package:
select-co/sage200-api-client - License: MIT
- Minimum PHP: 7.2.5+
Links
- Source: https://github.com/SelectCo/sage200-api-client
- Issues: https://github.com/SelectCo/sage200-api-client/issues
Features
- Simple connector with Bearer token auth and default Sage base URL
- Optional
X-SiteandX-Companyheaders - Request/Response abstraction over Guzzle
- OData query builder for
$select,$filter,$orderby,$top,$skip,$expand,$count - Meaningful exceptions for common HTTP error codes
- Optional endpoint helpers when paired with
select-co/sage200-api-endpoints
Installation
Install via Composer:
If you also want a typed set of endpoint/resource helpers, install the companion package (if available publicly) or include it as a path repo like in this repo's composer.json:
Quick start
Usage
Connector
SelectCo\Sage200ApiClient\Sage200Connector extends the abstract Http\Connector and configures:
- Authorization header:
Authorization: Bearer <token> - JSON Content-Type
- Optional
X-SiteandX-Companyheaders - Base URL (defaults to Sage production URL)
You can also pass custom Guzzle options via the constructor $clientOptions or later through setClientOptions(). The client forces http_errors=false and will not throw Guzzle exceptions for 4xx/5xx; instead this library maps key status codes to domain exceptions.
Requests
Create small request objects by extending SelectCo\Sage200ApiClient\Http\Request and defining:
protected $method: one ofGET,POST,PUT,DELETEprotected $endPoint: e.g./customers- Optionally use
setQueryParameters(SageODataBuilder)orsetQueryString(string) - Optionally set a body (for POST/PUT) by assigning
$this->bodyto a JSON string
Example POST with a JSON body:
Response
SelectCo\Sage200ApiClient\Http\Response wraps a PSR-7 ResponseInterface and provides helpers such as:
getStatus()— HTTP status codegetBody()— PSR-7 body stream (StreamInterface)getContents()— raw body string (reads the stream)getResponse()— underlying PSR-7 response for advanced access (e.g.,getHeaders())
OData query builder
Use SelectCo\Sage200ApiClient\QueryBuilder\SageODataBuilder to fluently construct query strings. Examples:
See inline PHPDoc in SageODataBuilder for many more examples: string functions, date comparisons, enums, nested filters, expands, etc.
Error handling
The connector translates common HTTP statuses into dedicated exceptions:
400→SelectCo\Sage200ApiClient\Exception\BadRequestException401→SelectCo\Sage200ApiClient\Exception\UnauthorizedException403→SelectCo\Sage200ApiClient\Exception\ForbiddenException404→SelectCo\Sage200ApiClient\Exception\NotFoundException
Each exception extends SageException and exposes the raw Sage response via getSageResponse() to help with diagnostics.
Optional: Endpoint helpers
If the companion package select-co/sage200-api-endpoints is installed, Sage200Connector::resources() will return its Resource entry point, giving you a discoverable set of endpoint classes. Otherwise it returns a placeholder Http\Resources class.
Example:
Configuration
- Base URL: override in
Sage200Connectorconstructor if using sandbox or regional endpoints X-Site/X-Company: set in constructor or withsetSite()/setCompany()- Guzzle options: supply associative array via constructor
clientOptionsorsetClientOptions()later
Development
- PRs and issues are welcome in the GitHub tracker
License
MIT License. See LICENSE if provided, otherwise the license is declared in composer.json.