Access tokens (OAuth)

Get a short-lived access token for your API application and use it from your server or your web pages: sending leads, reading products, the quote form.

This guide shows how your firm's systems get an access token from Subcontext and use it. An access token lets your code use the Subcontext API for two hours. Your code gets one by showing Subcontext its client id and client secret, the username and password of an API application you create in the dashboard. This is a standard called OAuth (the "client credentials" kind).

You need a token when:

  • your server talks to Subcontext, for example to send leads from your own systems or a partner's, or to read what became of them; or
  • a web page uses the API with your server's help, for example the quote form offering several products on one page, or your own JavaScript reading your products.

Most website embeds don't need a token. They use a public key or id that you paste into your page:

Embed What it uses Can it use a token?
Webchat Your agent's id No
Form guide Your agent's id No
Lead form The form's key (lfk_...) No. To send leads from a server, use a token with the leads API (Send leads from your server).
Quote form The quote form's key (qfk_...) Yes, with getToken in place of the key (Hand a token to the quote form)
WebMCP The integration's key (wmk_...) No
Nurture The widget key (nwk_...) and a pass your server signs No (it has its own signing key)
  • Token address: https://subcontext.com/oauth/token
  • API address: https://subcontext.com/api/v1

Connecting an AI assistant such as Claude or ChatGPT to Subcontext uses a different kind of sign-in, where a person approves the connection. This guide doesn't cover it.

Quick start#

This gets a token for your server and sends a lead with it.

  1. In the Subcontext dashboard, open Integrations, API applications and press New application. (Only owners of your organisation can.)
  2. Give it a Name (like "Our CRM"), tick read, write and crm, and leave Allowed origins empty. Press Create application.
  3. Copy the Client ID and Client secret now. The secret is shown only this once. Keep it somewhere safe on your server.
  4. Ask for a token:
sh
   curl -X POST https://subcontext.com/oauth/token \
     -d grant_type=client_credentials \
     -d client_id=YOUR_CLIENT_ID \
     -d client_secret=YOUR_CLIENT_SECRET \
     -d "scope=read write crm" \
     -d resource=https://subcontext.com/api/v1

The answer:

json
   {"access_token":"vX2...k9Q","token_type":"Bearer","expires_in":7200,"scope":"read write crm","created_at":1791792055}
  1. Use the token. Send it in an Authorization header on each API request:
sh
   curl -X POST https://subcontext.com/api/v1/crm/ingests \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/json" \
     -H "Idempotency-Key: lead-0001" \
     -d '{"source": "my_website", "campaign": "YOUR_CAMPAIGN_KEY",
          "identity": {"first_name": "Ada", "email": "ada@example.com"}}'

A 202 Accepted answer means Subcontext has the lead.

send-lead.mjs does the same in Node. There are PHP and .NET versions in the example files.

Need help?#

Email hello@subcontext.com.

In this section

Stuck, or something missing?

Get in touch and a person on the team will help.

Contact us