Getting started with the Anrok API

Table of contents
  1. Introduction
  2. Create your first product ID
  3. Create an API key
  4. Send your first API request
  5. View the transaction on Anrok

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.

Create your first product ID

Before making our first transaction, we need to add a product ID in Anrok:

  1. Login to Anrok and navigate to the Product IDs page.
  2. Click “Add product ID” and fill in the details (or use your own values):
    • Product name: Acme Pro
    • Product ID: acme-pro
    • Product type: B2B
    • Category: SaaS - General
  3. Click “Save.”

For a complete guide on setting up product IDs, refer to the help center article “Setup your product IDs.

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 on Anrok. It’s important to store this key securely for future reference:

  1. Login to Anrok and navigate to the Settings page.
  2. Click “Manage API keys”.
  3. Click “New key”, then “Create key.”
  4. 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": "acme-pro",
            "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 on Anrok

You have successfully created a new transaction via the API. Follow these steps to find and view it in Anrok:

  1. Login to Anrok and navigate to the Transactions page.
  2. Search for “my-first-transaction” in the search bar.