Legacy Dev Forum Posts

 View Only

Sign Up

Read ContactList as stream

  • 1.  Read ContactList as stream

    Posted 06-05-2025 18:05

    vrvoice1 | 2017-04-25 11:26:11 UTC | #1

    Hi, I want to download the Contact list as a stream, but I got the following error message:

    <Error> <Code>InvalidArgument</Code> <Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified</Message> <ArgumentName>Authorization</ArgumentName> <ArgumentValue>bearer xxxxxxxxxxxxxx</ArgumentValue> <RequestId>xxxxxxxxx</RequestId> <HostId>xxxxxxxxxxxxxxxxxxxxxxxxx</HostId> </Error>

    I try it with the following code:

    using (var client = new HttpClient()) { var request = new HttpRequestMessage(HttpMethod.Get, "https://public-api.eu-west-1.mypurecloud.ie/api/v1/downloads/99999999");

    request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", "xxxxxxxxxxxxxx");

    var rTask = client.SendAsync(request); rTask.Wait(); var response = rTask.Result;

    var sTask = response.Content.ReadAsStreamAsync(); sTask.Wait(); var stream = sTask.Result;

    StreamReader reader = new StreamReader(stream);

    var line = reader.ReadLine();

    var st = reader.ReadToEnd(); }


    tim.smith | 2017-04-25 14:51:42 UTC | #2

    First, I've created CD-4785 to update that API resource to use the v2 download service; it's currently returning a v1 URL. The v2 download service has a fix for this that was intentionally not backported to the v1 service (technical reasons).

    To work around this until that issue is fixed, you'll need to update the URL to the v2 download service and use the ?issueRedirect=false query parameter. Here's the full process to follow:

    1. Use POST /api/v2/outbound/contactlists/{contactListId}/export to initiate the export of the contact list
    2. Use GET /api/v2/outbound/contactlists/{contactListId}/export?download=false to retrieve the download URL. The URL will look like https://public-api.us-east-1.mypurecloud.com/api/v1/downloads/b509dea4
    3. Here's the workaround: Change the URL to https://public-api-v2.us-east-1.mypurecloud.com/api/v2/downloads/b509dea4. Note the change of the server from public-api -> public-api-v2 and the change in the path from v1 -> v2.
    4. Add ?issueRedirect=false to the download URL
    5. Perform a GET request on the v2 download URL with the querystring and include the authorization header used in API requests. The URL should look like this: https://public-api-v2.us-east-1.mypurecloud.com/api/v2/downloads/b509dea4?issueRedirect=false
    6. You will get a JSON body with the schema: { "url": "" }. This URL will point to the AWS S3 bucket where the file is stored and will include an authorization token in the query string; do not pass your PureCloud authorization header with this request. You may use this URL for retrieving the contact list.

    vrvoice1 | 2017-04-26 08:09:39 UTC | #3

    Hi Tim,

    thanks. That is working fine.

    Regards,

    Sven


    Ben_Carroll | 2017-05-31 21:23:01 UTC | #4

    Hi, I used the method you explained here to download DNC Lists and it worked fine. When I initiate the download in a browser, at either the original download url or the aws bucket url, the download is initiated with a file name "DNCListId - DNCListName.csv". However, using the method above I cannot locate the file name in any response headers. What am I missing?


    tim.smith | 2017-06-01 15:40:32 UTC | #5

    The AWS URL you get in step 6 above will contain the filename in the URL; it's not contained in any header. You'll need to parse it out from there. For example, here's the AWS URL for a contact list I exported:

    https://prod-dialer.s3.amazonaws.com/contact-lists/exports/f55495cf-hbc6-4871-b59f-530ddddddddf-A%20List.csv?X-Amz-Security-Token=xxx&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=xxx&X-Amz-SignedHeaders=host&X-Amz-Expires=xxx&X-Amz-Credential=xxx&X-Amz-Signature=xxx

    The file name to find is f55495cf-hbc6-4871-b59f-530ddddddddf-A%20List.csv, and then unescape it to turn %20 into a space.


    Ben_Carroll | 2017-06-01 16:06:53 UTC | #6

    Thanks, that was it.


    system | 2017-08-28 19:34:06 UTC | #7


    This post was migrated from the old Developer Forum.

    ref: 1220