Legacy Dev Forum Posts

 View Only

Sign Up

HTTP status codes 415 with contact list create

  • 1.  HTTP status codes 415 with contact list create

    Posted 06-05-2025 18:08

    fingersfive | 2017-06-20 13:35:40 UTC | #1

    Hi PureCloud team

    I am trying to use python to create a new contact list.

    I am using oauth example here: https://developer.mypurecloud.com/api/tutorials/oauth-client-credentials/#python

    Contact list https://developer.mypurecloud.com/api/rest/v2/outbound/index.html#postOutboundContactlists

    I am using the code below, and the following is the output: Failure: 415 - Unsupported Media Type

    import base64, requests, sys, json

    clientId = ' ' clientSecret = ' ' authorization = base64.b64encode(clientId + ':' + clientSecret)

    requestHeaders = { _ 'Authorization': 'Basic ' + authorization,_ _ 'Content-Type': 'application/x-www-form-urlencoded'_ } requestBody = { _ 'granttype': 'clientcredentials'_ }

    response = requests.post('https://login.mypurecloud.com.au/oauth/token', data=requestBody, headers=requestHeaders)

    if response.statuscode == 200:_ _ print 'Got token'_ else: _ print 'Failure: ' + str(response.statuscode) + ' - ' + response.reason _ sys.exit(response.statuscode)

    responseJson = response.json()

    requestHeaders = { _ 'Authorization': responseJson['tokentype'] + ' ' + responseJson['accesstoken']}_

    requestBody = {"name": "My Contact List","columnNames": [ _ "First Name"_ _ "Last Name",_ _ "Home",_ _ "Work",_ _ "Contact ID"_ _ ]_ _ ,_ _ "phoneColumns": [_ _ { "columnName": "Cell", type: "cell"},_ _ { "columnName": "Home", type: "home"}_ _ ]_ _ } _

    response = requests.post('https://api.mypurecloud.com.au/api/v2/outbound/contactlists', data=requestBody, headers=requestHeaders)

    if response.statuscode == 200:_ _ print 'All good'_ else: _ print 'Failure: ' + str(response.statuscode) + ' - ' + response.reason _ sys.exit(response.statuscode)

    It would be great if you could provide some assistance.

    Many thanks Tim


    tim.smith | 2017-06-20 21:56:52 UTC | #2

    It doesn't appear that you're using the Python SDK. I'm not sure what's wrong with your manual request, but this request using the Python SDK is working correctly. Give this a try:

    # import SDK
    import PureCloudPlatformClientV2
    
    # (do the client credentials login here)
    
    # Set host
    PureCloudPlatformClientV2.configuration.host = 'https://api.mypurecloud.com.au'
    
    # Set access token
    PureCloudPlatformClientV2.configuration.access_token = responseJson['access_token']
    
    # Build request
    api_instance = PureCloudPlatformClientV2.OutboundApi()
    body = PureCloudPlatformClientV2.ContactList() # ContactList | ContactList
    body.name = "My Contact List"
    body.column_names = [ "First Name", "Last Name", "Home", "Cell", "Contact ID" ]
    body.phone_columns = []
    col1 = PureCloudPlatformClientV2.ContactPhoneNumberColumn()
    col1.column_name = "Cell"
    col1.type = "cell"
    body.phone_columns.append(col1)
    col2 = PureCloudPlatformClientV2.ContactPhoneNumberColumn()
    col2.column_name = "Home"
    col2.type = "home"
    body.phone_columns.append(col2)
    
    try:
        # Create a contact List.
        api_response = api_instance.post_outbound_contactlists(body)
        print "Created contact list " + api_response.name
    except Exception as e:
        print "Exception when calling OutboundApi->post_outbound_contactlists: %s\n" % e

    fingersfive | 2017-06-21 10:11:34 UTC | #3

    Thanks Tim - works perfectly!


    system | 2017-07-22 10:11:48 UTC | #4

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


    This post was migrated from the old Developer Forum.

    ref: 1436