How do I create a Stripe price with a custom ID thru their API?
I can create prices with custom IDs in the Stripe Dashboard, but when I create using the API I get this error:
Received unknown parameter: id
For example, I am using this code to synchronize the test environment with the same prices as the live environment, but I can't get the id
to sync:
$testClient->prices->create([
'id' => $livePrice->id,
'product' => $livePrice->product,
'nickname' => $livePrice->nickname,
'currency' => $livePrice->currency,
'unit_amount' => $livePrice->unit_amount,
'active' => $livePrice->active,
]);
For some reason I don't see the Stripe API price create endpoint has support for creating prices with a custom ID but I am wondering if maybe I am just doing something wrong here. Seems very strange they'd leave that off the API for prices but include it in the dashboard and on the products API.
As answered above, it's not possible.
Some Stripe accounts had the ability to set custom IDs on Prices but that feature was removed.
What I would add to @quine9997's answer is that you should consider setting the Price's nickname as it's
lookup_key
.The reason being you can actually list Prices by
lookup_key
, while you can't by nickname.So let's say you have this call to create your Price:
If you do this on different Stripe accounts (or on live / test mode for the same account), this will give you two different Price IDs.
But you can just get it regardless of the account with this code:
This will give you a list, containing (hopefully) one Price.