Four Types of Parameters in API Integration
Hundreds of interfaces of dozens of service providers are built in Integration Center. Beginners may not be able to get started with some special types of parameters when calling interfaces. The following are examples of 4 types of parameters:
- URL for documents and images
- Ordinary arrays
- Object arrays
- Base64 for images
I. URL for Documents/Images
For example, for interfaces for invoice recognition, text recognition, etc., the parameter passed is the URL of the image, so as long as the interface server has access to the URL, it can recognize the image or document.
If the parameters of the passed URL requires selecting an image or document in the file field, it needs to be obtained through a workflow.
API Query field
This field is not used when a new record is created. Instead, after the record is saved, get the URL of the attached image through the code block node in the workflow and write it to the Image URL field (text control) before you can click the API Query button, and select the Image URL field for the URL parameter.
Call Integrated API node
Get the URL of the image through the code block node first in the workflow, and select the output URL of the code block for the URL parameter.
How to get the URL of an attachment
II. Ordinary Array
Take the interface for sending text to a group robot in WeCom as an example, there is a parameter that needs an ordinary array to be passed.
Format of ordinary array: [element1,element2,...].
Here what is passed is the cell phone number of the mentioned member, the format is [1990909090909,18811111111,...]. If you need to mention all the members in the group, the format is ["@all"].
Currently arrays in this format can only be output directly by code blocks, so to pass such a type of parameter, a workflow is required.
When creating a new record, the array parameter cannot be passed through the API query field, but only after the record is created, it can be obtained through the workflow, and click the API query button.
Get Ordinary Array
Take the example of sending a text message to WeCom to get an array of cell phone numbers.
Workflow Node - Call Integrated API
Worksheet Configuration
1. Add an Alerted Member field
The member field is multi-select.
1. Add an Alert All field
If it is checked, the array is ["@all"].
Workflow Configuration
It can be a workflow triggered by a button or a workflow triggered by a new record, depending on your actual need.
1. Add Branch node, Alert all/Alert mentioned members
When the workflow is triggered, first to see if all members are alerted, if not, get the members to be alerted.
If alerting all members is not required, you can remove the related fields and branching flows.
2. Branch - Alert all
2.1) Output ["@all"] array by code block node.
2.2) Get array by JSON parsing node。
2.3) Select the array in JSON parsing node when configuring call integrated API node
3. Branch - Alert mentioned members
3.1) Get the members in the organization to be alerted
3.2) Convert a member's cell phone number to an array via a code block
Before testing, write the cell phone number parameter as fixed, e.g. ["+861990909090909"].
After a successful test, replace it with the field in the node.
var mobiles= JSON.parse(input.mobile.replace(/\+86/g, ""))
output = {mobiles:mobiles};3.3) Get arrays by JSON parsing node
3.4) Select the array in JSON parsing node when configuring call integrated API node
Worksheet Field - API Query
Passing an ordinary array through an API query field is not the same as in a workflow, where only commas are needed between the different elements, and the middle bracket is not needed. So when passing an ordinary array through an API query field, you can choose either a text field or a multi-select field as they can store arrays in this format.
Alert mentioned members
Alert all
Here also take sending text messages to WeCom group as an example. Before API query, it is necessary to get the list of cell phone numbers through the workflow and write them to a text field, which is selected as the parameter of the ordinary array.
Workflow Configuration
1. Process the obtained cell phone number in the code block node
Test with fixed values first, and then replace them with node fields.
Required code block: to remove +86, double quotes and middle brackets.
output = {output: input.phone.replace(/["\[\]]|(\+86)/g, '') };
If you need to combine other fields in multiple records into an array and write it to a text field, you can use the following code.
output = {output: input.phone.replace(/["\[\]]/g, '') };
2. Update obtained content to a text field
Effect:
API Query Field Configuration
When configuring the API query field, select the Mobile Phone of Alerted Member field (text field) for the passed ordinary array.
III. Object Array
The format of an object array is as follows and can be regarded as the format of a multi-row records. The following object array represents data on the names and ages of two members:
[ {"name" : "jim", "age" : 18},{ "name" : "bob", "age" : 16} ]
How to get object arrays
Take sending messages with images to WeCom as an example
This interface supports sending multiple messages with images, so it is necessary to pass the object array. There are two ways to pass the object array parameter.
API Query
When passing object array parameters through the API query field, you can only select the subform field or relationship field (multiple rows), because these two fields are of multi-row structure, in which one row of records represents a business object, and multiple rows of records are an object array.
If what is to be sent is the content of the current record, it can not use the API query field, but can be sent via a workflow triggered by a custom button.
Workflow
In the workflow, first get the records to be sent via the [Get Multiple Data] node, and then select the obtained fields in the [Call Integrated API] node.
How to pass parameters when sending content of the current record
What if the content to be sent is all in the current record and not in an associated record or subform?
Because of the format of the object array parameters, it is necessary to obtain the data of multi-row structure, therefore, first obtain the data through the [Get Multiple Data] node and then query the current record, with the filtering set to Record ID is equal to the current Record ID, so that only to query current record.
If queried, select the parameters via the [Call Integrated API] node.
IV. Base64 Encoding of Images
For some interfaces, the passed parameter is the Base64 encoding of the image instead of the image URL, you can only get the Base64 encoding of the image through the code block node, and then call the API.
Have questions about this article? Send us feedback