Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription returned as empty object #43

Open
ghost opened this issue Oct 26, 2023 · 6 comments
Open

Subscription returned as empty object #43

ghost opened this issue Oct 26, 2023 · 6 comments

Comments

@ghost
Copy link

ghost commented Oct 26, 2023

Version: [email protected]

Using this

const response = await this.chargebee.subscription
  .list({
    'sort_by[desc]': 'created_at',
    customer_id: {
      is: customerId,
    },
  })
  .request();
return response.list;

it returns an array of empty objects of type Result

Example of console.info(response) from the request above:

ListResult {
  list: [ Result {}, Result {}, Result {}, Result {} ],
  next_offset: undefined,
  responseHeaders: {
    date: 'Thu, 26 Oct 2023 10:59:56 GMT',
    'content-type': 'application/json;charset=utf-8',
    'transfer-encoding': 'chunked',
    connection: 'keep-alive',
    'cache-control': 'no-store, no-cache, must-revalidate',
    expires: 'Thu, 01 Jan 1970 00:00:00 UTC',
    'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
    pragma: 'no-cache',
    vary: 'Accept-Encoding',
    server: 'ChargeBee'
  }
}

So it seems that subscriptions are getting read, but actual data is not projected.

Chargebee is being instantiated the way it is displayed in docs:

this.chargebee = new ChargeBee();
this.chargebee.configure({
  site: this.resolveName(),
  api_key: this.resolveApiKey(),
});

Am I doing something wrong? is it a bug?

@sebyddd
Copy link

sebyddd commented Nov 14, 2023

Seeing the same issue when fetching Hosted Pages using the Typescript client. It appears to be a client-side parsing problem, specifically with the content field in the response. Direct API fetches via cURL yield the complete and correct response, indicating that the issue is isolated to the client's handling of the data.

@MerrittJ
Copy link

MerrittJ commented Jan 18, 2024

Also facing this issue with invoices and customers entities

        const items = await chargebeeClient.invoice
            .list({
                subscription_id: { in: [subscriptionId] },
            })
            .request();

returns

ListResult {
  list: [ Result {} ],
  next_offset: undefined,
  responseHeaders: {
    date: 'Thu, 18 Jan 2024 18:01:40 GMT',
    'content-type': 'application/json;charset=utf-8',
    'content-length': '3867',
    connection: 'close',
    'cache-control': 'no-store, no-cache, must-revalidate',
    expires: 'Thu, 01 Jan 1970 00:00:00 UTC',
    'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
    pragma: 'no-cache',
    'x-content-type-options': 'nosniff',
    vary: 'Accept-Encoding',
    server: 'ChargeBee'
  }

@yksolanki9
Copy link

Facing the same issue, any update on this?

@cb-sriramthiagarajan
Copy link
Collaborator

Hey folks, my apologies for the delay in response.

This looks like an issue with using console.log / info with the ListResult object directly. I can see the result being printed when I access an array item directly (like console.log(response.list[0]) instead of console.log(response.list)) and this also lets you access any property in the object directly (like response.list[0].subscription). So looping over the result and accessing individual objects should also work. Does this help?

One of the possible solutions to make the result work with console.log is to have util.inspect.custom method in our result object. We'll further evaluate in the future if this the right approach.

@skysteve
Copy link

There's something v weird happing with this library in general. If I debugger inspect I can see there's a lot of keys but if you do Object.keys() on the response only response headers shows up, which is likely why console log is broken. This also happens if you do JSON.stringify(reponse), you only get the response headers.

Screenshot 2024-08-29 at 14 14 38

I'm not sure I understand the additional complexity of the model class vs just returning a JS object.

If I do the following it works

  const response = await chargebee.subscription.retrieve(subId).request();

  return JSON.parse(response.toString())

But it adds additional complexity and isn't very intuitive (I had to read the code in the model class above to figure this out). There's potentially another argument that .toString() shouldn't return a JSON string either but I'll save that debate for others.

I see there's a V3 SDK coming so fingers crossed this is addressed in that but in the meantime hopefully the .toString() hack works for others

@cb-sriramthiagarajan
Copy link
Collaborator

Thanks for the note @skysteve. Yeah, I agree that it's not very intuitive. And the good news is that we've fixed this (and some) in v3, which is currently in beta 😄

It'd be great if you all could give it a try and share any feedback. We have a Migration guide for v3 and the README in the next branch also has more info on the usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants