Skip to content

Service Token API

The AutoROICalc service token is used for API-based integrations. It lets trusted systems create or manage records through the AutoROICalc API, which is useful for custom backends, scheduled jobs, server-side conversions, and internal automation.

When to Use the Service Token

Use the service token when you want to:

  • Send records from a backend service
  • Import data from a custom system
  • Connect automation tools or internal scripts
  • Build a server-side data pipeline
  • Use the Records API instead of manual imports

Where to Find It

Open the AutoROICalc Integrations page and copy the service token from the Service Token API section.

Protect your service token

Treat the service token like a password. Do not publish it in frontend code, public repositories, screenshots, or client-side JavaScript.

Finding the service token

Finding the service token

Records API

Most custom integrations use the Records API to add records with fields such as type, description, date, source, tags, value, raw data, and custom data.

Records API Guide Records API Reference

Service Token Record Endpoints

Use service-token endpoints from trusted server-side code. The service token is passed as the service_token query parameter.

Action Endpoint Purpose
Create one record POST /service_token/record Adds a single record.
Create many records POST /service_token/records Adds multiple records in one request.
Query records POST /service_token/records/query Reads records with pagination and optional filters.
Update a record PUT /service_token/record/{record_id} Updates an existing record by ID.

Keep service-token calls server-side

Do not call service-token endpoints from browser JavaScript or public mobile app code. Query parameters can appear in logs, analytics, proxies, and browser history, so only use the service token from trusted backend code, scripts, jobs, or private automation.

Example Record Payload

The examples below create a record for a paid order. Adjust type, source, tags, value, custom_data, and raw_data to match your integration.

{
  "date": "2026-09-15",
  "time": "14:30:00",
  "type": "sale",
  "activity": "closed",
  "desc": "Order paid",
  "source": ["woocommerce"],
  "tags": ["ecommerce", "paid-order"],
  "value": 129.9,
  "custom_data": {
    "order_id": "100045",
    "customer_id": "8742",
    "campaign_id": "fall-2026"
  },
  "raw_data": {
    "provider": "woocommerce",
    "event": "order.paid"
  }
}

Create a Record Examples

curl -X POST "https://api.autoroicalc.com/service_token/record?service_token=$AUTOROICALC_SERVICE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "date": "2026-09-15",
    "time": "14:30:00",
    "type": "sale",
    "activity": "closed",
    "desc": "Order paid",
    "source": ["woocommerce"],
    "tags": ["ecommerce", "paid-order"],
    "value": 129.9,
    "custom_data": {
      "order_id": "100045",
      "customer_id": "8742",
      "campaign_id": "fall-2026"
    },
    "raw_data": {
      "provider": "woocommerce",
      "event": "order.paid"
    }
  }'
<?php

$serviceToken = getenv('AUTOROICALC_SERVICE_TOKEN');
$url = 'https://api.autoroicalc.com/service_token/record?service_token=' . urlencode($serviceToken);

$record = [
    'date' => '2026-09-15',
    'time' => '14:30:00',
    'type' => 'sale',
    'activity' => 'closed',
    'desc' => 'Order paid',
    'source' => ['woocommerce'],
    'tags' => ['ecommerce', 'paid-order'],
    'value' => 129.9,
    'custom_data' => [
        'order_id' => '100045',
        'customer_id' => '8742',
        'campaign_id' => 'fall-2026',
    ],
    'raw_data' => [
        'provider' => 'woocommerce',
        'event' => 'order.paid',
    ],
];

$ch = curl_init($url);
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode($record),
    CURLOPT_RETURNTRANSFER => true,
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException('AutoROICalc request failed: ' . $response);
}

echo $response;
import os
import requests

service_token = os.environ["AUTOROICALC_SERVICE_TOKEN"]
url = "https://api.autoroicalc.com/service_token/record"

record = {
    "date": "2026-09-15",
    "time": "14:30:00",
    "type": "sale",
    "activity": "closed",
    "desc": "Order paid",
    "source": ["woocommerce"],
    "tags": ["ecommerce", "paid-order"],
    "value": 129.9,
    "custom_data": {
        "order_id": "100045",
        "customer_id": "8742",
        "campaign_id": "fall-2026",
    },
    "raw_data": {
        "provider": "woocommerce",
        "event": "order.paid",
    },
}

response = requests.post(
    url,
    params={"service_token": service_token},
    json=record,
    timeout=15,
)
response.raise_for_status()

print(response.json())
const serviceToken = process.env.AUTOROICALC_SERVICE_TOKEN;
const url = new URL("https://api.autoroicalc.com/service_token/record");
url.searchParams.set("service_token", serviceToken);

const record = {
  date: "2026-09-15",
  time: "14:30:00",
  type: "sale",
  activity: "closed",
  desc: "Order paid",
  source: ["woocommerce"],
  tags: ["ecommerce", "paid-order"],
  value: 129.9,
  custom_data: {
    order_id: "100045",
    customer_id: "8742",
    campaign_id: "fall-2026",
  },
  raw_data: {
    provider: "woocommerce",
    event: "order.paid",
  },
};

const response = await fetch(url, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify(record),
});

if (!response.ok) {
  throw new Error(`AutoROICalc request failed: ${response.status} ${await response.text()}`);
}

console.log(await response.json());
#include <curl/curl.h>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>

int main() {
  const char* token = std::getenv("AUTOROICALC_SERVICE_TOKEN");
  if (!token) {
    throw std::runtime_error("AUTOROICALC_SERVICE_TOKEN is not set");
  }

  CURL* curl = curl_easy_init();
  if (!curl) {
    throw std::runtime_error("Could not initialize curl");
  }

  char* escapedToken = curl_easy_escape(curl, token, 0);
  std::string url = "https://api.autoroicalc.com/service_token/record?service_token=";
  url += escapedToken;
  curl_free(escapedToken);

  std::string payload = R"json({
    "date": "2026-09-15",
    "time": "14:30:00",
    "type": "sale",
    "activity": "closed",
    "desc": "Order paid",
    "source": ["woocommerce"],
    "tags": ["ecommerce", "paid-order"],
    "value": 129.9,
    "custom_data": {
      "order_id": "100045",
      "customer_id": "8742",
      "campaign_id": "fall-2026"
    },
    "raw_data": {
      "provider": "woocommerce",
      "event": "order.paid"
    }
  })json";

  struct curl_slist* headers = nullptr;
  headers = curl_slist_append(headers, "Content-Type: application/json");

  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload.c_str());

  CURLcode result = curl_easy_perform(curl);
  if (result != CURLE_OK) {
    std::cerr << "AutoROICalc request failed: " << curl_easy_strerror(result) << std::endl;
  }

  curl_slist_free_all(headers);
  curl_easy_cleanup(curl);
  return result == CURLE_OK ? 0 : 1;
}

Batch Records Example

Use POST /service_token/records when your integration can send several records at once. The request body is an array of record objects.

curl -X POST "https://api.autoroicalc.com/service_token/records?service_token=$AUTOROICALC_SERVICE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "date": "2026-09-15",
      "time": "14:30:00",
      "type": "sale",
      "activity": "closed",
      "desc": "Order paid",
      "source": ["woocommerce"],
      "tags": ["ecommerce"],
      "value": 129.9
    },
    {
      "date": "2026-09-15",
      "time": "15:10:00",
      "type": "lead",
      "activity": "open",
      "desc": "Pricing form submitted",
      "source": ["website"],
      "tags": ["lead", "pricing"],
      "value": 1
    }
  ]'

Next Steps