1

I need some to do integration with accounting software (Xero).

once an order is completed, it sends an API call to Xero to create an invoice in Xero. once Xero does a reconciliation that payment is received. it will be sending an API call to bagisto that payment is processed, and the order is good to ship.

Error: UnexpectedValueException

Invalid response received from Authorization Server. Expected JSON.

    public function getAccessToken($grant, array $options = [])
    {
        $grant = $this->verifyGrant($grant);

        $params = [
            'client_id'     => $this->clientId,
            'client_secret' => $this->clientSecret,
            'redirect_uri'  => $this->redirectUri,
        ];

        $params   = $grant->prepareRequestParameters($params, $options);
        $request  = $this->getAccessTokenRequest($params);
        $response = $this->getParsedResponse($request);
        if (false === is_array($response)) {
            throw new UnexpectedValueException(
                'Invalid response received from Authorization Server. Expected JSON.'
            );
        }
        $prepared = $this->prepareAccessTokenResponse($response);
        $token    = $this->createAccessToken($prepared, $grant);

        return $token;
    }

When I call the function the error occurred.

    $response = $this->getParsedResponse($request); 

Error Is HERE

Video is HERE

Pritesh
  • 1,066
  • 3
  • 15
  • 35
  • Hey Pritesh, what library are you using to implement the Xero API? I would suggest checking out the official PHP library here: https://github.com/XeroAPI/xero-php-oauth2 That might give you some insight into how your implementation differs. – RJaus Aug 29 '21 at 23:02

1 Answers1

0

The error clearly says that you are JSON is expecting from the server end. But in your case server is not able to detect the JSON response. That's why you are getting issues. There is not Bagisto stuff here. You are simply integrating some new package.

Just check your request and response.

Devansh
  • 52
  • 7