The first step is to obtain a valid access token using your API Keys as described below. The token that you receive is then used by one of our API Clients (or your own) in order to send Batches of image processing tasks to the API. Each Batch consists of a collection of Transform Graphs, and each Transform Graph describes the source, operations and destination(s) for an image processing task.
Access to the Pixelshift API is secured via OAuth 2.0 authorization using the Client Credentials grant type. All requests to the API must include a valid access token. The steps to accquire this token are outlined below.
1. Generate API Public/Private Key Pair
Visit your :webroot:`Pixelshift Dashboard <Dashboard/ApiAccess>` and hit 'Generate New Api Key'. This is the only time the secret key will be shown to you, so make sure you store both keys somewhere safe. Please note that as the secret key is only available when a new key is generated, if you lose it you will need to generate a new secret key or generate an entirely new public/secret key pair.
2. Accquire an OAuth 2.0 Access Token
Using your technology of choice, make a POST to http://www.pixelshift.io/connect/token with a POST body of
grant_type=client_credentials sent with a content-type of
application/x-www-form-urlencoded and your API public/secret key pair base64 encoded in the Authorization Header.
The public/secret key pair should be joined, separated by a
: prior to base64 encoding. For instance, with a public key of
fb160b4b-40bd-406e-bd43-260d3d6181c7 and a secret key of
4e8e316c5bcc , the string to be base64 encoded would be
For example, using Node.js this would look something like:
Creating an API Client
The details of this step depend on your chosen language and implementation.
If you are using C#, Node.js or Java the fastest route to an API Client is to clone one of our repositories. If, on the other hand, you are using Go, PHP, Python, Ruby or Typescript, you can generate a client automagically using autorest against our :webroot:`Swagger/OpenAPI document <swagger/v1/swagger.json>`.
Although autorest can generate clients in Node.js, it requires a workaround. If you're using Node, clone from our Node.js Client repo instead of rolling your own. To simplify this process, we will soon be releasing NPM packages.
Once you have a client, it needs to be initialized with the OAuth token accquired in the previous step. As an example, the Node.js client is initialized as follows:
Defining Processing Tasks
You can submit authorized JSON requests directly to the API if you wish (:webroot:`see here for an example <swagger/index.html#/BatchProcessing/ProcessImageBatch>`), though we recommend using one of our :webroot:`auto-generated clients <documentation/api/apiAccess.html#creating-an-api-client>` and the Transform Graph models that come with it. See below for details.
Transform Units and Transform Graphs
The core building blocks of processing tasks are abstract entities called Transform Units. Sources, Sinks and Operations such as resizing and cropping are all Transform Units. Processing tasks are described by chains of Transform Units that have been assembled into Transform Graphs.
Transform Graphs consist of one or more Transform Units and zero or more Output Transform Graphs (which are themselves Transform Graphs).
Simple Transform Graphs
The diagram above shows a simple standalone Transform Graph consisting of 4 Transform Units and no Outputs. This Transform Graph will fetch an image from S3 Storage, resize it once and then store it as a new jpeg in S3 Storage. For any set of operations with a single output file, a standalone Transform Graph is sufficient.
Branching Transform Graphs
A more complex operation, such as resizing a single image multiple times, or storing a resized image as multiple formats, requires nested, or branching Transform Graphs:
The above is equivalent to the following:
Valid Transform Graphs
There are no restrictions on how Transform Graphs are assembled, but in order to be valid, each chain of Transform Units that results must:
1. Begin with a single StorageSource, giving the location of the original image to be processed
2. Contain one or more Operations, describing the processing tasks to be performed
3. End with an ImageFormat and a StorageSink node that define the file type and location for the result.
The sample below shows how to use the the Pixelshift Node.js API Client to build a simple Transform Graph to fetch an image, resize it and then store it:
Submitting a Batch
Transform Graphs are added to a Batch, which is then submitted for processing. Using Node.js again as an example, the simple graph assembled in the previous section would be added and submitted as shown below:
Please Note: Line 5 in the above code is only required for Node.js clients (see our example in github for the implementation of
The response will indicate success or, if a non-2xx HTTP status is returned, the reason that the submission has failed. See
BatchStartReportResponse in our :webroot:`swagger documentation <swagger/index.html#model-BatchStartReportResponse>`.
Pixelshift supports all the usual image manipulations such as resizing, colouring, cropping and even auto-cropping. Please refer to the Models section of the :webroot:`swagger info page <swagger/index.html>` for the full list, including detailed descriptions for each.
A Throttle setting is provided in your :webroot:`Dashboard <dashboard/apiaccess#throttling>` to prevent accidental submission of more processing tasks than you intend. Use the controls to set a limit on your API access in order to reduce the impact of accidents, should they occur. Initially this is set to 1000 transforms per hour, though it can be changed whenever and as often as you wish.
The following limits apply to Batches submitted to the API:
- Maximum Batch size: 1000 (though multiple batches can be submitted concurrently)
- Maximum StorageSinks per Transform Graph: 5
- Maximum source image file size: 800MB