I'm currently using the Javascript SDK in a React App. I need to display the list of contacts from a Contact List in a table.
I'm using loginImplicitGrant with OAuth to login, and pagekite service to get a public URL locally on my dev environment. I can successfully make several API calls but when I try to call outboundApi.getOutboundContactlistExport I get a CORS error. This is the code I'm using and I'm attaching the error message from the Chrome console as an image <the code below is called after executing outboundApi.postOutboundContactlistExport(contactListId)>:
const GetContactListContent = (platformClient, outboundApi, contactListId) => {
let opts = {
'download': "false" // String | Redirect to download uri
};
outboundApi.getOutboundContactlistExport(contactListId, opts)
.then((data) => {
// console.log(`getOutboundContactlistExport success! data: ${JSON.stringify(data, null, 2)}`);
const client = platformClient.ApiClient.instance;
var downloadUri = data.uri;
return request({
uri: downloadUri,
qs: { issueRedirect: 'false' },
headers: {
'authorization': `bearer ${client.authData.accessToken}`,
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
})
.then((res) => {
// Show downloaded file in console
var resObject = JSON.parse(res); // Contains the AWS URL
console.log(resObject);
return request({
uri: resObject.url
});
// setLoaded(true);
})
.then((res) => {
// Show downloaded file in console
console.log(res);
setLoaded(true);
})
.catch((err) => {
if (err.body && err.body.code === 'no.available.list.export.uri')
// Wait until file is available for download and try downloading again.
// For some reason the file isn't available right away. Wait 1 second and try download again
setTimeout(
function() {
GetContactListContent(platformClient, outboundApi, contactListId)
}, 1000
);
else {
console.log('There was a failure calling getOutboundContactlistExport');
console.error(err);
}
});
}
BTW, Is there an easier way to get the list of contacts from a Contact List in JSON Format?