Create a Client Token

Client Tokens are short lived authentication tokens which can be generated by an integrated application and passed to frontend applications in order to enable front end applications to communicate directly with the OpenTransact API. Client Tokens are tied to an “Owner”, for example a Profile in the system and may only be used to make API calls for other items related to that Owner.

Note: Even though Client Tokens do not currently have any required attributes on input, the client must pass an empty attributes object as shown in the examples below.

Accepts a ClientTokenRequest object. Returnas a ClientTokenResponse object.

Example (Ruby)

require 'uri'
require 'net/http'

url = URI("https://api.opentransact.com/v1/client-tokens")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["authorization"] = "Bearer #{API_KEY}"
request["content-type"] = 'application/vnd.api+json'
request.body = {
	"data":{
		"type": "client-tokens",
		"attributes": {
		},
		"relationships": {
			"roles": {
				"data": [{ "type": "roles", "id": $ROLE_ID}]
			},
			"subject": {
				"data": {
					"type": "profiles",
					"id": $PROFILE_ID
				}
				
			}
		}
	}
}.to_json

response = http.request(request)
puts response.read_body

Example (cURL)

curl --request POST \
  --url https://api.opentransact.com/v1/client-tokens \
  --header 'authorization: Bearer $API_KEY' \
  --header 'content-type: application/vnd.api+json' \
  --data '{
	"data":{
		"type": "client-tokens",
		"attributes": {
		},
		"relationships": {
			"roles": {
				"data": [{ "type": "roles", "id": $ROLE_ID}]
			},
			"subject": {
				"data": {
					"type": "profiles",
					"id": $PROFILE_ID
				}
				
			}
		}
	}
}'