Is it possible to rename metadata? or transfer a metadata to other one?

13 views
Skip to first unread message

kydo....@gmail.com

unread,
May 10, 2018, 7:44:30 AM5/10/18
to Stripe API Discussion
Greeting,

I would like to transfer or rename a metadata which belongs to `Customer`.

We are maintaining the contract period with two metadatas,  `fromContractPeriod` and `toContractPeriod` , for yealy-contract but monthly-paid plan.

But Now We want to abolish the job and `toContractPeriod` for some reasons.

So, even if it's enabled to rename or transfer metadata,
we are going to face the problem how to do sefely because we have to deploy and rename metadata at the same time while service working.
But I want to know  at first whether possible to rename or transfer metadata.

Thanks in advance for any help on this.

Kydo

Remi J.

unread,
May 10, 2018, 8:01:05 AM5/10/18
to api-d...@lists.stripe.com
Hey Kydo,

This is definitely possible to do using our API. The idea is that you would fetch the object you are trying to update, set the new metadata key with the original value and then unset the original metadata key.You can see what it would look like for a customer in PHP for example here [1]. The output looks like this:

Stripe\StripeObject JSON: { "toContractPeriod": "March 1st" }

It confirms that the old metadata key has been removed and the new one has the expected value. If you want to do this on each customer, you would use the List Customers API [2] and for each one run a subset of that code to update it.

As for the second part of your question, you should be able to run the background job to update the data without having to sync the service. The idea would be to update your main service's code to look at the expected value in both metadata keys. When you need to access the period, you'd first look at the new value in "toContractPeriod". If it's empty you'd then fall back to "fromContractPeriod". You would then update the part of the code that sets this metadata key to use the new name for all new customers. Once that's ready you can run your script that unsets the old metadata key for existing ones. At the end of that, you can modify the main service's code again to only look at the new metadata key as the old one has been completely removed.

Hope this helps!
Remi


--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Reply all
Reply to author
Forward
0 new messages