Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Can I use an array as metadata value?

I'm trying to create a product in Stripe (using Next.js + Node) with a metadata of the following format:

metadata: {categories: ['foo', 'bar']}

but it seems I can't workaround string-only values in metadata.

Creating a product in the stripe dashboard with brackets in the metadata value result in, when being retrieved:

categories: "['foo', 'bar']"

Trying to create with Node:

const new_product = await stripe.products.create({
      name: 'new product',
      metadata: {categories: ['foo', 'bar']}
})

resulted in:

Error: Invalid value type: {:"0"=>"foo", :"1"=>"bar"} must be a string

This confirms that the value must be a string. The docs were kind of unclear as to the specific type allowance:

You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long.

But I suppose I'm stuck with string values in the metadata.

What is the best workaround for this?

I know I can loop through an object as long as its keys are indices, but I also will want more metadata keys and values. String delimination using split just sounds like a pain. I'm certain there are more ways to effectively use JS objects, but I'm trying to go as simple as possible, as non-developers will also want to make products that follow this archetype.

Thank you for any help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Stripe stores this data as a single string and AFAIK there is no way around that.

However, when using a Stripe library like the one for Node.js, it does the conversion of the string into an object you can traverse. I created a product with the same categories as the code you shared and was able to access the .categories property using dot notation.

const getProduct = async (id) => {
  console.log("Fetching product to evaluate metadata");
  const product = await stripe.products.retrieve(id)
  const meta = product.metadata
  // console.log(meta);
  console.log(meta.categories); 
}

node test.js
Fetching product to evaluate metadata
["foo", "bar"]
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda