Jump to content

Abk

Members
  • Posts

    4
  • Joined

  • Last visited

Reputation

0 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Solution for developer: is tax_rate_id must be ES_EXEMPT Solution for good UX: Message error on API must be more descriptive. Error in GET Error in GET 422 - [{"$severity":"error","$dataCode":"RecordInvalid","$message":"is not included in the list","$source":"invoice_lines.tax_rate_id"},{"$severity":"error","$dataCode":"RecordInvalid","$message":"must be 'ES_EXEMPT' for Customers outside the EU.","$source":"invoice_lines.tax_rate_id"}]
  2. Error message that does not correctly identify the problem: Error in GET Error in GET 422 - [{"$severity":"error","$dataCode":"RecordInvalid","$message":"is not included in the list","$source":"line_items.tax_rate"},{"$severity":"error","$dataCode":"RecordInvalid","$message":"must be 'Zero Rated' for Customers outside the EU.","$source":"line_items.tax_rate"}] - line_items is invoice_lines? - tax_rate not exists in doc or demo postman. Exists tax_rate_id Params send into payload are below. User contact is outside Europa (China) [ 'sales_invoice' => [ 'contact_id' => '7a37e41cd14f45e9b19269e38f2ff985', 'date' => '2023-10-15 07:00:29', 'reference' => 'MAMS-7266', 'invoice_lines' => [ 0 => [ 'description' => 'Wordpress Manejado China - sxxxxxxxx.com (22/10/2023 - 21/11/2023)', 'ledger_account_id' => '1ea6606e04c1489c802f733ea65035a1', 'quantity' => 1, 'unit_price' => '19.99', 'tax_rate_id' => 'ES_ZERO', ], 1 => [ 'description' => 'Costo administrativo', 'ledger_account_id' => 'e28101ad59ad4b8f9798b59be32e9cf6', 'quantity' => 1, 'unit_price' => '0.88', 'tax_rate_id' => 'ES_ZERO', ], ], ], ] Any ideas ?
  3. After analyzing the refresh action in postman I see a difference in headers. Authorization I have tried use with $headers = [ 'Authorization' => 'Basic ' . base64_encode(config('services.sage.client_id') . ':' . config('services.sage.client_secret')), 'Accept' => 'application/json' ]; I have also done a test. - From Postman, I have requested the token refresh. - I have copied the new access token into my code. And my code works. So I don't understand why, if I get a new access token with the refresh one in my application, without error, the new access token tells me "$severity" => "error" "$dataCode" => "AuthorizationFailure" "$message" => "Access denied. Account inactive. (CAI)" "$source" => ""
  4. HI. I'm try to use API Accountig v3.1 ES On Postman I have installed Savagge examples, and connecting for get access token. Also make code for validate access token, and if is near to expired, get a new token using refresh token. API Accountig v3.1 ES public function verifyAndRefreshToken() { if ($this->extToken === null) { throw new SageException('No ExtToken found.'); } if (!$this->isAccessTokenValid()) { $this->refreshAccessToken(); } } public function isAccessTokenValid(): bool { return $this->extToken->access_expires->subSeconds(15) >= now(); } public function refreshAccessToken() { $extToken = ExtToken::find('sage'); $params = [ 'client_id' => config('services.sage.client_id'), 'client_secret' => config('services.sage.client_secret'), 'grant_type' => 'refresh_token', 'refresh_token' => $extToken->refresh, ]; $response = Http::asForm()->post(config('services.sage.refresh_endpoint'), $params); if ($response->successful()) { $data = $response->json(); ray($data)->red(); // Update tokens $extToken = ExtToken::find('sage'); $extToken->update([ 'access' => $response->json()['access_token'], 'refresh' => $response->json()['refresh_token'], 'access_expires' => now()->addSeconds($response->json()['expires_in']), 'refresh_expires' => now()->addSeconds($response->json()['refresh_token_expires_in']), ]); // Update propierty of class $this->extToken = $extToken; } else { throw new SageException('Error refreshing access token', $response->status()); } } ``` After this go to get the call public function getRequest() { $endpoint = $this->endpoint . '/' . $this->action; if (!is_null($this->key) && $this->key !== '') { $endpoint = $endpoint . '/' . $this->key; // https://api.accounting.sage.com/v3.1/bank_accounts } try { $response = Http::withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->extToken->access, // Valid token access ]) ->timeout(30) // Timeout in seconds ->get($endpoint, $this->params); ray($response->json(), $response)->die(); And get this error. array:1 [▶ 0 => array:4 [▶ "$severity" => "error" "$dataCode" => "AuthorizationFailure" "$message" => "Access denied. Account inactive. (CAI)" "$source" => "" ] ] I'm desperate with this issue.
×
×
  • Create New...