Just try in swagger UI,
Then send curl to free AI assistant to generate Code.
I’m assuming that laravel is PHP
<?php
// Function to generate a new GUID
function generateGUID() {
if (function_exists('com_create_guid')) {
return trim(com_create_guid(), '{}');
} else {
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
}
// Define variables for the API
$baseUrl = 'http://127.0.0.1:55667';
$apiPath = '/api2/purchase-order-form';
$apiKey = 'CgdBcGlUZXN0EhIJxOm3d83TuUgRvhBjwLYmeO4aEglOHwkiCH36SRGTmWDvW8sopA==';
$resourceId = '5174ef41-735e-45d3-83a8-085fde12a7e7';
// Build the GET URL
$getUrl = "$baseUrl$apiPath/$resourceId";
// Fetch the JSON template with a GET request
$ch = curl_init($getUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept: */*',
"X-API-KEY: $apiKey",
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('Error in GET request: ' . curl_error($ch));
}
curl_close($ch);
// Decode the JSON response
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
die('Error decoding JSON: ' . json_last_error_msg());
}
// Perform 10 POST requests
$postUrl = "$baseUrl$apiPath";
for ($i = 1; $i <= 10; $i++) {
// Update the 'Key' field with a new GUID for each request
$data['Key'] = generateGUID();
// Ensure 'CustomFields' and 'CustomFields2' are objects
$data['CustomFields'] = (object)[];
$data['CustomFields2'] = (object)[
'Strings' => (object)[],
'Decimals' => (object)[],
'Dates' => (object)[],
'Booleans' => (object)[],
'StringArrays' => (object)[],
];
// For each line in 'Lines', ensure 'CustomFields' and 'CustomFields2' are objects
foreach ($data['Lines'] as &$line) {
$line['CustomFields'] = (object)[];
$line['CustomFields2'] = (object)[
'Strings' => (object)[],
'Decimals' => (object)[],
'Dates' => (object)[],
'Booleans' => (object)[],
'StringArrays' => (object)[],
];
}
unset($line); // Unset reference to avoid side effects
// Make a POST request
$ch = curl_init($postUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept: */*',
"X-API-KEY: $apiKey",
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // Encode JSON correctly
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Log success or failure
if (curl_errno($ch)) {
echo "Request #$i failed: " . curl_error($ch) . "\n";
} elseif ($httpCode >= 200 && $httpCode < 300) {
echo "Request #$i succeeded: HTTP $httpCode\n";
} else {
echo "Request #$i failed: HTTP $httpCode, Response: $response\n";
}
curl_close($ch);
}
Result
Request #1 succeeded: HTTP 201
Request #2 succeeded: HTTP 201
Request #3 succeeded: HTTP 201
Request #4 succeeded: HTTP 201
Request #5 succeeded: HTTP 201
Request #6 succeeded: HTTP 201
Request #7 succeeded: HTTP 201
Request #8 succeeded: HTTP 201
Request #9 succeeded: HTTP 201
Request #10 succeeded: HTTP 201