Reputation: 9
$client = new Client([
'base_uri' => 'http://localhost',
]);
$response = $client->request('POST', '/API/customerOrder/createOrder.php', [
'json' =>[
'SKU_QUANTITY' => [9,7,8],// we send the array of 3 elements to specific ID array.
'CUSTOMER_ID'=>[12,23,34] // This is the array which contain ID.
]
]);
Upvotes: 1
Views: 105
Reputation: 349
If you are using Laravel and consuming the internal APIs using Guzzle, your request seems correct, however the data that you are posting to the endpoint could be incorrect. Here is an example of how it should be:
use Illuminate\Support\Facades\Http;
$response = Http::post('http://example.com/users', [
'name' => 'Steve',
'role' => 'Network Administrator',
]);
In your case, the request would be:
$data = [
'SKU_QUANTITY' => [9,7,8],
'CUSTOMER_ID'=>[12,23,34],
];
$response = Http::post('/API/customerOrder/createOrder.php', $data);
And in the API route that handles your request, you can get the data as follow:
$customerIdsArray = $request->get('CUSTOMER_ID');
//to get first element of the customer array you would use:
$Id1 = $customerIdsArray[0];
You could iterate the array and process the IDs as per your requirement.
Upvotes: 1