Chilkat Online Tools

ListLenses C# Example

AWS Well-Architected Tool

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

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

Chilkat.AuthAws authAws = new Chilkat.AuthAws();
authAws.AccessKey = "AWS_ACCESS_KEY";
authAws.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.Region = "us-west-2";
authAws.ServiceName = "wellarchitected";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws);

// URL: https://wellarchitected.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect("wellarchitected.us-west-2.amazonaws.com",443,true,true);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

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

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
success = rest.FullRequestNoBodySb("GET","/lenses",sbResponseBody);
if (success != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

int respStatusCode = rest.ResponseStatusCode;
Debug.WriteLine("response status code = " + Convert.ToString(respStatusCode));
if (respStatusCode != 200) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(rest.ResponseHeader);
    Debug.WriteLine("Response Body:");
    Debug.WriteLine(sbResponseBody.GetAsString());
    return;
}

Chilkat.JsonObject jResp = new Chilkat.JsonObject();
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

int CreatedAt;
string Description;
string LensAlias;
string LensArn;
string LensName;
string LensStatus;
string LensType;
string LensVersion;
string Owner;
int UpdatedAt;

string NextToken = jResp.StringOf("NextToken");
int i = 0;
int count_i = jResp.SizeOfArray("LensSummaries");
while (i < count_i) {
    jResp.I = i;
    CreatedAt = jResp.IntOf("LensSummaries[i].CreatedAt");
    Description = jResp.StringOf("LensSummaries[i].Description");
    LensAlias = jResp.StringOf("LensSummaries[i].LensAlias");
    LensArn = jResp.StringOf("LensSummaries[i].LensArn");
    LensName = jResp.StringOf("LensSummaries[i].LensName");
    LensStatus = jResp.StringOf("LensSummaries[i].LensStatus");
    LensType = jResp.StringOf("LensSummaries[i].LensType");
    LensVersion = jResp.StringOf("LensSummaries[i].LensVersion");
    Owner = jResp.StringOf("LensSummaries[i].Owner");
    UpdatedAt = jResp.IntOf("LensSummaries[i].UpdatedAt");
    i = i + 1;
}

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

// {
//   "LensSummaries": [
//     {
//       "CreatedAt": number,
//       "Description": "string",
//       "LensAlias": "string",
//       "LensArn": "string",
//       "LensName": "string",
//       "LensStatus": "string",
//       "LensType": "string",
//       "LensVersion": "string",
//       "Owner": "string",
//       "UpdatedAt": number
//     }
//   ],
//   "NextToken": "string"
// }