#raffi23_search-data-freshness
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1326550077057142795
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
this is how how i am calling the api
await stripe.paymentIntents.search({
query: "metadata[\'orderId\']:\'${order.id}\'",
limit: 1,
})
Could you please share a requestId ?
hey man, i just tried to do the request again, now it is working not sure why it was returning empty results
do you think i should not rely on the search api?
this is the first time i go to production with stripe and i would like to take your opinion
There must be issue on your request call. Please double check your request body.
can you please check this request id? req_kBm3Q5vheiNb9r
Yes and do you have a PaymentIntent Id that should match this search ?
Could you please share two requestIds ? where one is working as expected and another not using the same request body.
here is the payment intent: pi_3QezEdL53dUV0i9Y1cn7Iqme
this request worked: req_kBm3Q5vheiNb9r
this didn't: req_iM4Hs8KZc6zA3z
i didn't change anything in the query so the request body should be similar
I mean not sure if we can say it worked or not but one has returned results and one didn't
I think these show the issue more accurately as there was more space in between requests
empty response from: req_wmRzG1n0CN5k4j
returned results from: req_Hl732clJVKO9qI
payment intent: pi_3QezbFL53dUV0i9Y1IkVMrzN
Checking..
Hi there ๐ jumping in as my teammate needs to step away soon. Let me take a closer look at those requests for you.
okay thanks
It looks like your first request to our Search API was made before the Payment Intent had been indexed.
The Search API shouldn't be used with the expectation that data will be available in its results immediately. It takes time for objects to be indexed into the results of the Search API:
https://docs.stripe.com/search#data-freshness
The data is typically available for searching within a minute, but could take longer.
What are you trying to accomplish in this flow? There may be a better approach to retrieve the Payment Intent here.
raffi23_search-data-freshness
oh okay, the flow is like this, when a customer wants me to cancel their order i search for the payment intent that has the order id and refund it
i was testing a purchase then refund in production also and this happened so i was concerned
Gotcha. Hm, I see your search is currently using metadata in the search query, which you can't use as a filter with our list endpoints (which don't have this data delay).
Since you're looking up Payment Intents for a Customer, do you happen to have the Customer's ID when trying to find those?
If so, you can use the list endpoint and pass the ID of the Customer to list their associated Payment Intents:
https://docs.stripe.com/api/payment_intents/list
Then step through the results to find the one with the metadata you're looking for.
Yes I do have the customer id, does this endpoint have a limit on how many payments can be retrieved? and does it return them in descending order?
Also coming to think about it, in general there is very little chance that a customer might want a refund right away which makes it okay to use the search api, can you give me your take here?
They are returned in descending order. By default 10 results are returned, but you can use the limit parameter, shown in the list of accepted paramters in the endpoint definition I linked to, to set that as high as 100. Beyond that you would need to implement pagination, either on your own or using our auto-pagination feature:
https://docs.stripe.com/api/pagination/auto
If you think there's very little risk of that, then maybe you're fine. If I was in your shoes I'd try to proactively mitigate the chance of this running into problems, but I'm not as familiar with your use case or how likely this scenario is to occur as you are.
sounds good, thanks for the advice it is appreciated
I think this would be all i need thanks man
Any time, happy to help! Best of luck with the project!