public function toApi(Request $request) { $client = new \GuzzleHttp\Client(); $input = $request::all(); $command = 'request'; $api_key = 'MjuhMtfAAfvJqzbnWFLA'; // $api_key = 'mysendykey'; $api_username = '******'; // $api_username = '******'; $from_name = 'Chris Munialo'; $from_lat = $input['lat']; $from_long = $input['lng']; $from_description = ''; $to_name = 'TRM'; $to_lat = $input['lat1']; $to_long = $input['lng1']; $to_description = ''; $recepient_name = 'John'; $recepient_phone = '0710000000'; $recepient_email = '*****@*****.**'; $pick_up_date = '2016-04-20 12:12:12'; $status = false; $pay_method = 0; $amount = 10; $return = true; $note = 'Sample note'; $note_status = true; $request_type = 'quote'; $info = ['command' => $command, 'data' => ['api_key' => $api_key, 'api_username' => $api_username, 'from' => ['from_name' => $from_name, 'from_lat' => floatval($from_lat), 'from_long' => floatval($from_long), 'from_description' => $from_description], 'to' => ['to_name' => $to_name, 'to_lat' => floatval($to_lat), 'to_long' => floatval($to_long), 'to_description' => $to_description], 'recepient' => ['recepient_name' => $recepient_name, 'recepient_phone' => $recepient_phone, 'recepient_email' => $recepient_email], 'delivery_details' => ['pick_up_date' => $pick_up_date, 'collect_payment' => ['status' => $status, 'pay_method' => $pay_method, 'amount' => $amount], 'return' => $return, 'note' => $note, 'note_status' => $note_status, 'request_type' => $request_type]]]; $clientHandler = $client->getConfig('handler'); // Create a middleware that echoes parts of the request. $tapMiddleware = Middleware::tap(function ($request) { $request->getHeader('Content-Type'); // application/json $request->getBody(); // {"foo":"bar"} }); $endpoint = 'https://developer.sendyit.com/v1/api/#request'; // $info = json_encode($info); $client = new \GuzzleHttp\Client(); $res = $client->request('POST', $endpoint, ['json' => $info, 'handler' => $tapMiddleware($clientHandler), 'headers' => ['Accept' => 'application/json']]); // $res->getStatusCode(); // "200" // $res->getHeader('content-type'); // 'application/json; charset=utf8' $pns = json_decode($res->getBody(), true); // var_dump($pns); // echo $pns; // echo $pns; // $pns= $res->getBody(); // {"type":"User"... // Send an asynchronous request. // $request = new \GuzzleHttp\Psr7\Request('POST', $endpoint ); // $promise = $client->sendAsync($request)->then(function ($response) { // $response->getBody(); // }); // $promise->wait(); return view('orders.new', ['pns' => $pns]); }