Chilkat Online Tools

DescribeActivities C++ Example

Amazon WorkDocs

#include <CkRest.h>
#include <CkAuthAws.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRest rest;
    bool success;

    CkAuthAws authAws;
    authAws.put_AccessKey("AWS_ACCESS_KEY");
    authAws.put_SecretKey("AWS_SECRET_KEY");

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.put_Region("us-west-2");
    authAws.put_ServiceName("workdocs");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://workdocs.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("workdocs.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    rest.AddHeader("Content-Type","application/x-amz-json-1.1");
    rest.AddHeader("X-Amz-Target","DescribeActivities");

    CkStringBuilder sbResponseBody;
    success = rest.FullRequestNoBodySb("GET","/api/v1/activities",sbResponseBody);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    std::cout << "response status code = " << respStatusCode << "\r\n";
    if (respStatusCode != 200) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << rest.responseHeader() << "\r\n";
        std::cout << "Response Body:" << "\r\n";
        std::cout << sbResponseBody.getAsString() << "\r\n";
        return;
    }

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const char *CommentId = 0;
    const char *CommentStatus = 0;
    int CreatedTimestamp;
    const char *EmailAddress = 0;
    const char *GivenName = 0;
    const char *Id = 0;
    const char *Locale = 0;
    int ModifiedTimestamp;
    const char *OrganizationId = 0;
    const char *RecycleBinFolderId = 0;
    const char *RootFolderId = 0;
    const char *Status = 0;
    int StorageAllocatedInBytes;
    const char *StorageType = 0;
    int StorageUtilizedInBytes;
    const char *Surname = 0;
    const char *TimeZoneId = 0;
    const char *v_Type = 0;
    const char *Username = 0;
    int CommentMetadataCreatedTimestamp;
    const char *RecipientId = 0;
    const char *InitiatorEmailAddress = 0;
    const char *InitiatorGivenName = 0;
    const char *InitiatorId = 0;
    const char *InitiatorSurname = 0;
    const char *InitiatorUsername = 0;
    int IsIndirectActivity;
    const char *OriginalParentId = 0;
    const char *Name = 0;
    const char *OriginalName = 0;
    const char *OwnerEmailAddress = 0;
    const char *OwnerGivenName = 0;
    const char *OwnerId = 0;
    const char *OwnerSurname = 0;
    const char *OwnerUsername = 0;
    const char *ParentId = 0;
    const char *OriginalParentType = 0;
    const char *VersionId = 0;
    const char *ResourceMetadataId = 0;
    const char *ResourceMetadataName = 0;
    const char *ResourceMetadataOriginalName = 0;
    const char *ResourceMetadataParentId = 0;
    const char *ResourceMetadataType = 0;
    const char *ResourceMetadataVersionId = 0;
    int TimeStamp;
    int j;
    int count_j;

    const char *Marker = jResp.stringOf("Marker");
    int i = 0;
    int count_i = jResp.SizeOfArray("UserActivities");
    while (i < count_i) {
        jResp.put_I(i);
        CommentId = jResp.stringOf("UserActivities[i].CommentMetadata.CommentId");
        CommentStatus = jResp.stringOf("UserActivities[i].CommentMetadata.CommentStatus");
        CreatedTimestamp = jResp.IntOf("UserActivities[i].CommentMetadata.Contributor.CreatedTimestamp");
        EmailAddress = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.EmailAddress");
        GivenName = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.GivenName");
        Id = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.Id");
        Locale = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.Locale");
        ModifiedTimestamp = jResp.IntOf("UserActivities[i].CommentMetadata.Contributor.ModifiedTimestamp");
        OrganizationId = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.OrganizationId");
        RecycleBinFolderId = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.RecycleBinFolderId");
        RootFolderId = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.RootFolderId");
        Status = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.Status");
        StorageAllocatedInBytes = jResp.IntOf("UserActivities[i].CommentMetadata.Contributor.Storage.StorageRule.StorageAllocatedInBytes");
        StorageType = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.Storage.StorageRule.StorageType");
        StorageUtilizedInBytes = jResp.IntOf("UserActivities[i].CommentMetadata.Contributor.Storage.StorageUtilizedInBytes");
        Surname = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.Surname");
        TimeZoneId = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.TimeZoneId");
        v_Type = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.Type");
        Username = jResp.stringOf("UserActivities[i].CommentMetadata.Contributor.Username");
        CommentMetadataCreatedTimestamp = jResp.IntOf("UserActivities[i].CommentMetadata.CreatedTimestamp");
        RecipientId = jResp.stringOf("UserActivities[i].CommentMetadata.RecipientId");
        InitiatorEmailAddress = jResp.stringOf("UserActivities[i].Initiator.EmailAddress");
        InitiatorGivenName = jResp.stringOf("UserActivities[i].Initiator.GivenName");
        InitiatorId = jResp.stringOf("UserActivities[i].Initiator.Id");
        InitiatorSurname = jResp.stringOf("UserActivities[i].Initiator.Surname");
        InitiatorUsername = jResp.stringOf("UserActivities[i].Initiator.Username");
        IsIndirectActivity = jResp.IntOf("UserActivities[i].IsIndirectActivity");
        OrganizationId = jResp.stringOf("UserActivities[i].OrganizationId");
        OriginalParentId = jResp.stringOf("UserActivities[i].OriginalParent.Id");
        Name = jResp.stringOf("UserActivities[i].OriginalParent.Name");
        OriginalName = jResp.stringOf("UserActivities[i].OriginalParent.OriginalName");
        OwnerEmailAddress = jResp.stringOf("UserActivities[i].OriginalParent.Owner.EmailAddress");
        OwnerGivenName = jResp.stringOf("UserActivities[i].OriginalParent.Owner.GivenName");
        OwnerId = jResp.stringOf("UserActivities[i].OriginalParent.Owner.Id");
        OwnerSurname = jResp.stringOf("UserActivities[i].OriginalParent.Owner.Surname");
        OwnerUsername = jResp.stringOf("UserActivities[i].OriginalParent.Owner.Username");
        ParentId = jResp.stringOf("UserActivities[i].OriginalParent.ParentId");
        OriginalParentType = jResp.stringOf("UserActivities[i].OriginalParent.Type");
        VersionId = jResp.stringOf("UserActivities[i].OriginalParent.VersionId");
        ResourceMetadataId = jResp.stringOf("UserActivities[i].ResourceMetadata.Id");
        ResourceMetadataName = jResp.stringOf("UserActivities[i].ResourceMetadata.Name");
        ResourceMetadataOriginalName = jResp.stringOf("UserActivities[i].ResourceMetadata.OriginalName");
        OwnerEmailAddress = jResp.stringOf("UserActivities[i].ResourceMetadata.Owner.EmailAddress");
        OwnerGivenName = jResp.stringOf("UserActivities[i].ResourceMetadata.Owner.GivenName");
        OwnerId = jResp.stringOf("UserActivities[i].ResourceMetadata.Owner.Id");
        OwnerSurname = jResp.stringOf("UserActivities[i].ResourceMetadata.Owner.Surname");
        OwnerUsername = jResp.stringOf("UserActivities[i].ResourceMetadata.Owner.Username");
        ResourceMetadataParentId = jResp.stringOf("UserActivities[i].ResourceMetadata.ParentId");
        ResourceMetadataType = jResp.stringOf("UserActivities[i].ResourceMetadata.Type");
        ResourceMetadataVersionId = jResp.stringOf("UserActivities[i].ResourceMetadata.VersionId");
        TimeStamp = jResp.IntOf("UserActivities[i].TimeStamp");
        v_Type = jResp.stringOf("UserActivities[i].Type");
        j = 0;
        count_j = jResp.SizeOfArray("UserActivities[i].Participants.Groups");
        while (j < count_j) {
            jResp.put_J(j);
            Id = jResp.stringOf("UserActivities[i].Participants.Groups[j].Id");
            Name = jResp.stringOf("UserActivities[i].Participants.Groups[j].Name");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("UserActivities[i].Participants.Users");
        while (j < count_j) {
            jResp.put_J(j);
            EmailAddress = jResp.stringOf("UserActivities[i].Participants.Users[j].EmailAddress");
            GivenName = jResp.stringOf("UserActivities[i].Participants.Users[j].GivenName");
            Id = jResp.stringOf("UserActivities[i].Participants.Users[j].Id");
            Surname = jResp.stringOf("UserActivities[i].Participants.Users[j].Surname");
            Username = jResp.stringOf("UserActivities[i].Participants.Users[j].Username");
            j = j + 1;
        }

        i = i + 1;
    }

    // A sample JSON response body parsed by the above code:

    // {
    //   "Marker": "string",
    //   "UserActivities": [
    //     {
    //       "CommentMetadata": {
    //         "CommentId": "string",
    //         "CommentStatus": "string",
    //         "Contributor": {
    //           "CreatedTimestamp": number,
    //           "EmailAddress": "string",
    //           "GivenName": "string",
    //           "Id": "string",
    //           "Locale": "string",
    //           "ModifiedTimestamp": number,
    //           "OrganizationId": "string",
    //           "RecycleBinFolderId": "string",
    //           "RootFolderId": "string",
    //           "Status": "string",
    //           "Storage": {
    //             "StorageRule": {
    //               "StorageAllocatedInBytes": number,
    //               "StorageType": "string"
    //             },
    //             "StorageUtilizedInBytes": number
    //           },
    //           "Surname": "string",
    //           "TimeZoneId": "string",
    //           "Type": "string",
    //           "Username": "string"
    //         },
    //         "CreatedTimestamp": number,
    //         "RecipientId": "string"
    //       },
    //       "Initiator": {
    //         "EmailAddress": "string",
    //         "GivenName": "string",
    //         "Id": "string",
    //         "Surname": "string",
    //         "Username": "string"
    //       },
    //       "IsIndirectActivity": boolean,
    //       "OrganizationId": "string",
    //       "OriginalParent": {
    //         "Id": "string",
    //         "Name": "string",
    //         "OriginalName": "string",
    //         "Owner": {
    //           "EmailAddress": "string",
    //           "GivenName": "string",
    //           "Id": "string",
    //           "Surname": "string",
    //           "Username": "string"
    //         },
    //         "ParentId": "string",
    //         "Type": "string",
    //         "VersionId": "string"
    //       },
    //       "Participants": {
    //         "Groups": [
    //           {
    //             "Id": "string",
    //             "Name": "string"
    //           }
    //         ],
    //         "Users": [
    //           {
    //             "EmailAddress": "string",
    //             "GivenName": "string",
    //             "Id": "string",
    //             "Surname": "string",
    //             "Username": "string"
    //           }
    //         ]
    //       },
    //       "ResourceMetadata": {
    //         "Id": "string",
    //         "Name": "string",
    //         "OriginalName": "string",
    //         "Owner": {
    //           "EmailAddress": "string",
    //           "GivenName": "string",
    //           "Id": "string",
    //           "Surname": "string",
    //           "Username": "string"
    //         },
    //         "ParentId": "string",
    //         "Type": "string",
    //         "VersionId": "string"
    //       },
    //       "TimeStamp": number,
    //       "Type": "string"
    //     }
    //   ]
    // }
    }