Error umpload contact list

hi,
I am uploading a .cvs file to a contact list through NODE at the time of doing it generates this error

require('dotenv').config();
const axios = require('axios');
const fs = require('fs');

conten = {
    'id': "a74f5613-c7a3-4747-b89f-5e934a5dea50",
    'file': fs.readFileSync('./Contact List.csv'),
    'fileType': "contactlist",
    'contact-id-name': 'Cedula'
}
axios.post("https://apps.mypurecloud.com/uploads/v2/contactlist", conten, {
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': `bearer ${process.env.GENESYS_TOKEN}`
    }
}).then(res => {
    console.log(res.data);
}).catch(error => {
    if (error.response) {
        console.error(error.response.status);
        console.error(error.response);
    }
})

error 400

Hi,

It's hard to know exactly what the issue is without a response body. It's possible that your Content-Type and Accept headers are not necessary and are causing the issue.
You can use the Uploading Contacts to a Contact List Javascript tutorial as a reference to show how this is achieved in Javascript.

Hello,

The request's content-type must be "multipart/form-data" and the body must be encoded accordingly (i.e. FormData).
The link Ronan has mentioned above is doing this with javascript/jquery. You should check how to do the equivalent with axios.

Regards,

Hi,

But in the example it is with a browser and I have to do it with node, don't you have an example with node?

Hello,

We do not have a node example for the upload of contact list.
But you can possibly check this web page that describes how to use Axios with Multipart Form Data.

Regards,

Hello, this was the way I do it

const form = new FormData();
const token = await Token();
form.append('id', idlista);
form.append('file[]', fs.createReadStream(csv));
form.append('fileType', 'contactlist');
form.append('contact-id-name', 'cedula');
let head = form.getHeaders();
head.Authorization = 'bearer ' + token;
axios({
method: "post",
url: "https://apps.mypurecloud.com/uploads/v2/contactlist",
data: form,
headers: head
}).then(function (response) {
console.log(response.data)
}).catch(function (error) {
console.log(error)
});

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