Uploads/v2/contactlist / 400 (Bad Request)

Hello, I am trying to upload a csv file in a contact list, with exactly the same method that appears in the following link:

https://developer.mypurecloud.com/api/tutorials/upload-contacts/#javascript

But I get 400 Bad Request error. In case I wanted to see if you can help me solve this problem.

This is the Code that I am doing:

<html>
<head>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
    <script src='https://code.jquery.com/jquery-1.11.3.min.js'></script>
    <script src="https://sdk-cdn.mypurecloud.com/javascript/0.88.8/purecloud-api.min.js"></script>

    <script>
        var contactListId, authToken;
        var redirectUrl = "http://localhost/GestorCampaing/index.html";
        var pureCloudSession = purecloud.platform.PureCloudSession({
              strategy: 'implicit',
              clientId: '201d445c-609e-4ffa-afaa-070706a16a13',
              redirectUrl: "http://localhost/GestorCampaing/index.html"
            });

        pureCloudSession.login().then(function () {
            authToken = pureCloudSession.options.token;

            var outboundApi = new purecloud.platform.OutboundApi(pureCloudSession);
            outboundApi.getContactlists(false, false, 100, 1)
                .then(function (response) {
                    response.entities.forEach(function(contactList) {
                        $("#contactLists").append($("<option></option>")
                            .attr("value", contactList.id)
                            .text(contactList.name));
                    });
                });
        });

        function uploadContacts(file) {
            var contactListId = $("#contactLists").find(":selected").val();
            console.log("contactListId: " + contactListId);
            var data = new FormData();
            data.append('id', contactListId);
            data.append('file', file);
            data.append('fileType', 'contactlist');
            data.append('contact-id-name', 'Contact ID');

            $.ajax({
                url: 'https://apps.mypurecloud.com/uploads/v2/contactlist',
                type: 'POST',
                headers: {
                    Authorization: 'bearer ' + authToken
                },
                //data: data,
                processData: false,
                contentType: false,
                success: function(data, textStatus, jqXHR) {
                    console.log("UPLOAD SUCCESS");
                    $("body").append('<p>UPLOAD SUCCESS</p>');
                    console.log(data);
                    console.log(textStatus);
                    console.log(jqXHR);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.log("UPLOAD FAILURE");
                    $("body").append('<p>UPLOAD FAILURE</p>');
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        }

        $('document').ready(function () {
            $('#file-input').change(function (event) {
                uploadContacts(event.target.files[0]);
            });
        });
    </script>
</head>

<body>
    Contact Lists: <select id="contactLists"></select><br />
    Choose file to upload: <input type="file" id="file-input" />
</body>
</html>

What API request are you getting the error from? Please provide the correlation ID from the response.

I do not get ID, in is the method,

 var contactListId = $("#contactLists").find(":selected").val();
            console.log("contactListId: " + contactListId);
            var data = new FormData();
            data.append('id', contactListId);
            data.append('file', file);
            data.append('fileType', 'contactlist');
            data.append('contact-id-name', 'Contact ID');

            $.ajax({
                url: 'https://apps.mypurecloud.com/uploads/v2/contactlist',
                type: 'POST',
                headers: {
                    Authorization: 'bearer ' + authToken
                },
                //data: data,
                processData: false,
                contentType: false,
                success: function(data, textStatus, jqXHR) {
                    console.log("UPLOAD SUCCESS");
                    $("body").append('<p>UPLOAD SUCCESS</p>');
                    console.log(data);
                    console.log(textStatus);
                    console.log(jqXHR);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.log("UPLOAD FAILURE");
                    $("body").append('<p>UPLOAD FAILURE</p>');
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });

I received the 400 Bad Request error

<image redacted, please don't post auth tokens publicly>

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