#matrix-metadata

1 messages · Page 1 of 1 (latest)

cinder wigeon
#

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

mild harness
#

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

cinder wigeon
#

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

mild harness
#

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,
});`

cinder wigeon
#

line_items.data.price.product

#

the docs I linked also has some examples

mild harness
#

ok

mild harness
#

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

cinder wigeon
#

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,
});

mild harness
#

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 "

cinder wigeon
#

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)

mild harness
#

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];?

cinder wigeon
#

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

mild harness
#

what about const product = session.line_items.data.price.product.data[0];

cinder wigeon
#

what's the specific cs_test_xxx you're using?

cinder wigeon
#

you don't have to guess at the structure, this is all in the API reference.

mild harness
#

cs_test_a1SkzIenNBniU0ICC0sgoaM97e9F8T4GXItE5kyzcfOeaRVxIAn2uiP3mJ

#

i have an additional exapand in my code

#

expand: [ 'line_items', 'line_items.data.price.product' ],

#

is this the problem?

cinder wigeon
#

maybe, but I added that to my code and it still works

#

my guess is you are not actually running the code you think you are, like you didn't save the file after editing it.

mild harness
#

ok will try again

#

you were probably right

#

it works now

#

many thanks for your help!!! really