Last updated 3 minutes ago

Preventing Duplicates

A Note on Duplication

Important: There are different strategies to prevent creating duplicate customers.

Using the PUT request with an ID

If the customer has an identifier within your system prior to the request to create the customer in Rebilly, you may utilize your own identifier as long as it conforms to our basic requirements that it is a url-safe string of 50 characters or less.

In this case, we recommend you utilize a PUT request to create (or on duplicate ID update) the customer record.

Our tutorial uses this PUT technique.

Using GET + PUT or POST

If the customer does not have an identifier in your system, or your system doesn't maintain identifiers, then you may need to try to find if the customer exists first. The best way to do that is to do a GET request on the customers resource and filter by whatever should make that customer unique (such as their email address).

Email address is a popular such item for that, but for some businesses, other keys make more sense, such as name or phone number, or a combination of them.

To do this request, you need to understand how to generate a filter string.

GET customers?filter=primaryAddress.*.email:bob@example.com

Here is an example to filter by name and email:

GET customers?filter=primaryAddress.*.email:bob@example.com;firstName:Bob;lastName:Smith

If there is a matching customer in the response, then utilize that ID for the corresponding PUT request.

If there is not a matching customer, then create one using the POST request.

This technique requires 2 requests to implement the "insert on duplicate email update" type of behavior, where you can substitute email for any combination of values.

The preferred solution is the first option, of the PUT only requests.

Preventing Duplicate Transactions

To prevent a duplicate transaction, generate a unique id that you pass to the client form. Include that id as the requestId property value with your transaction request.

Only regenerate a different id for the client form after you receive a declined result in the response from Rebilly.