Reputation: 31
I am using laravel framework. I am trying to update an existing data using api (kinda new to this).
So this is my route
Route::group(['middleware' => 'web'], function () {
Route::post('/update_supplier_details/{id}', "UpdateController@update_supplier_details");
});
This is my Controller
public function update_supplier_details(Request $request, $id){
$details = $request->all();
$client = new CharmeAPI;
$token = Session::get('token');
$url = "https://api.charmeapp.com/api/v1/suppliers/{$id}?token={$token}";
$response = $client->request('POST', $url,['form_params' => $details])->getBody();
echo $response;
$data = json_decode($response, true);
$status = array_get($data, 'status');
$message = array_get($data, 'error.msg');
if($status == 'error'){
session(['update_supplier_details_error' => $status]);
return redirect()->back()->with('supplier_details_msg', $message);
}
else if($status == 'ok') {
session(['update_supplier_details_error' => $status]);
session(['supplier_details_first_name' => array_get($data, 'data.Supplier.first_name')]);
session(['supplier_details_last_name' => array_get($data, 'data.Supplier.last_name')]);
$first_name = session('supplier_details_first_name');
$last_name = session('supplier_details_last_name');
return $first_name.$last_name;
return redirect()->back()->with('supplier_details_msg', $first_name.' '.$last_name.' added successfully');
}
}
}
and I am getting this error -
ServerException in RequestException.php line 107: Server error: POST https://api.charmeapp.com/api/v1/suppliers/139?token=Q8vJLPvpnRImoz5Li4tVfGtGliyGBQcx3NdqYbNdRaYYvsaoLncyDvFHkriS resulted in a 500 Internal Server Error response:
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
(truncated...)
But if I use postman to call the api url I get the desired data Any help pls
Upvotes: 3
Views: 1829
Reputation: 31
Make sure you pass the correct parameters and token to the api.
Upvotes: 0