Sample code for 30+ languages & platforms
C Requires Chilkat v11.6.0+

Amazon S3: List Objects Using a Regional Path-Style Endpoint

See more S3 - REST Examples

List current keys under a prefix using ListObjectsV2. Follow NextContinuationToken even when a page is empty. Requires s3:ListBucket. encoding-type=url makes XML-safe keys; decode once before using a returned key. Sizes and ETags remain strings. A listing is not an atomic snapshot across pages.

The bucket is in the request path and the regional service host is used for TLS. Path-style requests remain supported for general purpose buckets, including bucket names with dots. Directory buckets require different endpoints.

For general purpose S3 buckets, using regional HTTPS endpoints and AWS Signature Version 4. Directory buckets (S3 Express), access points, Outposts, and other AWS partitions need their own endpoint/authentication rules. Use a bucket name without dots for these virtual-hosted TLS examples; see the path-style example for dotted names.

Provide current IAM credentials in a private qa_data/aws/s3.json file with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This file is explicitly loaded; these examples do not discover profiles or refresh credentials. Keep it outside public content and source control. The session token is included in the signed request. TLS certificate verification is enabled on the Socket used by Rest.

Transport success and HTTP success are different. Keep full diagnostics private; signed requests and presigned URLs can contain credentials or grant access. For retryable reads use bounded backoff with jitter. Before retrying a write with an uncertain outcome, check the resource state. Keep keys, upload IDs, version IDs, ETags, and large sizes as strings.

AWS ListObjectsV2 reference

Chilkat C Downloads

C
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
#include <C_CkAuthAws.h>
#include <C_CkRest.h>
#include <C_CkSocket.h>
#include <C_CkXml.h>
#include <C_CkHashtable.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkStringBuilder textCompare;
    HCkJsonObject credentials;
    BOOL sameText1;
    BOOL sameText2;
    const char *region;
    const char *bucketName;
    HCkStringBuilder endpoint;
    HCkAuthAws aws;
    HCkRest rest;
    BOOL sameText3;
    HCkSocket connection;
    HCkXml xml;
    HCkStringBuilder bucketPath;
    HCkHashtable seenTokens;
    const char *nextToken;
    BOOL more;
    int page;
    const char *responseBody;
    BOOL sameText4;
    BOOL sameText5;
    int i;
    BOOL sameText6;
    BOOL sameText7;
    BOOL sameText8;
    HCkStringBuilder decodedKey;
    int escapedPluses;
    BOOL sameText9;
    BOOL sameText10;
    BOOL sameText11;
    BOOL sameText12;
    BOOL sameText13;
    BOOL sameText14;

    success = FALSE;

    //  StringBuilder compares text by value in every generated language.
    textCompare = CkStringBuilder_Create();
    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    success = FALSE;
    //  Private configuration, not a file in public web content or source control.
    //  Load current IAM credentials authorized for the S3 operation.
    credentials = CkJsonObject_Create();
    CkJsonObject_putStrict(credentials,TRUE);
    success = CkJsonObject_LoadFile(credentials,"qa_data/aws/s3.json");
    if (success != TRUE) {
        printf("Could not load private AWS credentials.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        return;
    }

    CkStringBuilder_Clear(textCompare);
    CkStringBuilder_SetString(textCompare,CkJsonObject_stringOf(credentials,"access_key"));
    sameText1 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
    if ((CkJsonObject_JsonTypeOf(credentials,"access_key") != 1) || (sameText1 == TRUE)) {
        printf("Missing or invalid access_key.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        return;
    }

    CkStringBuilder_Clear(textCompare);
    CkStringBuilder_SetString(textCompare,CkJsonObject_stringOf(credentials,"secret_key"));
    sameText2 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
    if ((CkJsonObject_JsonTypeOf(credentials,"secret_key") != 1) || (sameText2 == TRUE)) {
        printf("Missing or invalid secret_key.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        return;
    }

    //  General purpose bucket in the commercial AWS partition.
    region = "us-west-2";
    bucketName = "amzn-s3-demo-bucket";
    endpoint = CkStringBuilder_Create();
    success = CkStringBuilder_Append(endpoint,"s3.");
    if (success != TRUE) {
        printf("Could not build text.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        return;
    }

    success = CkStringBuilder_Append(endpoint,region);
    if (success != TRUE) {
        printf("Could not build text.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        return;
    }

    success = CkStringBuilder_Append(endpoint,".amazonaws.com");
    if (success != TRUE) {
        printf("Could not build text.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        return;
    }

    aws = CkAuthAws_Create();
    CkAuthAws_putAccessKey(aws,CkJsonObject_stringOf(credentials,"access_key"));
    CkAuthAws_putSecretKey(aws,CkJsonObject_stringOf(credentials,"secret_key"));
    CkAuthAws_putRegion(aws,region);
    CkAuthAws_putServiceName(aws,"s3");
    CkAuthAws_putSignatureVersion(aws,4);
    rest = CkRest_Create();
    CkRest_putConnectTimeoutMs(rest,20000);
    CkRest_putIdleTimeoutMs(rest,60000);
    success = CkRest_SetAuthAws(rest,aws);
    if (success != TRUE) {
        printf("Could not configure AWS signing.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        return;
    }

    //  Temporary credentials require this token in every signed query.
    //  Keep request URLs private. Do not clear this parameter between requests.
    if (CkJsonObject_HasMember(credentials,"session_token") == TRUE) {
        if (CkJsonObject_JsonTypeOf(credentials,"session_token") != 1) {
            printf("session_token must be a string.\n");
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            return;
        }

        CkStringBuilder_Clear(textCompare);
        CkStringBuilder_SetString(textCompare,CkJsonObject_stringOf(credentials,"session_token"));
        sameText3 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
        if (sameText3 != TRUE) {
            success = CkRest_AddQueryParam(rest,"X-Amz-Security-Token",CkJsonObject_stringOf(credentials,"session_token"));
            if (success != TRUE) {
                printf("Could not prepare the request.\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                return;
            }

        }

    }

    //  Connect to the SAME hostname used for TLS verification and request signing.
    connection = CkSocket_Create();
    CkSocket_putRequireSslCertVerify(connection,TRUE);
    CkSocket_putMaxReadIdleMs(connection,60000);
    CkSocket_putMaxSendIdleMs(connection,60000);
    success = CkSocket_Connect(connection,CkStringBuilder_getAsString(endpoint),443,TRUE,20000);
    if (success != TRUE) {
        printf("TLS connection failed; inspect diagnostics privately.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        return;
    }

    success = CkRest_UseConnection(rest,connection,TRUE);
    if (success != TRUE) {
        printf("Could not attach the TLS connection.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        return;
    }

    xml = CkXml_Create();
    CkXml_putStrict(xml,TRUE);
    bucketPath = CkStringBuilder_Create();
    success = CkStringBuilder_Append(bucketPath,"/");
    if (success != TRUE) {
        printf("Could not build text.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        CkXml_Dispose(xml);
        CkStringBuilder_Dispose(bucketPath);
        return;
    }

    success = CkStringBuilder_Append(bucketPath,bucketName);
    if (success != TRUE) {
        printf("Could not build text.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        CkXml_Dispose(xml);
        CkStringBuilder_Dispose(bucketPath);
        return;
    }

    success = CkRest_AddQueryParam(rest,"list-type","2");
    if (success != TRUE) {
        printf("Could not prepare the request.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        CkXml_Dispose(xml);
        CkStringBuilder_Dispose(bucketPath);
        return;
    }

    success = CkRest_AddQueryParam(rest,"max-keys","1000");
    if (success != TRUE) {
        printf("Could not prepare the request.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        CkXml_Dispose(xml);
        CkStringBuilder_Dispose(bucketPath);
        return;
    }

    success = CkRest_AddQueryParam(rest,"encoding-type","url");
    if (success != TRUE) {
        printf("Could not prepare the request.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        CkXml_Dispose(xml);
        CkStringBuilder_Dispose(bucketPath);
        return;
    }

    //  Optional prefix filter; a slash is part of an object key, not a real folder.
    success = CkRest_AddQueryParam(rest,"prefix","documents/");
    if (success != TRUE) {
        printf("Could not prepare the request.\n");
        CkStringBuilder_Dispose(textCompare);
        CkJsonObject_Dispose(credentials);
        CkStringBuilder_Dispose(endpoint);
        CkAuthAws_Dispose(aws);
        CkRest_Dispose(rest);
        CkSocket_Dispose(connection);
        CkXml_Dispose(xml);
        CkStringBuilder_Dispose(bucketPath);
        return;
    }

    seenTokens = CkHashtable_Create();
    nextToken = "";
    more = TRUE;
    page = 0;
    while ((more == TRUE)) {
        if (page == 1000) {
            printf("Page limit reached; enumeration is incomplete.\n");
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            CkSocket_Dispose(connection);
            CkXml_Dispose(xml);
            CkStringBuilder_Dispose(bucketPath);
            CkHashtable_Dispose(seenTokens);
            return;
        }

        responseBody = CkRest_fullRequestNoBody(rest,"GET",CkStringBuilder_getAsString(bucketPath));
        if (CkRest_getLastMethodSuccess(rest) != TRUE) {
            printf("Request did not complete; inspect diagnostics privately.\n");
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            CkSocket_Dispose(connection);
            CkXml_Dispose(xml);
            CkStringBuilder_Dispose(bucketPath);
            CkHashtable_Dispose(seenTokens);
            return;
        }

        if (CkRest_getResponseStatusCode(rest) != 200) {
            printf("S3 HTTP status: %d\n",CkRest_getResponseStatusCode(rest));
            success = CkXml_LoadXml(xml,responseBody);
            CkStringBuilder_Clear(textCompare);
            CkStringBuilder_SetString(textCompare,CkXml_tag(xml));
            sameText4 = CkStringBuilder_ContentsEqual(textCompare,"Error",TRUE);
            if ((success == TRUE) && (sameText4 == TRUE)) {
                printf("S3 error code: %s\n",CkXml_getChildContent(xml,"Code"));
            }

            //  Keep signed headers, credentials, URLs, and full diagnostics private.
            //  A timeout may leave a write's outcome uncertain. Check before retrying.
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            CkSocket_Dispose(connection);
            CkXml_Dispose(xml);
            CkStringBuilder_Dispose(bucketPath);
            CkHashtable_Dispose(seenTokens);
            return;
        }

        success = CkXml_LoadXml(xml,responseBody);
        if (success != TRUE) {
            printf("Expected well-formed XML.\n");
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            CkSocket_Dispose(connection);
            CkXml_Dispose(xml);
            CkStringBuilder_Dispose(bucketPath);
            CkHashtable_Dispose(seenTokens);
            return;
        }

        CkStringBuilder_Clear(textCompare);
        CkStringBuilder_SetString(textCompare,CkXml_tag(xml));
        sameText5 = CkStringBuilder_ContentsEqual(textCompare,"ListBucketResult",TRUE);
        if (sameText5 != TRUE) {
            printf("Unexpected S3 response element; this is not a successful result.\n");
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            CkSocket_Dispose(connection);
            CkXml_Dispose(xml);
            CkStringBuilder_Dispose(bucketPath);
            CkHashtable_Dispose(seenTokens);
            return;
        }

        i = 0;
        while ((i < CkXml_NumChildrenHavingTag(xml,"Contents"))) {
            CkXml_putI(xml,i);
            CkStringBuilder_Clear(textCompare);
            CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"Contents[i]|Key"));
            sameText6 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
            if ((CkXml_HasChildWithTag(xml,"Contents[i]|Key") != TRUE) || (sameText6 == TRUE)) {
                printf("Missing response field: Contents[i]|Key\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                return;
            }

            printf("Encoded key: %s\n",CkXml_getChildContent(xml,"Contents[i]|Key"));
            CkStringBuilder_Clear(textCompare);
            CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"Contents[i]|Size"));
            sameText7 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
            if ((CkXml_HasChildWithTag(xml,"Contents[i]|Size") != TRUE) || (sameText7 == TRUE)) {
                printf("Missing response field: Contents[i]|Size\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                return;
            }

            printf("Size: %s\n",CkXml_getChildContent(xml,"Contents[i]|Size"));
            CkStringBuilder_Clear(textCompare);
            CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"Contents[i]|ETag"));
            sameText8 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
            if ((CkXml_HasChildWithTag(xml,"Contents[i]|ETag") != TRUE) || (sameText8 == TRUE)) {
                printf("Missing response field: Contents[i]|ETag\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                return;
            }

            printf("ETag: %s\n",CkXml_getChildContent(xml,"Contents[i]|ETag"));
            //  Decode percent escapes without interpreting a literal plus as a space.
            decodedKey = CkStringBuilder_Create();
            success = CkStringBuilder_Append(decodedKey,CkXml_getChildContent(xml,"Contents[i]|Key"));
            if (success != TRUE) {
                printf("Could not prepare the request.\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                CkStringBuilder_Dispose(decodedKey);
                return;
            }

            escapedPluses = CkStringBuilder_Replace(decodedKey,"+","%2B");
            success = CkStringBuilder_Decode(decodedKey,"url","utf-8");
            if (success != TRUE) {
                printf("Could not decode object key.\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                CkStringBuilder_Dispose(decodedKey);
                return;
            }

            printf("Key: %s\n",CkStringBuilder_getAsString(decodedKey));
            i = i + 1;
        }

        page = page + 1;
        more = FALSE;
        nextToken = "";
        CkStringBuilder_Clear(textCompare);
        CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"IsTruncated"));
        sameText9 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
        if ((CkXml_HasChildWithTag(xml,"IsTruncated") != TRUE) || (sameText9 == TRUE)) {
            printf("Missing response field: IsTruncated\n");
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            CkSocket_Dispose(connection);
            CkXml_Dispose(xml);
            CkStringBuilder_Dispose(bucketPath);
            CkHashtable_Dispose(seenTokens);
            CkStringBuilder_Dispose(decodedKey);
            return;
        }

        CkStringBuilder_Clear(textCompare);
        CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"IsTruncated"));
        sameText10 = CkStringBuilder_ContentsEqual(textCompare,"true",TRUE);
        CkStringBuilder_Clear(textCompare);
        CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"IsTruncated"));
        sameText11 = CkStringBuilder_ContentsEqual(textCompare,"false",TRUE);
        if ((sameText10 != TRUE) && (sameText11 != TRUE)) {
            printf("Invalid IsTruncated value.\n");
            CkStringBuilder_Dispose(textCompare);
            CkJsonObject_Dispose(credentials);
            CkStringBuilder_Dispose(endpoint);
            CkAuthAws_Dispose(aws);
            CkRest_Dispose(rest);
            CkSocket_Dispose(connection);
            CkXml_Dispose(xml);
            CkStringBuilder_Dispose(bucketPath);
            CkHashtable_Dispose(seenTokens);
            CkStringBuilder_Dispose(decodedKey);
            return;
        }

        CkStringBuilder_Clear(textCompare);
        CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"IsTruncated"));
        sameText12 = CkStringBuilder_ContentsEqual(textCompare,"true",TRUE);
        if (sameText12 == TRUE) {
            CkStringBuilder_Clear(textCompare);
            CkStringBuilder_SetString(textCompare,CkXml_getChildContent(xml,"NextContinuationToken"));
            sameText13 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
            if ((CkXml_HasChildWithTag(xml,"NextContinuationToken") != TRUE) || (sameText13 == TRUE)) {
                printf("Missing response field: NextContinuationToken\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                CkStringBuilder_Dispose(decodedKey);
                return;
            }

            nextToken = CkXml_getChildContent(xml,"NextContinuationToken");
        }

        CkStringBuilder_Clear(textCompare);
        CkStringBuilder_SetString(textCompare,nextToken);
        sameText14 = CkStringBuilder_ContentsEqual(textCompare,"",TRUE);
        if (sameText14 != TRUE) {
            if (CkHashtable_Contains(seenTokens,nextToken) == TRUE) {
                printf("Repeated pagination token; enumeration is incomplete.\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                CkStringBuilder_Dispose(decodedKey);
                return;
            }

            success = CkHashtable_AddInt(seenTokens,nextToken,1);
            if (success != TRUE) {
                printf("Could not track pagination.\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                CkStringBuilder_Dispose(decodedKey);
                return;
            }

            if (page > 1) {
                success = CkRest_RemoveQueryParam(rest,"continuation-token");
                if (success != TRUE) {
                    printf("Could not prepare the request.\n");
                    CkStringBuilder_Dispose(textCompare);
                    CkJsonObject_Dispose(credentials);
                    CkStringBuilder_Dispose(endpoint);
                    CkAuthAws_Dispose(aws);
                    CkRest_Dispose(rest);
                    CkSocket_Dispose(connection);
                    CkXml_Dispose(xml);
                    CkStringBuilder_Dispose(bucketPath);
                    CkHashtable_Dispose(seenTokens);
                    CkStringBuilder_Dispose(decodedKey);
                    return;
                }

            }

            success = CkRest_AddQueryParam(rest,"continuation-token",nextToken);
            if (success != TRUE) {
                printf("Could not prepare the request.\n");
                CkStringBuilder_Dispose(textCompare);
                CkJsonObject_Dispose(credentials);
                CkStringBuilder_Dispose(endpoint);
                CkAuthAws_Dispose(aws);
                CkRest_Dispose(rest);
                CkSocket_Dispose(connection);
                CkXml_Dispose(xml);
                CkStringBuilder_Dispose(bucketPath);
                CkHashtable_Dispose(seenTokens);
                CkStringBuilder_Dispose(decodedKey);
                return;
            }

            more = TRUE;
        }

    }

    printf("Enumeration complete.\n");


    CkStringBuilder_Dispose(textCompare);
    CkJsonObject_Dispose(credentials);
    CkStringBuilder_Dispose(endpoint);
    CkAuthAws_Dispose(aws);
    CkRest_Dispose(rest);
    CkSocket_Dispose(connection);
    CkXml_Dispose(xml);
    CkStringBuilder_Dispose(bucketPath);
    CkHashtable_Dispose(seenTokens);
    CkStringBuilder_Dispose(decodedKey);

    }