SubspaceProductAPI

Introduction

The Subspace API is based on REST, has resource-oriented URLs, returns JSON-encoded responses, and returns standard HTTP response codes.

The base URL for the API is: https://api.subspace.com/

Naming Convention

Authentication

API Tokens

Subspace authenticates your API requests using JWT Bearer tokens. To use any Subspace API, you must pass a Bearer token with each request. If you do not include your Bearer token when making an API request, or use one that is incorrect or disabled, Subspace returns an error.

Bearer tokens are granted by requesting one (as noted below) and presenting your publishable (client_id) and secret (client_secret) tokens.

Subspace provides two types of API tokens: publishable (client_id) and secret (client_secret). These are available in the Subspace console.

Getting a JWT Bearer Token

Subspace uses auth0 for JWT token management. You can acquire a JWT token by utilizing https://id.subspace.com and following the instructions in the curl example below.

Protecting Your API Tokens

Error Codes

Subspace uses HTTP response codes to indicate the success or failure of an API request.

General HTML status codes:

Security

We provide a valid, signed certificate for our API methods. Be sure your connection library supports HTTPS with the SNI extension.

REST How-To

Making your first REST API call is easy and can be done from your browser. You will need:

First, acquire a JWT Bearer Token. Command line example:

curl --request POST \\
     --url \"https://id.subspace.com/oauth/token\" \\
     --header 'content-type: application/json' \\
     --data '{ \"client_id\": \"YOURCLIENTID\", \"client_secret\": \"YOURCLIENTSECRET\", \"audience\": \"https://api.subspace.com/\", \"grant_type\": \"client_credentials\" }'

REST calls are made up of:

Authorization header example

If your API token was “my_api_token”, you would add...

Authorization: Bearer my_api_token

...to the header.

Command line examples

To list your current open packet_accelerators using the token “my_api_token”:

curl -H “Authorization: Bearer my_api_token” https://api.subspace.com/v1/accelerator

Alternately, to get the details of a specific accelerator whose id is 'abcd-ef01-2345':

curl -H “Authorization: Bearer my_api_token” https://api.subspace.com/v1/accelerator/abcd-ef01-2345

API Versioning

Subspace will release new versions when we make backwards-incompatible changes to the API. We will give advance notice before releasing a new version or retiring an old version.

Backwards compatible changes:

Versions are added to the base url, for example:

Current Version is v1:https://api.subspace.com/v1

Building

To install the required dependencies and to build the elixir project, run:

mix local.hex --force
mix do deps.get, compile

Installation

If available in Hex, the package can be installed by adding subspace_openapi_client to your list of dependencies in mix.exs:

def deps do
  [{:subspace_openapi_client, "~> 0.1.0"}]
end

Configuration

Set your key to be the JWT.

You can configure for your application as:

 config :subspace_product_api, key: :value

And access this configuration in your application as:

 Application.get_env(:subspace_product_api, :key)

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/subspace_openapi_client.