chargebee / chargebee-php

PHP library for the Chargebee API.

Home Page:https://apidocs.chargebee.com/docs/api?lang=php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting "Response not in JSON format. Might not be a ChargeBee Response" exception in some requests

canatufkansu opened this issue · comments

Hi,

We are using Chargebee for almost 2 months. Sometimes we are getting errors that disturbs our services. When we check the logs we found that sometimes ItemFamilies response that returns from Chargebee API in not a valid json format. For this reason we cannot list ItemFamilies to our customers in some cases. We are using Chargebee API V2

Following is our code that returns all of the ItemFamilies from Chargebee API

        $families = collect();
        $itemFamilies = \ChargeBee_ItemFamily::all();

        foreach ($itemFamilies as $itemFamily) {
            $families->add($itemFamily->itemFamily()->GetValues());
        }

        return $families;

in some cases we get he following error

ERROR: Response not in JSON format. Might not be a ChargeBee Response. {"exception":"[object] (Exception(code: 0): Response not in JSON format. Might not be a ChargeBee Response. at /application/zeus/vendor/chargebee/chargebee-php/lib/ChargeBee/Curl.php:78)"}

when we check the code we can see that Chargebee's API response is not a valid json response

public static function processResponse($response, $httpCode) {
        $respJson = json_decode($response, true);
        if(!$respJson){
            throw new Exception("Response not in JSON format. Might not be a ChargeBee Response.");
        }
        if ($httpCode < 200 || $httpCode > 299) {
            self::handleAPIRespError($httpCode, $respJson,$response);
        }
        return $respJson;
    }

Can you share your domain details, code snippet and the timestamp when you next encounter this issue? It will be helpful for us to debug.

Hi. I got same error when i create or get all subscriptions.
Response not in JSON format. Might not be a ChargeBee Response.
Here is code for getting all subscriptions

$api_key = "test_8GRSM***********";
$site_url = "m*****-test.chargebee.com/";  
Environment::configure($site_url, $api_key);
$all = Subscription::all(array(
      "limit" => 2,
));

One thing more in documentation like this
ChargeBee_Environment::configure("{site}","{site_api_key}");
but in library and some documentation code
Environment::configure($site_url, $api_key);

What is the difference between them ?
chargebee

Hi @canatufkansu and @haseebmirza
We tested it from dev end and getting proper json response and response code for both ChargeBee_ItemFamily::all()/ItemFamily::all and ChargeBee_Subscription::all()/ Subscription::all().
Could you Please send us the respJson when you next encounter this issue? It will help us to know the issue better.

@haseebmirza Regrading your question related to documentation, Currently we are having 2 versions of chargebee-php i.e v3.x.x and v2.x.x.
For v3.x.x ---> Environment::configure($site_url, $api_key);
For v2.x.x ---> ChargeBee_Environment::configure("{site}","{site_api_key}");

I got this error as well. It was working for months. And all of a sudden, it starts pulling this error.

This is on our production/live server.

try { $method = ChargeBee_Subscription::retrieve($subscription_id); echo '<pre>'.print_r($method).'</pre>' } catch (Exception $e) { echo $e->getMessage(); }

What do I need to provide for you guys to help me. Thanks

as @nicozarris said, we are seeing the same issue right now. This seems a systemic problem on your end. We have not made any changes on our side and the error started occurring. Please fix this is urgent.

Thank you for notifying us. We are looking into this issue. Could you please help us with the below information?

  1. The output of the composer show command or what chargebee-php version are you using.
  2. What PHP version are you using?
  3. Are you getting this error for all the APIs or only specific API?
  4. Are you facing this issue intermittently or for every API call?
  5. Domain details and timestamp (if possible).

As per this our servers were returning intermittent errors. We sincerely regret the inconvenience caused. We have resolved the issue, and the service is back to normal now. If you are still facing this issue, please reopen.

Getting this message for paymentsource for 12/29/2021. Been working for months with no code change on our end as well.