#peppemu-metadata
1 messages ยท Page 1 of 1 (latest)
hi toby
all right
so just to make sure I get this right
I share a quick example
can I do this (links are strings) :
metadata[payment_links][0], link_0)
metadata[payment_links][1], link_1)
metadata[payment_links][2], link_2)
etc...
??
As long as those values are strings, don't exceed the character limits, and don't contain sensitive information, then yes.
https://stripe.com/docs/api/metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
all right, thanks
then I have a followup questin
cause I am not able to do what I just wrote in that example ๐ฅถ
let me add some more info
I am using this (and I know the i is missing after [metadata])
let urlencoded_update_product = new URLSearchParams();
for (let i = 0; i < list.length; i++){
let link = list[i]
urlencoded_update_product.append("metadata[payment_links]",link);
}
and I then use the urlencoded_update_product in the body of the api call
now, how can u add the index of each item that's coming from a list ?
Add the index where?
as in:
metadata[payment_links][0], link_0
metadata[payment_links][1], link_1
It's up to you how you structure your data. Looking at your above examples though I want to point out that keys need to be unique values.
so I cant have an array of payment links in the metadata?
Sure, but you'll need a layer that remaps them from an array to a dictionary. Or use the index as the key (though that may make retrieving the information from the Stripe object more tedious).
all right and then I would just do:
metadata[payment_links], dictionary
instead of goin through all the items ?
If you're passing entire URLs, then I suspect your entire dictionary won't fit within the 500 character limit.
What are you actually trying to accomplish here? It sounds like you're trying to save payment links on an object, but would you mind clarifying what type of object and why?
Is that the only thing you're planning to store in the products metadata?
yea that\s most important bit I need
there is a thread I had with one of your colleagues where you can see how and why we came up with this
not sure how I can share it iwth u
If you're not using metadata on the product for anything else, then you can use the key to map to the index of your array:
1: <second_payment_link,
...}```
that's exactly what I want to do
but it does not work whne I try it
and it gives me an error
I am not sure how to set the index given that I am pulling the items using a loop
like if I do this:
for (let i = 0; i < list.length; i++){
let link = list[i]
urlencoded_update_product.append("metadata[payment_links]["+i+"]",link);
}
i get an error....
and I cant find any example in your documentation...
What error do you get? this looks like code that runs on your side, what are you actually sending to Stripe?
message: "Invalid value type: {:"0"=>"https://buy.stripe.com/bIY16C3r7eurgzm3ig", :"1"=>"https://buy.stripe.com/28oeXsd1H2LJcj62ee"} must be a string"
do you have any link to your documentation to see how to add a dictionary to metadata ?
No, because our metadata is a series of string-based key/value pairs, so it already is a dictionary. Do you have a request ID (req_XXX) from a request that errored? It'll give us more insight into exactly what you're sending us.
the code I pasted above is what I am sending
where list = a list of payment links
Yeah that's not right. You can't pass structured data into metadata like that. You need to decompile it and pass it in as a string-key matched to a string-value, as shown in the code snippet in the metadata documentation that I linked earlier. Is that Node you're working with?
ah ah ok, thanks toby
that's already a big news for me ๐๐ฝ
I saw the documentation but I am still not sure how i can actually do that
@atomic storm hey there just stepping in for @proven barn ๐ . do you need more help with this, or is that a sufficient pointer for you to restructure your metadata to get what you need?
hi there
I am looking into this
I am gonna test a few more things and then see
is this the only way I can achieve what I'd like to have ?
ignore the "payment_links" please
Yep you can create a pseudo-array by appending numbers like that if you like ๐
As long as metadata is a flat object with string keys/values
I see