Discussions

Ask a Question
Back to All

How do I get the phone numbers (and CustomerChannels generally) that are a part of a customer object?

I need a way to get the phone numbers (and CustomerChannels generally) that are in a customer object.

The high level view of the whole thing I am trying to do is that on our website we are going to have a contact us/schedule a call form for our customers to use to get in touch with us. I know you guys have a contact us form type thing out of the box, but we need one that has a specific, possibly required, phone number field so we’re looking into making a custom one. Once the customer has inputted all the necessary information there are a few things I need to do in Gorgias. First I need to see if a customer exists under the email they gave (https://developers.gorgias.com/reference/get_api-customers). If there isn’t a customer I need to make one (https://developers.gorgias.com/reference/post_api-customers). Second I need to add the phone number that they inputted into that Gorgias customer object (https://developers.gorgias.com/reference/put_api-customers-id). Third I need to make a ticket with all the information that was given in the custom form (https://developers.gorgias.com/reference/post_api-tickets). The phone number needs to be in the customer object and not just a part of the ticket text so that the support agent can then call the customer from inside Gorgias.

The second step is where I think the main problem is. From what I can tell, I have no way to know if that given phone number is already a part of that Gorgias customer. If I try to just blindly update the Gorgias customer with the phone number (https://developers.gorgias.com/reference/put_api-customers-id), two problems could occur. The first problem is if the phone number was already a part of the Gorgias customer object the PUT request returns a 400 error and the message “phone number is already associated with another user” which is very unhelpful. The error message is just false. The phone number isn’t associated with another user, but with this user. The PUT returning an error code also seems a bit misleading, because there wasn’t error. Nothing was updated in the customer object, which since there was nothing to update is a success. The second problem with blindly sending a PUT request with the phone number to the customer object is that it will override all the preexisting CustomerChannels. If the customer already has two email addresses and a phone number in their customer object and I blindly make a PUT request with the new phone number being the only CustomerChannel in the request, those other email addresses and phone numbers are going to be deleted. There is no way to see which CustomerChannels are already in the customer object so that I can include them in the PUT request.