Basics of API
What is API
API (Application Programming Interface) refers to a number of pre-defined functions designed to provide applications and developers with the ability to access a set of routines based on a software, while not having to access the source code or understand the internal workings mechanism. Users can access the information by calling the API in a defined format.
Here's a typical API service, to get the province and city to which a cell phone number belongs:
http://apis.juhe.cn/mobile/get?key=4c80e35a4220b955a2932a38e6511e9e&phone=15838082573
Click the link, and you only need to modify the cell phone number behind [phone=] in the address bar, and press Enter to get the province and city to which the cell phone number belongs.
That's the API service, where you simply pass parameters to the server when requesting to get the desired content.
What is API Request
What is a request? API is called through a URL, opening the URL once is a request, and refreshing the page is again counted as a request.
Requesting an API is to open the URL of the interface, and the URL contains several components:
API address
The address of the API service that is available to the public for external access.
Request method
The commonly used methods are Get, Post and others. It depends on the API service.
Request parameter
The API processes the data based on the parameters you pass, for example, phone in the URL is a parameter.
Authorization and authentication
When requesting the API, it is necessary to authenticate your request. The common ones are token authentication and key (sometimes combined with sign). These information is provided to you by the API service provider.
Header
The header information to be passed when requesting is a system-level parameter that contains the parameters for the Token. In general you don't need to configure it.
Body
Also, Body stores the passed data, and it needs to be configured only when the request method is Post.
For example, if the data in a form is added to a third-party system via the API, the field names and field values of the form are stored in the Body.
In summary, the following three parts are required for API calls:
- The URL of the requested API
- Passed parameters
- Authorization and authentication
Examples
Example 1: Get the city where the cell phone number belongs (Get)
API Service Provider: Juhe
API address: http://apis.juhe.cn/mobile/get
Request method: Get
Passed parameter: phone (phone number), key(authentication code provided by the service provider)
Authorization and Authentication: Authentication is performed through a requested Key.
Header: No need to configure if not specified.
Body: Get. No need to configure.
Splice the request address and parameters to get the full URL of the request (use & between parameters and prefix the first parameter with ?).
http://apis.juhe.cn/mobile/get?key=4c80e35a4220b955a2932a38e6511e9e&phone=15838082573
Here is the data returned by the API.
Nodes configuration in workflow:
- Triggering node: The workflow is triggered when a contact's cell phone number is added or modified.
- Send API Request node: Request the API based on the cell phone number to get the province and city to which this cell phone number belongs.
- Update Record node: Update location information to the contact record.
Example 2: Add a new record to the worksheet via the API (Post)
First take a look at the API of a worksheet.
As you can see from the API description, the request method is Post, and you only need to configure the request URL and parameters.
The authorization and authentication is by appkey and sign , which can be configured in the Body together with the parameters.
Two types of parameter formats are supported in Body:
Key-value pairs: Simply put, just like the configuration in the figure, the left side is the parameter name, and the right side is the parameter value.
Raw(application/json): Convert parameter and parameter value to Json format.
Nodes configuration in workflow:
- Triggering node: The workflow is triggered when a new record is added to the Registration worksheet.
- Send API Request node: Add a new record through the API of the Members worksheet.
Have questions about this article? Send us feedback