Join our Ask A Trainer Sessions and Chat With our Experts!

How To Remove Contact's Phone Number (& custom field value) via the API

SegmintD
Brand Influencer
0 Votes

How do I remove a contact's phone number (& custom field value) using the API? 

 

I have previously added a contact using the API. The contact contains a first name, last name, email, phone number ('other') and a custom field. If the contact's information changes, I would like to be able to remove these values. I can successfully remove the first name and last name using a putContact call; however, I have been unable to remove the phone number or custom field in this manner.

 

Thank you!

9 REPLIES 9
John__B
Employee
0 Votes

Hello SegmintD,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

Based on the information you provided, it sounds like your PUT request may not be including contact subresources. When updating a contact using the PUT request, any properties that are left blank or not included in the request are overwritten with null value - however this does not apply to contact subresources. Any subresources that are not included in the request, such as the “phone_number” or  “custom_field” subresources would not be updated in the request. In order to update these subresources, they would need to be included in your PUT request. When removing existing values for these subresources, you would need to include them in the request with blank values. Below I am including documentation on the PUT (update) a Contact request, as well as contact subresources.

 

PUT (update) a Contact:

https://developer.constantcontact.com/api_reference/index.html#!/Contacts/putContact

 

Contact Subresources:

https://developer.constantcontact.com/api_guide/contacts_subresources.html

 

If you have any further questions, please feel free to email webservices@constantcontact.com with your API key and we would be happy to look into this further.

 

Regards,


John B.
API Support Specialist
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
SegmintD
Brand Influencer
0 Votes

Thank you for the response. I have tried sending the subresources using a blank value. The API call succeeds, but no change occurs within the contact. An example of the body generated by our code:

 

class ContactPutRequest {
emailAddress: class EmailAddressPut {
address: {{{aykeLohJnTdTIh1AZSPW1gGNzgrYcbh71yXmNM1iBm2nvLn5Z5x9si}}}
permissionToSend: implicit
}
firstName: {{{NrxKAayoOX}}}
lastName: {{{yoEytn64h8BClz}}}
updateSource: Account
customFields: [class ContactCustomField {
customFieldId: 397abae4-7481-11ec-b411-fa163eaf1c42
value: {{{kUyYfv9TeomTatKrO431Mk03v1fxS1H3solfxLbfI6W3I40hMQzLFv4QR4qUDHJW}}}
}]
phoneNumbers: [class PhoneNumberPut {
phoneNumber:
kind: other
}]
listMemberships: [4df2e336-71b9-11ec-b411-fa163eaf1c42, 55953f04-73bb-11ec-b55c-fa163e470cab, 93ac28d6-7f8f-11ec-a993-fa163eaf1c42, bd3ef544-77b4-11ec-abf0-fa163ed2816c]
}

Courtney_E
Moderator
0 Votes

Hello SegmintD,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

It looks like some of the properties in your request body may not be formatted correctly, which could be preventing those fields from mapping correctly to the corresponding contact fields.  

 

Based on the values in the example you provided, I noticed these potential discrepancies:

  • "customFields" should be: "custom_fields"
  • "Custom_field_id" should be: "custom_field_id"
  • "phoneNumbers" should be: "phone_numbers"
  • "Phone_number" should be: "phone_number"

On our API Reference page, to the right of the Tester, you can find Body Samples and Body Schemas that show how the (case sensitive) properties should be formatted for each of the endpoints that are listed:

 

API Reference - PUT (update) a Contact

 https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/putContact

 

Please have a look and let us know if you have any other questions! If you’d like us to look at any additional request body examples, you can also contact our team directly and securely via email at webservices@constantcontact.com and reference case number 29446454.


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
SegmintD
Brand Influencer
0 Votes

I think that is just a discrepancy between how the body of the call logs in our program and how it reaches the actual API? We use this exact same call to update values in the contacts (for instance, updating a phone number), and it works fine. The only thing that doesn't seem to work is updating the value to be blank. Is there anything else that could be causing the issue?

 

Thank you!

Courtney_E
Moderator
0 Votes

Hello SegmintD,

 

Thank you for reaching out to Constant Contact API Developer Support. 

 

I took a look at one of the recent request bodies for one of your PUT calls to /v3/contacts/{contact_id} within our logs, which had the value for the other phone number set to blank and was not passing the properties correctly when being submitted to the API. 

 

I did some testing, and was able to replicate what you were experiencing, that when including a value with "customFields" and "phoneNumbers" those properties are updated, (but "streetAddresses" is not). 

 

28/Jan/2022 :00:04:20 (customer information redacted)

{"customFields":[{"custom_field_id":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","value":"xxxxxxxxxx"}],"phoneNumbers":[{"phone_number":"","kind":"other"}],"streetAddresses":null,"email_address":{"address":"xxxxxxxxxx","permission_to_send":"implicit","created_at":null,"updated_at":null,"opt_in_date":null,"opt_out_source":null,"opt_out_date":null,"opt_out_reason":null,"confirm_status":null},"first_name":"xxxxxxxxxx","last_name":"xxxxxxxxxx","job_title":null,"company_name":null,"birthday_month":null,"birthday_day":null,"anniversary":null,"update_source":"Account","list_memberships":["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"],"taggings":null,"notes":null}

 

However, I was also able to replicate that the “other” phone number can only be overwritten with a blank value if the naming conventions of the properties in the request body match those that are specified in the Body Schema for the Contacts endpoint in our API Documentation:

 

  "custom_fields": [

    { "custom_field_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","value": "" }

  ],

  "phone_numbers": [

    { "phone_number": "", "kind": "other"}

  ],

  "street_addresses": [

    {  "kind": "home", "street": "","city": "","state": "","postal_code": "","country": "" }

  ],

 

PUT (update) a Contact

https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/putContact

 

Please have a look and let us know if you have any other questions!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
SegmintD
Brand Influencer
0 Votes

I believe I have updated our code to use the snake_case values you indicated (though I still do not think this is the problem since our normal update calls work with our existing generated API code),  and I do not think that it solved the problem. Our existing code (and the current code) are capable of updating the value of a custom field or phone number. However we still cannot update the value to a blank value to remove the data from the contact in Constant Contact. Even though we are sending a blank value and receive a 200 response, nothing changes with the contact in ConstantContact.

John__B
Employee
0 Votes

Hello SegmintD,

 

Thank you for reaching out to Constant Contact API Developer Support. 

 

I have reviewed the request bodies of a few your most recent PUT calls to /v3/contacts/{contact_id} and found that the naming conventions for properties such as “custom_fields” and “phone_numbers” are still appearing in your original format of “customFields”and “phoneNumbers”.

 

If you could provide full examples of the recent requests you’ve sent with the updated property naming conventions, including timestamps if possible in an email to webservices@constantcontact.com we would be happy to investigate this further.    

 

Regards,


John B.
API Support Specialist
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
SegmintD
Brand Influencer
0 Votes

Thank you for the continued help! We finally got the format to the standard, and that seems to work. Why do some of our calls work with the bodies you see (e.g. using phoneNumbers and not phone_numbers), but these calls to remove a value do not? We have definitely used calls with phoneNumbers to update the value of a phone number without an issue. We only encountered this problem when we tried to remove values which seems strange and inconsistent. 

 

Thank you again!

John__B
Employee
0 Votes

Hello SegmintD,

 

Thank you for reaching out to Constant Contact API Developer Support. 

 

I’m glad to hear that you were able to properly remove the phone number and custom field values with the naming conventions outlined in our documentation. While we were able to replicate the behavior you experienced with your original naming conventions updating these properties (but not removing their values if left blank), we can only guarantee that the calls will function as expected if they are made in the format specified in our documentation.

 

Please let us know if you have any other questions!

 

Regards,


John B.
API Support Specialist
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up