Requests with Multiple API Tokens

Contents

Overview

This article introduces methods for setting multiple API Tokens in REST API requests. Examples using multiple API Tokens with Lookup and Related records fields are also introduced.

How to Set Multiple API Tokens

Separate API Tokens with commas

Specify the API Tokens in the HTTP request header with a comma in between them.

1
2
3
4
# Specify the API tokens with a comma in between them
$ curl -X GET 'https://{subdomain}.kintone.com/k/v1/records.json?app=1'  \
  'https://{subdomain}.kintone.com/k/v1/records.json?app=2' \
  -H 'X-Cybozu-API-Token:{API_Token_1},{API_Token_2}'

Set API Tokens in Separate Headers

Specify multiple header options in the request. Set the relative API tokens in each header.

1
2
3
4
# Specify the API tokens as separate headers
$ curl -X GET 'https://{subdomain}.kintone.com/k/v1/records.json?app=1' \
  'https://{subdomain}.kintone.com/k/v1/records.json?app=2' \
  -H 'X-Cybozu-API-Token:{API_Token_1}' -H 'X-Cybozu-API-Token:{API_Token_2}'

Example Requests Using Multiple API Tokens

Example overview

This tutorial references three Apps: a Customer Database App, a Sales Leads Management App, and an Activity History App with the following relationships.

A diagram representing relationships between the 3 Apps.

A curl command is used to perform the following two request patterns.

  • Adding a new record that includes a Lookup field A new record will be added into the Sales Leads Management App, which has a Lookup field inside. Since the Lookup field accesses data from a different App, API tokens generated from the two Apps will be needed in the request.
  • Getting records by querying Related Records field values Multiple records will be obtained from the Sales Leads Management App. The query for getting the records will include values in the Related Records field. Since the Related Records field is referencing data from the Activity History App, API tokens generated from the two Apps will be needed in the request.

Adding a new record that includes a Lookup field

In the Sales Leads Management App, data from the Customer Database App is retrieved with a Lookup field. The Organization Name is used as the key. The values of the Department and the Contact Name fields are also copied into the Sales Leads Management App.

In the request header specify:

  • the API Token of the App to add records to
  • the API Token of the App to be used as the Lookup source
1
2
3
4
$ curl -X POST 'https://{subdomain}.kintone.com/k/v1/record.json' \
  -d '{"app": {Sales_Leads_Management_App_ID}, "record": {"company_name": {"value": "Kintone"}, "lead_title": {"value": "This record was added with an API token!"}}}' \
  -H 'Content-Type: application/json' \
  -H 'X-Cybozu-API-Token:{Sales_Leads_Management_App_API Token},{Customer_Database_App_API_Token}'

The following values must be changed to match the environment.

  • {subdomain}: Environment’s subdomain name
  • {Sales_Leads_Management_App_ID}: The App ID of the Sales Leads Management App
  • {Sales_Leads_Management_App_API_Token}: The API token of the Sales Leads Management App
  • {Customer_Database_App_API_Token}: The API token of the Customer Database App

Each record in the Activity History App has a Sales Leads Management App Record Number to denote which lead the activity is connected to. Records of the Activity History App whose Sales Leads Management App Record Number value matches the Record Number value of the current Sales Leads Management App record are displayed as Related Records.

A GET request to the Sales Leads Management App using only the API token from the Sales Leads Management App would not allow the user to use a Related Records field in the query. However, additionally specifying the API token of the Activity History App allows the Related Records fields to be used in the query.

In the request header, specify the API Tokens of App with the Related Records field and the Related Records source App.

1
2
3
4
# The following query is used:
# related_records.activity_history_date >= "2020-01-01" and related_records.activity_history_date < "2021-01-01"
$ curl -X GET 'https://{subdomain}.kintone.com/k/v1/records.json?app={Sales_Leads_Management_App_ID}&query=related_records.activity_history_date%20>=%20"2020-01-01"%20and%20related_records.activity_history_date%20<%20"2021-01-01"' \
  -H 'X-Cybozu-API-Token:{Sales_Leads_Management_App_API_Token},{Activity_History_App_API_Token}'

The following values must be changed to match the environment.

  • {subdomain}: Environment’s subdomain name
  • {Sales_Leads_Management_App_ID}: The App ID of the Sales Leads Management App
  • {Sales_Leads_Management_App_API_Token}: The API token of the Sales Leads Management App
  • {Activity_History_App_API_Token}: The API Token of the Activity History App

Reference

For more references on API Tokens, refer to the API Tokens article. This article covers how to generate API tokens, troubleshooting notes and limitations.