Download Contact List via .NET program

I am trying to download a contact list, using the following API calls:

https://developer.genesys.cloud/routing/outbound/#post-api-v2-outbound-contactlists--contactListId--export

and
https://developer.genesys.cloud/routing/outbound/#get-api-v2-outbound-contactlists--contactListId--export

My program is returning the correct URI for the contact list, however, when I try and download it, I'm getting an HTML file that doesn't have any useful information versus the .CSV. I copied the URI into a browser and got prompted to log in with my Genesys Cloud account and then it downloaded so that tells me that I need to pass the token in with my call but I'm stuck as to where and how to do that. I've tried many examples that I've found online, using both WebClient and HttpClient but have had no success--the same file contents gets downloaded.

Can someone please point me to a .NET example that shows what I need to do in order to pass in the token and actually download correct contents of the file?

As the notes warn;

The request headers should include the Authorization header with the same bearer token that you would use to make other API requests.

Not sure how you're trying to download it, but it's as simple as adding the necessary header to your webclient;

webClient.Headers.Add("Authorization", $"Bearer {Configuration.Default.AccessToken}");
webClient.DownloadFile(address, fileName);

or just call the internal RestClient directly to do the download via - Configuration.Default.ApiClient.RestClient;

byte[] file = Configuration.Default.ApiClient.RestClient.DownloadData(new RestRequest(url));

Here is my code to download, everything from the 2 API calls that I'm using work and to eliminate scoping issues, I have everything in one procedure as this is just a "stub" program.


 Dim myUri As New Uri(resultURI.Uri)

 Dim wc As New WebClient

        wc.Headers.Add("Authorization", "Bearer" & Configuration.Default.AccessToken)

        wc.DownloadFile(myUri, "Agentless.csv")

I'm attaching the results. I even tried calling the RestClient.Download data like you suggested and I'm still getting the attached contents.

You're missing a space between the word Bearer and the token.

That's it! It's working! Thank you and Eos_Rios!

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