Forum Discussion
POSTMAN multiple pool creation
Good day,
We are looking at using POSTMAN to "script" pool creations.
I am able to submit one pool at a time to the device but when I attempt multiple pools it fails with a 400 error.
Sample:
12 Replies
those are 2 json objects.
It should be one so you need to put those 2 in a list of dictionaries, something like this:
[
{
"name":"x10779",
"partition":"x",
"loadBalancingMode":"least-connections-node",
"monitor":"/Common/tcp",
"members":[
{"name":"x.x.x.x:10779"}
]
}
,
{
"name":"x10778",
"partition":"x",
"loadBalancingMode":"least-connections-node",
"monitor":"/Common/tcp",
"members":[
{"name":"x.x.x.x:10778"}
]
}
]- Chause1
Cirrus
Hi
Thanks for the feedback, however still no luck.
{"code": 400,"message": "Found invalid JSON body in the request. The expected JSON type is object. The received JSON type is array.","errorStack": [],"apiError": 1}[{"name":"y_PROD","partition":"y","loadBalancingMode":"least-connections-node","monitor":"/Common/tcp","members":[{"name":"x.x.x.x:11"},{"name":"x.x.x.x:11"}]},{"name":"x_PROD","partition":"y,"loadBalancingMode":"least-connections-node","monitor":"/Common/tcp","members":[{"name":"x.x.x.x:10"},{"name":"x.x.x.x:10"}]}]The error message you're seeing indicates that the API expects a single JSON object, but it received an array instead.
To create multiple pools, you need to send each pool creation request individually or use a different approach to handle multiple objects.Correct Approach for Multiple Pool Creation
- Single Request for Each Pool:
- You can send individual POST requests for each pool. This ensures that each request is a valid JSON object.
- Using a Collection Runner in POSTMAN:
- You can use POSTMAN's Collection Runner to iterate over a data file containing multiple pool configurations. This way, each iteration sends a single JSON object.
Example of a Single Pool Creation Request
Here’s how you should format a single pool creation request:
{
"name": "y_PROD",
"partition": "y",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{"name": "x.x.x.x:11"},
{"name": "x.x.x.x:11"}
]
}Using POSTMAN Collection Runner
- Create a Data File:
- Create a JSON or CSV file with your pool configurations. For example, a JSON file (pools.json) might look like this:
{
"name": "y_PROD",
"partition": "y",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{"name": "x.x.x.x:11"},
{"name": "x.x.x.x:11"}
]
},
{
"name": "x_PROD",
"partition": "y",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{"name": "x.x.x.x:10"},
{"name": "x.x.x.x:10"}
]
}
] - Set Up POSTMAN:
- Create a new POST request in POSTMAN with the URL for pool creation.
- In the Body tab, select raw and JSON.
- Use a variable for the request body, like {{requestBody}}.
- Pre-request Script:
- Add the following script in the Pre-request Script tab to set the request body from the data file:
- Run the Collection:
- Use the Collection Runner to run the collection with the data file (pools.json). POSTMAN will iterate over each entry in the file and send individual requests.
Why the Wrong Options are Incorrect
- Sending an Array Instead of an Object:
- The API expects a single JSON object per request. Sending an array directly causes a parsing error because the API cannot process multiple objects in a single request.
- Incorrect JSON Structure:
- JSON must be properly structured with matching braces and brackets. Any deviation from the correct structure will result in errors, as the API cannot parse the malformed JSON.
- JSON must be properly structured with matching braces and brackets. Any deviation from the correct structure will result in errors, as the API cannot parse the malformed JSON.
By following these steps, you should be able to create multiple pools using POSTMAN without encountering the 400 error.
- Single Request for Each Pool:
Probably you need an API request for each pool you create.
I don't know about Postman but it would be easier to use python or Ansible for this.
There is a way to add a data file ( where you have a list of json dictionaries) to Postman and get data from it but it did not work for me for some reason.
I've managed to create pools via Postman. You will need to a collection and under it the post request.
Then you need a file containing your configuration of the pools, under your user ~/Postman/files/ folder.
here is an example of a file:
[
{
"name": "pool1",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{
"name": "8.8.8.8:10779"
} ,
{
"name": "1.1.1.1:80"
}
]
},
{
"name": "pool2",
"loadBalancingMode": "round-robin",
"monitor": "/Common/tcp",
"members": [
{
"name": "9.9.9.9:10779"
},
{
"name": "2.2.2.2:443"
}
]
}
]You also need to put this under the Pre-request Script:
pm.variables.set(`requestBody`, JSON.stringify(pm.iterationData.toObject()))
Under the body, select raw and JSON type and put this:
{{requestBody}}
Then you have to run the Collection and select the above file.
And that's it.
I've also created a collection for creating a VIP.
- ishhyd82
Nimbostratus
Hi mihaic
Can you please share the script of VIP for the postman please along with the pool member? Is it possible to create postman for health mon.
Appreciate for your support
Certainly!
Here’s how you can create F5 Virtual Servers (VIPs), Pools, and Health Monitors using POSTMAN.Creating a Pool with Members
- Create a new POST request in POSTMAN.
- Set the URL to:
https://<BIG-IP IP address>/mgmt/tm/ltm/pool
- Authorization: Use Basic Auth and enter your BIG-IP credentials.
- Body: Select raw and JSON format. Use the following JSON payload:
{
"name": "example_pool",
"partition": "Common",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{"name": "192.168.1.1:80"},
{"name": "192.168.1.2:80"}
]
}Creating a Virtual Server (VIP)
- Create a new POST request in POSTMAN.
- Set the URL to:
https://<BIG-IP IP address>/mgmt/tm/ltm/virtual
- Authorization: Use Basic Auth and enter your BIG-IP credentials.
- Body: Select raw and JSON format. Use the following JSON payload:
{
"name": "example_vip",
"partition": "Common",
"destination": "192.168.1.100:80",
"mask": "255.255.255.255",
"pool": "/Common/example_pool",
"profiles": [
{"name": "/Common/http"}
]
}Creating a Health Monitor
- Create a new POST request in POSTMAN.
- Set the URL to:
https://<BIG-IP IP address>/mgmt/tm/ltm/monitor/http
- Authorization: Use Basic Auth and enter your BIG-IP credentials.
- Body: Select raw and JSON format. Use the following JSON payload:
{
"name": "example_http_monitor",
"partition": "Common",
"interval": 5,
"timeout": 16,
"send": "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: Close\r\n\r\n",
"recv": "HTTP/1.1 200 OK"
}Using POSTMAN Collection Runner
To automate the creation of multiple objects, you can use POSTMAN’s Collection Runner with a data file:
- Create a JSON file with your configurations. For example, pools.json:
[
{
"name": "example_pool1",
"partition": "Common",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{"name": "192.168.1.1:80"},
{"name": "192.168.1.2:80"}
]
},
{
"name": "example_pool2",
"partition": "Common",
"loadBalancingMode": "round-robin",
"monitor": "/Common/tcp",
"members": [
{"name": "192.168.1.3:80"},
{"name": "192.168.1.4:80"}
]
}
]- Set up POSTMAN:
- Create a new POST request for pool creation.
- In the Pre-request Script tab, add:
- In the Body tab, use {{requestBody}}.
- Run the Collection:
- Use the Collection Runner to run the collection with the pools.json file. POSTMAN will iterate over each entry and send individual requests.
By following these steps, you can efficiently create VIPs, pools, and health monitors on your F5 BIG-IP system using POSTMAN.
[1]: Using Postman for Creating F5 Virtual Servers and Pools [2]: Node/Pool/VIP Creation Script (from csv input) [3]: How to create custom HTTP monitors with Postman, curl, and Python
References[1] Node/Pool/VIP Creation Script (from csv input) | DevCentral - F5, Inc.
Good day!
To create multiple pools using POSTMAN, you need to ensure that your JSON body is correctly formatted. The error you're encountering is due to the JSON structure.
Correct JSON Format for Multiple Pool Creation
When sending multiple objects in a single request, you should wrap them in an array. Here’s how you can format your JSON:
[
{
"name": "x10779",
"partition": "x",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{"name": "x.x.x.x:10779"}
]
},
{
"name": "x10778",
"partition": "x",
"loadBalancingMode": "least-connections-node",
"monitor": "/Common/tcp",
"members": [
{"name": "x.x.x.x:10778"}
]
}
]Explanation of Each Option
- Array Brackets []:
- Purpose: Wrapping the pool objects in square brackets [] indicates that you are sending an array of objects.
- Why Correct: This structure is necessary when sending multiple objects in a single request. It tells the API to expect an array of pool objects.
- Individual Pool Objects {}:
- Purpose: Each pool object is enclosed in curly braces {}. This defines the individual pool configurations.
- Why Correct: Properly formatted JSON objects ensure that each pool's configuration is correctly interpreted by the API.
- Correct JSON Syntax:
- Purpose: Ensure that each key-value pair is properly formatted with double quotes around keys and string values, and that commas are used correctly to separate items.
- Why Correct: Proper syntax is crucial for JSON parsing. Any deviation can cause errors.
Why the Wrong Options are Incorrect
- Missing Array Brackets:
- Issue: Without the array brackets, the JSON is interpreted as multiple separate objects rather than a single array of objects.
- Result: This leads to a "400 Bad Request" error because the API expects a single JSON array containing multiple objects.
- Incorrect Comma Placement:
- Issue: Incorrect placement of commas or missing commas between objects can cause JSON parsing errors.
- Result: The JSON parser will fail to interpret the structure correctly, resulting in an invalid JSON body error.
- Invalid JSON Structure:
- Issue: JSON must be properly structured with matching braces and brackets.
- Result: Any deviation from the correct structure will result in errors, as the API cannot parse the malformed JSON.
By structuring your JSON as an array of objects, you should be able to submit multiple pool creations in a single request using POSTMAN. If you have any further questions or need additional assistance, feel free to ask!
- Array Brackets []:
here you have some links:
https://latebits.com/2023/02/01/using-postman-for-creating-f5-virtual-servers-and-pools/
https://github.com/czirakim/Postman-and-F5
- ishhyd82
Nimbostratus
mihaicF5_Design_EngineerThanks for your reply, is there any way where we can create the CSR, offload the certificate, create profile and call its VS through the postman script. Appreciate for your support in this regard.
- ishhyd82
Nimbostratus
F5_Design_Engineermihaic Awaiting for your kind update.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com