Prasad
Prasad

Reputation: 59491

Get customerProfileId using the customer id in Authorize.Net

I need to retrieve the customerProfileId from Authorize.Net.

How to get the customerProfileId with the merchantCustomerId or the email which is used during the customer profile create in Authorize.Net for my asp.net mvc(C#) application.?

Upvotes: 3

Views: 2970

Answers (2)

John Conde
John Conde

Reputation: 219814

You cannot directly query the API by anything other than customerProfileId. The best you can do is use the getCustomerProfileIdsRequest to retrieve all of the profiles you created and then call getCustomerProfileRequest to get the profile information. Then you can check to see if it matches the email address or merchantCustomerID you have on file. If you have a lot of profiles this may take a while, but a simple loop in your code should make it easy to do.

Upvotes: 0

JeremyS
JeremyS

Reputation: 179

If you try to create a new Customer Profile, with a Merchant Customer ID which is already in use, Authorize.NET will return error E00039 - 'A duplicate record with ID {0} already exists.' where {0} is the Customer Profile ID.

So, for example, if you are trying to code logic to create a new Customer Profile only if the Merchant ID does not already exist I've found the easiest way to do this is go ahead and try to create it, and look for:

((ANetApiResponse)response).messages.resultCode == messageTypeEnum.Error

If so, then your Customer Profile ID can be found by running a regular expression against:

ErrorResponse.messages.message[0].text

and you can try to parse out the Customer Profile ID from the error message. This is the only way I've found which actually scales. You can't feasibly retrieve 100k customer records and iterate over them looking for a match each time you try to create a new record, but you can count on Authorize.NET business logic throwing an error if your Merchant Customer ID is already in use. Of course they could alter the format of the error message at any time, so YMMV.

Upvotes: 5

Related Questions