Getting started with the Anrok API
Table of contents
Introduction
This guide walks through the process of creating an API key, making your first transaction using an API request, and viewing the results in Anrok. For a complete overview of available API endpoints, refer to the Anrok API documentation.
Note: every Anrok seller account has the ability to generate API keys and has access to a sandbox account. Sandbox accounts are functionally identical to production accounts. If you need a new Anrok sandbox, please email support@anrok.com.
Each seller in Anrok will have their own set of API keys. The API key format is: {sellerId}/{apiKeyId}/secret.{secret}
.
Create your first product ID
Before creating a transaction in Anrok, we need to add a product ID:
- Log in to Anrok and navigate to the Product IDs page.
- Click “Add product ID” and fill in the details (or use your own values):
- Product name:
SaaS Product
- Product ID:
saas-product
- Product type:
B2B
- Category:
SaaS - General
- Product name:
- Click “Save.”
For a complete guide on setting up product IDs, refer to the help center article “Setup your product IDs.”
Note: Product IDs in Anrok are simply encapsulations of distinct tax categories. Anrok sellers only need to create product IDs for each unique tax category, not every single product in the catalog. This can greatly simplify tax category configuration.
Create an API key
Every API request to Anrok must include an API key. Follow these steps to generate your first key. Once generated, your secret key can no longer be viewed in Anrok. It’s important to store this key securely for future reference:
- Log in to Anrok and navigate to the Settings page.
- Click “Manage API keys”.
- Click “New key”, then “Create key.”
- Store your API key in a secure location like a password manager.
Send your first API request
Now that you have a Product ID in Anrok and have generated an API key, you’re ready to make your first API request. In this guide, we’ll use curl to create a new transaction with the createOrUpdate endpoint.
The API key you generated must be provided in the Authorization header for all requests. In the example below, replace the $anrok_api_key
value with your actual API key.
anrok_api_key='sxxx/sakxxx/secret.xxx'
curl https://api.anrok.com/v1/seller/transactions/createOrUpdate \
-H "Authorization: Bearer $anrok_api_key" \
--json '{
"id": "my-first-transaction",
"accountingDate": "2023-01-01",
"currencyCode": "USD",
"lineItems": [{
"productExternalId": "saas-product",
"amount": 1050
}],
"customerId": "customer-1",
"customerName": "Customer 1",
"customerAddress": {
"country": "us",
"line1": "310 S Houston St",
"city": "Dallas",
"state": "TX",
"zipCode": "75202"
}
}'
If the request is successful, you’ll receive a response similar to the example below. For a full overview of the response structure and possible error types, refer to the Anrok API documentation.
{
"version":1,
"taxAmountToCollect":69,
"lineItems":[{
"taxAmountToCollect":69
}]
}
View the transaction in Anrok
You have successfully created a new transaction via the API. Follow these steps to find and view it in Anrok:
- Login to Anrok and navigate to the Transactions page.
- Search for “my-first-transaction” in the search bar.