When designing APIs in Apidog, you may encounter situations requiring the addition of a large number of request parameters. Imagine an endpoint that necessitates dozens or even hundreds of parameters. Adding each parameter individually in the "Edit" section can be cumbersome, time-consuming, and prone to errors.
Fortunately, Apidog offers ways to batch-add parameters, making the process smoother and more efficient.
In this article, we will explore various methods to bulk add request parameters. Let's dive into the details.
Method 1: Using the Bulk Edit Feature
When the body parameter type is form-data
or x-www-form-urlencoded
, you can utilize the "Bulk Edit" feature to add request parameters.
Access the Bulk Edit Function:
In the parameter list, locate the "Bulk Edit" button in the upper right corner. Clicking this button will open a text editing box where you can input parameters in bulk.
Input Parameters in CSV Format:
The parameters must be in CSV format. For example, for form-data
parameters, the required format is:
Parameter Name, Type, Required, Example Value, Content-Type, Description
Each item separated by commas can be left blank if necessary. You can leverage AI tools to organize this data and minimize errors. Here’s an example:
email, string, false, user@gmail.com, text/plain, User's email address
password, string, false, ********, text/plain, User's password
After entering the parameters, click the "OK" button to generate the corresponding request parameters.
Method 2: Generating Parameters from Existing Formats
When working with body parameter types such as JSON or XML, you can paste content directly in the specific format to generate parameters automatically.
Use JSON to Bulk Add Parameters:
Click the "Generate from JSON" button in the parameter list, which opens a text editing box where you can paste or input the JSON object.
Comments in the JSON can be recognized as parameter descriptions. You can specify the override mode or naming conventions as required. Here’s an example:
{"region_id": "82","email": "b.wawjn@gmail.com", // User's email"sales_channel_id": "12","customer_id": "98","country_code": "70", // Country code"context": {"ip": "::1","user_agent": "Chrome"
},// Other parameters...
}
You can preview the inputted JSON data before confirming.
After editing, click the “OK” button to generate the corresponding request parameters.
If the “Generate Automatically” switch is turned on, request examples are also generated.
Use XML to Bulk Add Parameters:
Similar to JSON, you can also paste your XML data into the editing box. Click the "OK" button to generate the relevant request parameters. Here’s an example:
Import from Database:
You also have the option to import parameters from a database by connecting and selecting the desired data tables. The field comments in the database can be used as descriptions or names.
Alternatively, you can input SQL DDL statements to generate parameters (currently only supports MySQL), like so:
CREATE TABLE
carts
(
id int NOT NULL AUTO_INCREMENT,
region_id varchar(10) DEFAULT NULL,
email varchar(255) DEFAULT NULL,
sales_channel_id varchar(10) DEFAULT NULL,
customer_id varchar(10) DEFAULT NULL,
country_code varchar(10) DEFAULT NULL,PRIMARY KEY (
id
)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Method 3: Adding Common Parameters/Data Models
Apidog allows you to create and use predefined parameter templates, enabling reuse across similar APIs, notably through common parameters and data models.
Adding Common Parameters:
In the left navigation bar, select "Settings," then click "Common Parameters" to add parameters that you frequently use.
When you need to use a common parameter in the API, just click the parameter input box, and a selection panel will appear for you to choose your predefined parameters quickly.
Adding Schemas:
Find the "Schemas" option in the left navigation bar, click the "New Schemas" button, enter the model's name and description, then add fields and define each field’s type, example value, and description.
Schemas parameters can also be generated via JSON or JSON Schema, as mentioned in Method 2.
When you need to use a schemas in the request or response, simply click the type (e.g., object) and select "Reference other schemas" from the pop-up list.
Select the pre-defined shemas from the list and the parameters are automatically populated into the API.
If you need to add or modify some parameters, you can modify them in the corresponding “Data Schema”, or dereference them. When dereference, the request parameters are no longer dependent on the common data model, but exist independently and belong exclusively to the current API.
Method 4: Importing cURL Commands
Apidog supports direct importing of cURL commands, allowing for quick setup of request parameters, especially for APIs from third-party platforms that provide cURL commands for testing purposes, such as Shopify API.
To import a cURL command, simply copy the provided command and paste it into the address bar of a new API. Apidog will automatically parse the cURL command and generate the corresponding request parameters.
You can also click the "+" button next to the search box in your project, select "Import cURL," paste your copied command into the dialog, and click "OK."
Upon saving as an API, the JSON request body will automatically be structured to match the API documentation.
Conclusion
This article has presented various methods for batch adding request parameters in Apidog. You can use the bulk edit functionality for CSV data, generate parameters from JSON or XML formats, import from databases, utilize predefined parameter templates, or directly import cURL commands. These diverse approaches enable you to efficiently manage your API request parameters according to your needs.