• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

api - I can create a address ...

General Discussion
3
10
820
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W
    William Hatanaka last edited by 26 Nov 2020, 00:00

    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](fec6dfa7-68f6-4c21-964f-1dbeb56cb8f8-image.png image url)

    1 Reply Last reply Reply Quote 0
    • devansh-webkul
      devansh-webkul last edited by 26 Nov 2020, 04:18

      Hi @William-Hatanaka,

      You need to send your query in raw JSON format.

      W 2 Replies Last reply 26 Nov 2020, 16:00 Reply Quote 0
      • W
        William Hatanaka @devansh-webkul last edited by 26 Nov 2020, 05:42

        @devansh-webkul
        It's worked! Tahnk you very much !!!

        1 Reply Last reply Reply Quote 0
        • W
          William Hatanaka @devansh-webkul last edited by 26 Nov 2020, 16:00

          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?

          D 1 Reply Last reply 27 Nov 2020, 07:04 Reply Quote 0
          • D
            darkuser123 @William Hatanaka last edited by 27 Nov 2020, 07:04

            @William-Hatanaka You need to send the csrf token too, since the api using laravel

            W 1 Reply Last reply 27 Nov 2020, 08:19 Reply Quote 0
            • W
              William Hatanaka @darkuser123 last edited by 27 Nov 2020, 08:19

              @darkuser123
              I did the following things:

              1. 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?

              1 Reply Last reply Reply Quote 0
              • devansh-webkul
                devansh-webkul last edited by 27 Nov 2020, 13:07

                Hi @William-Hatanaka,

                Please check $token variable. Are you getting a token?

                W 2 Replies Last reply 2 Dec 2020, 00:47 Reply Quote 0
                • W
                  William Hatanaka @devansh-webkul last edited by 27 Nov 2020, 13:49

                  @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 ..

                  1 Reply Last reply Reply Quote 0
                  • W
                    William Hatanaka @devansh-webkul last edited by 2 Dec 2020, 00:47

                    @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?

                    1 Reply Last reply Reply Quote 0
                    • devansh-webkul
                      devansh-webkul last edited by 2 Dec 2020, 14:53

                      Hi @William-Hatanaka,

                      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?

                      1 Reply Last reply Reply Quote 0
                      3 out of 10
                      • First post
                        3/10
                        Last post