Requests with multiple API tokens

Index

Introduction

Records can be retrieved, added, or updated across multiple Apps by using multiple API tokens. This is useful to handle data involving multiple Apps, such as when using Lookup or Related Record fields. This tutorial will use a Lookup and Related Record field to demonstrate how to use multiple API tokens to perform operations across Apps.

Authentication with Multiple API Tokens

After generating the API tokens from each applicable App, set X-Cybozu-API-Token in the request header to specify the API tokens. Refer to the article, Using API token authentication for more information on how to generate API tokens.


There are two ways to use multiple API Tokens in a single request.

  1. Specify the API Tokens with a comma in between the tokens
    Specify the API Tokens in the HTTP request header with a comma in between them.
    Example: When the specified API Tokens are XXXXXXXXXX and YYYYYYYYYY

  1. Write the API Tokens as two separate headers
    cURL allows the user to specify API tokens in separate -H header options.
    Example: When the specified API Tokens are XXXXXXXXXX and YYYYYYYYYY

For details on how to run the Kintone REST API using the cURL command, see the explanation in the Quick Start article. The commands introduced in this article have been tested with macOS Mojave 10.14.6 / cURL 7.54.0.

Example of Requests Using Multiple API Tokens

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

 

app_relationship_diagram.png

 

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 Tokens of the App to add records to and the App to be used as a Lookup source.

 

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.

 

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
  • <Activity History App ID>: The App ID of the Activity History 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

Finally

Using multiple API tokens allows operations that would usually require two or more API requests to be achieved with a single request. This is useful to reduce the number of overall API requests that a single customization uses. 

Was this article helpful?
0 out of 0 found this helpful
Do you have any questions or issues related to this article?
Please share your views with us in the Community forums!