api - I can create a address ...
-
I following the https://devdocs.bagisto.com/1.x/api/addresses.html#create-a-new-address example, but I no have success... For tests I am using the the Postman.
The version of Bagisto is v1.1.0 (24th of March 2020)
I can login adding the [?token=true] to [api/customer/login] .
After that I try to create a address for this customer and the error 500 Internal Server Error occurs.
I try to create mannally the address and read it by api using GET <host>/api/addresses and I can get it !!!
But I can create and update...
Somebody could help me please?![alt text]( image url)
-
You need to send your query in raw JSON format.
-
@devansh-webkul
It's worked! Tahnk you very much !!! -
Hello, @devansh-webkul
But how can I do on Laravel?
I developed another system in Laravel thar consume Bagisto API, so I need to create a address on Bagisto E-commerce system throghout this another system in Laravel .
I am using Guzzle like this...$response = $client->request('POST', config('global.ecsite.url').'/api/addresses/create', [ 'form_params' => [ 'address1'=>[$member->address], 'city'=>$member->city, 'country'=>'JP', 'country_name'=>'Japan', 'phone'=>$member->fixed_phone, 'postcode'=>$member->zipcode, 'state'=>$member->prefecture, ]
and the response value is:
'Client error: `POST https://shop.mysite.com/api/addresses/create` resulted in a `401 Unauthorized` response: {"error":"Unauthenticated"} ',
Could you help me please?
-
@William-Hatanaka You need to send the csrf token too, since the api using laravel
-
@darkuser123
I did the following things:- I logged with a customer
$client = new \GuzzleHttp\Client([ 'headers' => [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', ], ]); $response = $client->request('POST', config('global.ecsite.url').'/api/customer/login', [ 'query' => ['token'=>'true'], 'form_params' => $data ]); $responseData = json_decode($response->getBody(), true); $token=$responseData['token'];
And after that I filled a array with the address data.
$data=[ 'address1' => ['Clock Tower'], 'city' => 'Dehradun', 'country' => 'IN', 'country_name' => 'India', 'phone' => '24833333001', 'postcode' => '222222', 'state' => 'UT', ]; $client = new \GuzzleHttp\Client([ 'headers' => [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => 'Bearer '.$token, ], ]); $response = $client->request('POST', config('global.ecsite.url').'/api/addresses/create', [ 'form_params' => $data, ]);
But the response value is
Client error: `POST https://shop.whatanaka.com/api/addresses/create` resulted in a `401 Unauthorized` response: {"error":"Unauthenticated"}
What am I doing wrong? Could you help me, please?
-
Please check
$token
variable. Are you getting a token? -
@devansh-webkul
I don't know if it is the right way to take a token...$client = new \GuzzleHttp\Client([ 'headers' => [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', ], ]); $response = $client->request('POST', config('global.ecsite.url').'/api/customer/login', [ 'query' => ['token'=>'true'], 'form_params' => $data ]); $responseData = json_decode($response->getBody(), true); $token=$responseData['token'];
I take the token in this last line after login ..
-
@devansh-webkul
I added the command Log::info() on method __construct(CustomerAddressRepository $customerAddressRepository) of the app/bagisto/packages/Webkul/API/Http/Controllers/Shop/AddressControler.php to check if all data I sending to api addresses/create is arriving.
All data is arriving BUT the store() method is not executing...
If I run by postman the store() method is executed...
Do you have any ideia what I need to configure to execute correctly ?
Please, could you help me? -
Can you share with me both the screenshot of request data that you are sending in postman and as well as with the guzzle client?