400 Bad Request api_instance.post_outbound_contactlist_contacts

Trying to add contacts to an existing contact list. I'm unable to have a successful post. Any thoughts?

My error:

Exception when calling OutboundApi->post_outbound_contactlist_contacts: (400)
Reason: Bad Request

HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '317', 'Connection': 'keep-alive', 'Date': 'Wed, 10 Jan 2024 22:37:18 GMT', 'ININ-Correlation-Id': 'd36eddb4-adeb-4ea6-a1e4-08a95ed14adf', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 2ac244f3035dac54badc413a33e6e00c.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'CMH68-P5', 'X-Amz-Cf-Id': 'KiONTCXS8yvuK4tAtzqtkxIKd2bsRAaffgwbvMBx1wSX2FjCMls8zQ=='})

HTTP response body: {"message":"The contact columns do not match what is required in the list","code":"invalid.contact.columns","status":400,"messageWithParams":"The contact columns do not match what is required in the list","messageParams":{"columnName":"[]"},"contextId":"d36eddb4-adeb-4ea6-a1e4-08a95ed14adf","details":[],"errors":[]}

Process finished with exit code 0

My column headers do match the contact list headers, and I've had success trying using the API explorer.

"data": {
"first_name": "Bandy",
"last_name": "Zztest",
"phone_best": "15555551212",
"time_zone": "America/New_York"
},

Can someone provide an example of a successful post body for these column headers and dummy values? I keep hitting the above "bad request" response no matter how I format.

"first_name": "Bandy",
"last_name": "Zztest",
"phone_best": "15555551212",
"time_zone": "America/New_York"

Make sure you're sending exactly the fields in the list. This message indicates you've made an error somewhere. If you are absolutely sure you haven't made any mistakes, please open a case with Genesys Cloud Care to report this as a bug.

Ahh, so not only the 4 columns I want to populate but all 19 column headers even if they will be blank values? My original import only contained the 4 columns, however when I export there are 19 or so. Still not having any luck.

Does anyone have a code example of a successful post using Python? I continue to receive the "The contact columns do not match what is required in the list" error. Thanks!

Using the developer tools, you can get code examples in all SDK languages: https://developer.genesys.cloud/devapps/api-explorer

Here is for python

import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException
from pprint import pprint

# Configure OAuth2 access token for authorization: PureCloud OAuth
PureCloudPlatformClientV2.configuration.access_token = 'your_access_token'
# or use get_client_credentials_token(...), get_saml2bearer_token(...), get_code_authorization_token(...) or get_pkce_token(...)

# create an instance of the API class
api_instance = PureCloudPlatformClientV2.OutboundApi();
contact_list_id = 'contact_list_id_example' # str | Contact List ID
body = [PureCloudPlatformClientV2.WritableDialerContact()] # list[WritableDialerContact] | Contact
priority = True # bool | Contact priority. True means the contact(s) will be dialed next; false means the contact will go to the end of the contact queue. (optional)
clear_system_data = True # bool | Clear system data. True means the system columns (attempts, callable status, etc) stored on the contact will be cleared if the contact already exists; false means they won't. (optional)
do_not_queue = True # bool | Do not queue. True means that updated contacts will not have their positions in the queue altered, so contacts that have already been dialed will not be redialed. For new contacts, this parameter has no effect; False means that updated contacts will be re-queued, according to the 'priority' parameter. (optional)

try:
    # Add contacts to a contact list.
    api_response = api_instance.post_outbound_contactlist_contacts(contact_list_id, body, priority=priority, clear_system_data=clear_system_data, do_not_queue=do_not_queue)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling OutboundApi->post_outbound_contactlist_contacts: %s\n" % e)

Alex Johnson achieve cx

Yes, that's what I based my code off of, the issue is I've not been able to have a successful post to this particular API. It would be great if someone out there is using this API, to see what a successfully formatted code looks like. Everything works fine from the API explorer. I'm just trying to add a contact to an existing list with 4 basic columns as a POC.

"first_name": "Mason",
"last_name": "Zztest",
"phone_best": "15555551215",
"time_zone": "America/New_York"

Did you try posting for all columns? One way to ensure you have the list right is to do a query a contact and use all the columns returned.

Alex Johnson achieve cx

Here's what I get back:

{
"id": "fe95e75562b182e78b5469e1d75233b7",
"contactListId": "b1b2529b-ecee-473d-8ad5-32a5a239c09e",
"data": {
"first_name": "Bob",
"last_name": "Boberson",
"phone_best": "15555551212",
"time_zone": "America/New_York"
},
"callable": true,
"phoneNumberStatus": {
"phone_best": {
"callable": true
}
},
"contactableStatus": {
"Email": {
"contactable": true
}
},
"dateCreated": "2023-09-22T19:36:38.626Z",
"selfUri": "/api/v2/outbound/contactlists/b1b2529b-ecee-473d-8ad5-32a5a239c09e/contacts/fe95e75562b182e78b5469e1d75233b7"
}

If I take that contact query and try to post this as a new contact:

{
"id":"",
"contactListId": "b1b2529b-ecee-473d-8ad5-32a5a239c09e",
"data": {
"first_name": "New",
"last_name": "Zztest",
"phone_best": "15555551212",
"time_zone": "America/New_York"
},
"callable": "1",
"phoneNumberStatus": {
"phone_best": {
"callable": "1"
}
},
"contactableStatus": {
"Email": {
"contactable": "1"
}
},
"dateCreated": "",
"selfUri": ""
}

I get this:

Exception when calling OutboundApi->post_outbound_contactlist_contacts: (400)
Reason: Bad Request

HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '317', 'Connection': 'keep-alive', 'Date': 'Mon, 15 Jan 2024 18:39:02 GMT', 'ININ-Correlation-Id': 'f0b99a89-ebd4-41bb-9a43-c1a92dc51175', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 eb377f5086ebfe1cf72cecf255a055ac.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'CMH68-P1', 'X-Amz-Cf-Id': 'Rm6P8K4kdl9caPcRsOlblhvGbBPIz4LN4-b-b-ver9sWv1r6BSy9XQ=='})

HTTP response body: {"message":"The contact columns do not match what is required in the list","code":"invalid.contact.columns","status":400,"messageWithParams":"The contact columns do not match what is required in the list","messageParams":{"columnName":"[]"},"contextId":"f0b99a89-ebd4-41bb-9a43-c1a92dc51175","details":[],"errors":[]}

Process finished with exit code 0

That does seem odd because the error shows that the missing "columnName" with a value of [] so it would indicate there was some sort of issues with the python Client SDK.

Alex Johnson achieve cx

I guess this API just doesn't work with Python then.

Hi Marcus,

Can you please open a Care Case and reference this post. Once you get a Case number, I will make sure it gets routed to the SDK team for further investigation. In the meantime, I would recommend you just call the API directly until we get this sorted out.

Thanks,
John Carnell
Director, Developer Engagement

Hi Marcus,

Would you be able to show your code, specifically where you're creating the body and setting the values on it. It's difficult to know what's happening with seeing the code.

Regards,
Declan

Hello,

This is just a guess.
I think your problem may come from the way you create the body (in python) for your POST request (to add new contacts to a calling list).

Have you declared your body like this?: body = [PureCloudPlatformClientV2.WritableDialerContact()]
And then adding the contact you wanted to that list (body.append(new_contact)).
If so, it could be the reason why you are having an issue with this endpoint.

If you did this, the list will in fact contain 2 elements (one empty contact, and the one you have added to the list in your code).
And that's this first empty contact which is making the request fail.

I created a calling list with the same four columns.
And I could add a contact with this code:

contact_list_id = 'THE CALLING LIST ID'
body = []
new_contact = PureCloudPlatformClientV2.WritableDialerContact()
new_contact.contact_list_id = contact_list_id
new_contact.data = {}
new_contact.data['first_name'] = 'MyFirstName'
new_contact.data['last_name'] = 'MyLastName'
new_contact.data['phone_best'] = '15555551216'
new_contact.data['time_zone'] = 'America/New_York'
new_contact.callable = True
new_contact.phone_number_status = {}
new_contact.phone_number_status['phone_best'] = PureCloudPlatformClientV2.PhoneNumberStatus()
new_contact.phone_number_status['phone_best'].callable = True
new_contact.contactable_status = {}
new_contact.contactable_status['Email'] = PureCloudPlatformClientV2.ContactableStatus()
new_contact.contactable_status['Email'].contactable = True
body.append(new_contact);
api_response = outboundApi.post_outbound_contactlist_contacts(contact_list_id, body)

In case you need to check what is sent in requests bodies or received in responses bodies, please note that you can enable logging in the Platform API Python SDK. See here

Hope this helps.

Regards,

@Jerome.Saint-Marc, ISSUE SOLVED you asked: " Have you declared your body like this?: `body = [PureCloudPlatformClientV2.WritableDialerContact()]?" My answer is YES.

I did not have "body = []" in my code either. I just pasted your entire code in and ran it, the last line errored out so I deleted it and used the example api response line form the API explorer Python example and that resolved the error.

For anyone else encountering issues, here's the entire functioning code as I'm running it now, you will need to insert your own values as applicable to your org for these 4 lines:
GENESYS_CLOUD_CLIENT_ID = xxxxx
GENESYS_CLOUD_CLIENT_SECRET = xxxxx
PureCloudPlatformClientV2.configuration.host = xxxxx
contact_list_id = xxxxx

Here's the code: (Keep in mind your column headers could be different in name and in total # of columns)

import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException
from pprint import pprint
import requests
import os

print("-------------------------------------------------")
print("- Contact List Contact Update -")
print("-------------------------------------------------")

GENESYS_CLOUD_CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxx'
GENESYS_CLOUD_CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'

PureCloudPlatformClientV2.configuration.host = 'https://api.{insert your AWS region}.pure.cloud'

apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(GENESYS_CLOUD_CLIENT_ID,
GENESYS_CLOUD_CLIENT_SECRET)

api_instance = PureCloudPlatformClientV2.OutboundApi(apiclient);
contact_list_id = 'xxxxxxxxxxxxxxxxxxxxxx'

body = []
new_contact = PureCloudPlatformClientV2.WritableDialerContact()
new_contact.contact_list_id = contact_list_id
new_contact.data = {}
new_contact.data['first_name'] = 'MyFirstName'
new_contact.data['last_name'] = 'MyLastName'
new_contact.data['phone_best'] = '15555551216'
new_contact.data['time_zone'] = 'America/New_York'
new_contact.callable = True
new_contact.phone_number_status = {}
new_contact.phone_number_status['phone_best'] = PureCloudPlatformClientV2.PhoneNumberStatus()
new_contact.phone_number_status['phone_best'].callable = True
new_contact.contactable_status = {}
new_contact.contactable_status['Email'] = PureCloudPlatformClientV2.ContactableStatus()
new_contact.contactable_status['Email'].contactable = True
body.append(new_contact);

priority = True
clear_system_data = True
do_not_queue = True

try:
api_response = api_instance.post_outbound_contactlist_contacts(contact_list_id, body, priority=priority, clear_system_data=clear_system_data, do_not_queue=do_not_queue)
pprint(api_response)
except ApiException as e:
print("Exception when calling OutboundApi->post_outbound_contactlist_contacts: %s\n" % e)

It is because I didn't use api_instance in my code as a variable name.
I had defined: outboundApi = PureCloudPlatformClientV2.OutboundApi(apiclient);
Sorry I didn't include that part of the code in my answer.

Regards,

Hi Marcus,

Glad we were able to help you figure out.

Thanks,
John Carnell
Director, Developer Engagement

Thank you all for jumping in and helping me out!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.