Stripe CLI: How to trigger events with nested metadata

Viewed 1351

I'm using Stripe CLI to trigger local webhook events. The command lets me set metadata using the following option / syntax:

--add resource:path1.path2=value

The metadata structure I'm trying to create looks like this:

{
    id: 1,
    artistId: 2,
    image: { 
        url: `https://somepath` 
    }
}

Here is my command:

$ stripe trigger payment_intent.succeeded --add payment_intent:metadata.id=1 --add payment_intent:metadata.artistId=1 --add payment_intent:metadata.image.url=https://www.arweave.net/ij5O6dDlzxOuWHUnikZapq10kkeEVe_elLWvpfE6ado?ext=PNG
⣟ Checking for new versions... Setting up fixture for: payment_intent
Running fixture for: payment_intent
Trigger failed: Request failed, status=400, body={
  "error": {
    "message": "Invalid value type: {:url=\u003E\"https://www.arweave.net/ij5O6dDlzxOuWHUnikZapq10kkeEVe_elLWvpfE6ado?ext=PNG\"} must be a string",
    "param": "metadata",
    "type": "invalid_request_error"
  }
}

At first, I thought that the . in the URL was breaking the syntax. But I get the same error when I substitute the URL with foo.

I think I must me doing something wrong with the path syntax. Or maybe there's a max limit to the depth of the data structure?

Update:

To sidestep this problem, I tried achieving the same thing using a fixtures json file but it didn't work. I got the same error, even though the syntax is JSON and unambiguous. I contacted Stripe support and they also seemed confused by this behavior. I'm awaiting a response from their escalation team.

3 Answers

if anyone coming here looking for a way to add multiple items in the metadata, you can do so by:

Stripe trigger payment_intent.succeeded --add payment_intent:metadata['key']=testing --add payment_intent:metadata['key2']=testing2

Stripe support confirmed that the metadata object can only have key / value pairs in which the values are strings. I was trying to use objects as values to create more complex data structures and this is not supported. :-(

It's the . in image.url key that's giving you problems. The . indicates to go down a level, but metadata params can't be nested like that.

You can modify the key to an acceptable value such as image_url or imageURL, and that should resolve the error you're hitting. (image_url did the trick for me)

Related