Install
native-tls:
Quickstart
Create an item, then list stock on hand.try_next comes from the futures-util crate.
Authentication
Pass an API key or an OAuth access token toClient::new. Create an API key in the app under Settings > Access > API keys. The key acts as the member who made it, and a call needs both the member’s permission and one of the key’s scopes.
For an OAuth token that expires, pass a Token::provider. The client calls it before each request:
Client::builder takes more settings:
A
Client is cheap to clone. Clones share one connection pool.
Making calls
Each area of the API has a method, such ascatalog() or inventory(), with a method for each operation on it. Path parameters and the body are arguments. Optional query parameters are methods on the call. Await the call to send it:
GET /catalog/items/{item}.
A call returns what the response’s data holds, so get_item returns an ItemResource. An empty response returns (), a CSV export a String and a file Bytes.
Every schema in the API reference has a type in stockshift::types. A request type is built with new, which takes its required fields, and a setter for each optional field:
Unknown variant, so a value the API adds later still decodes.
For an operation this version of the crate does not have, use Client::request with the path and any type that implements Deserialize.
Pagination
A list that can grow returns one page at a time. Callstream() on the call to get every record. It fetches the next page when the last one runs out:
next_cursor back with after() until it is None.
Errors
Every call returnsResult<T, stockshift::Error>. When the API answers with an error, the error is Error::Api, which holds the RFC 9457 problem details body. Branch on its code, which is stable. The detail is written for people and may change.
ApiError also has status, detail, problem and headers. A call that gets no answer, because the network failed or the attempt timed out, fails with Error::Connection.
Retries and idempotency keys
The client retries a429 after the time in Retry-After. It does this for every method, because the API did not run the call. If Retry-After is longer than max_retry_after, the call fails instead.
A 5xx or a network failure is retried for GET, PUT and DELETE, with a short backoff. A POST or PATCH is retried only when you give it an idempotency key, so a retry cannot make the change twice:
Webhooks
Check theStockShift-Signature header before you trust a delivery. Webhook::verify needs the raw body, exactly as it arrived:
tolerance to change that. Retries of an event keep its id, so store it and skip events you have handled. An event this version of the crate does not know arrives as EventData::Unknown with its data as JSON.
To test your own receiver, Webhook::sign signs a payload the same way StockShift does.
Versions
The major version moves when an API change can break your code, such as a removed field or a new required parameter. New endpoints, fields and enum values come in minor versions.stockshift::API_VERSION holds the version of the API reference the crate was built from.
A minor version may raise the minimum supported Rust version.