#matrix-metadata
1 messages · Page 1 of 1 (latest)
hi! hard to say without knowing exactly what part of the JSON you're looking at. There's two objects, a Price and a Product. You can't set the Price metadata in the dashboard as far as I know, but you can set the Product one
I have set the metadata in the dashboard. i think it is at product level
however when i retrieve the session below there is no metadata cs_test_a1SkzIenNBniU0ICC0sgoaM97e9F8T4GXItE5kyzcfOeaRVxIAn2uiP3mJ
i am retrieving the session with line item expanded
this is the object
yep that's the Price metadata you're looking at
you'd need to make an API call to retrieve the product field and look at the metadata on that object to see what you set in the dashboard
or use expand:["data.price.product"] when getting the lines of the session https://stripe.com/docs/expand
thanks
how do i expand? currently i have the following
` const session = await stripe.checkout.sessions.retrieve(dataObject.id, {
expand: [
'line_items',
],}, {
stripeAccount: event.account,
});`
ok
I am getting some errors
Here is what i am using
` const session = await stripe.checkout.sessions.retrieve(dataObject.id, {
expand: [
'line_items',
'line_items.data[0].price.product'
],
}, {
stripeAccount: event.account,
});`
error is This property cannot be expanded (line_items.data[0]). You may want to try expanding 'line_items.data.data[0]' instead
ah ok
pretty sure it's just expand: ["line_items.data.price.product"] though.
just tried it and it works fine!
const session = await stripe.checkout.sessions.retrieve(id, {
expand: [
'line_items.data.price.product'
],
}, {
stripeAccount: event.account,
});
I am trying this and it does not work (maybe it is because i am expanding 2 levels?)
` const session = await stripe.checkout.sessions.retrieve(dataObject.id, {
expand: [
'line_items',
'line_items.data.price.product'
],
}, {
stripeAccount: event.account,
});
const line_items = session.line_items;
console.log("line item price xx: ", line_items.data[0].price.unit_amount);
const product = session.line_items.data.price.product;
console.log("product name xx: ", product.name);`
Error is "Cannot read property 'product' of undefined "
it should be const product = session.line_items.data[0].price.product;, same as the line above(you're trying to get the product of the price of the first line item)
oh
i have added [0] but still Cannot read property 'product' of undefined
could it be const product = session.line_items.data.price.product[0];?
no that wouldn't make any sense. product is not an array, data is
not sure what to tell you, your code works fine for me
what about const product = session.line_items.data.price.product.data[0];
what's the specific cs_test_xxx you're using?
no that wouldn't make any sense. product is not an array, data is
you don't have to guess at the structure, this is all in the API reference.
cs_test_a1SkzIenNBniU0ICC0sgoaM97e9F8T4GXItE5kyzcfOeaRVxIAn2uiP3mJ
i have an additional exapand in my code
expand: [ 'line_items', 'line_items.data.price.product' ],
is this the problem?