lmsqueezy / lemonsqueezy.js

Official JavaScript SDK for Lemon Squeezy.
https://docs.lemonsqueezy.com/api
MIT License
399 stars 26 forks source link

No use for the "include" param. #82

Closed maxjnq closed 6 months ago

maxjnq commented 6 months ago

Hi guys,

When retrieving my variants including the product relationship for instance as follow

    const variants = await listVariants({
        include: ['product'],
        page: { number: 1, size: 30 },
        filter: { status: 'published' },
    })

All I get in the relationships is product.types and product.id which has no use at all as each variants already include the product_id, variant.attributes.product_id.

What I think would be more useful is having more fields from the relationships, like product.name, and so on.

Am I miss using something?

Let me know.

keyding commented 6 months ago

Hi, @maxjnq

Product information is included in the data.included field.

An example of which is shown below:

const {
  statusCode,
  error,
  data,
} = await listVariants({ include: ["product"] })

if(error)
  console.log(statusCode, error)
else 
  console.log(data.included) 

// [
//   {
//     type: "products",
//     id: "164559",
//     attributes: {
//       store_id: 10612,
//       name: "Test API",
//       slug: "test-api",
//       description: "<p>test</p>",
//       status: "published",
//       status_formatted: "Published",
//       thumb_url: null,
//       large_thumb_url: null,
//       price: null,
//       price_formatted: "Usage-based",
//       from_price: null,
//       to_price: null,
//       pay_what_you_want: false,
//       buy_now_url: "xxxxx",
//       from_price_formatted: null,
//       to_price_formatted: null,
//       created_at: "2024-01-10T13:08:13.000000Z",
//       updated_at: "2024-01-10T13:14:03.000000Z",
//       test_mode: true,
//     },
//     // ...
//   }
// ]

I hope this helps.

maxjnq commented 6 months ago

Oh great. Thanks a lot!