Chilkat Online Tools

ListAnswers autoit Example

AWS Well-Architected Tool

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

$oRest = ObjCreate("Chilkat_9_5_0.Rest")
Local $bSuccess

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

; URL: https://wellarchitected.us-west-2.amazonaws.com/
; Use the same region as specified above.
$bSuccess = $oRest.Connect("wellarchitected.us-west-2.amazonaws.com",443,True,True)
If ($bSuccess <> True) Then
    ConsoleWrite("ConnectFailReason: " & $oRest.ConnectFailReason & @CRLF)
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

$oRest.AddHeader("Content-Type","application/x-amz-json-1.1")
$oRest.AddHeader("X-Amz-Target","ListAnswers")

$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$bSuccess = $oRest.FullRequestNoBodySb("GET","/workloads/{WorkloadId}/lensReviews/{LensAlias}/answers",$oSbResponseBody)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

Local $iRespStatusCode = $oRest.ResponseStatusCode
ConsoleWrite("response status code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode <> 200) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oRest.ResponseHeader & @CRLF)
    ConsoleWrite("Response Body:" & @CRLF)
    ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF)
    Exit
EndIf

$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)

; 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

Local $iIsApplicable
Local $sPillarId
Local $sQuestionId
Local $sQuestionTitle
Local $sReason
Local $sRisk
Local $iJ
Local $iCount_j
Local $sChoiceId
Local $sStatus
Local $sDescription
Local $sDisplayText
Local $sV_Url
Local $sImprovementPlanDisplayText
Local $sImprovementPlanUrl
Local $sTitle
Local $strVal

Local $sLensAlias = $oJResp.StringOf("LensAlias")
Local $sLensArn = $oJResp.StringOf("LensArn")
Local $iMilestoneNumber = $oJResp.IntOf("MilestoneNumber")
Local $sNextToken = $oJResp.StringOf("NextToken")
Local $sWorkloadId = $oJResp.StringOf("WorkloadId")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("AnswerSummaries")
While $i < $iCount_i
    $oJResp.I = $i
    $iIsApplicable = $oJResp.IntOf("AnswerSummaries[i].IsApplicable")
    $sPillarId = $oJResp.StringOf("AnswerSummaries[i].PillarId")
    $sQuestionId = $oJResp.StringOf("AnswerSummaries[i].QuestionId")
    $sQuestionTitle = $oJResp.StringOf("AnswerSummaries[i].QuestionTitle")
    $sReason = $oJResp.StringOf("AnswerSummaries[i].Reason")
    $sRisk = $oJResp.StringOf("AnswerSummaries[i].Risk")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("AnswerSummaries[i].ChoiceAnswerSummaries")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sChoiceId = $oJResp.StringOf("AnswerSummaries[i].ChoiceAnswerSummaries[j].ChoiceId")
        $sReason = $oJResp.StringOf("AnswerSummaries[i].ChoiceAnswerSummaries[j].Reason")
        $sStatus = $oJResp.StringOf("AnswerSummaries[i].ChoiceAnswerSummaries[j].Status")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("AnswerSummaries[i].Choices")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sChoiceId = $oJResp.StringOf("AnswerSummaries[i].Choices[j].ChoiceId")
        $sDescription = $oJResp.StringOf("AnswerSummaries[i].Choices[j].Description")
        $sDisplayText = $oJResp.StringOf("AnswerSummaries[i].Choices[j].HelpfulResource.DisplayText")
        $sV_Url = $oJResp.StringOf("AnswerSummaries[i].Choices[j].HelpfulResource.Url")
        $sImprovementPlanDisplayText = $oJResp.StringOf("AnswerSummaries[i].Choices[j].ImprovementPlan.DisplayText")
        $sImprovementPlanUrl = $oJResp.StringOf("AnswerSummaries[i].Choices[j].ImprovementPlan.Url")
        $sTitle = $oJResp.StringOf("AnswerSummaries[i].Choices[j].Title")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("AnswerSummaries[i].SelectedChoices")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("AnswerSummaries[i].SelectedChoices[j]")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

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

; {
;   "AnswerSummaries": [
;     {
;       "ChoiceAnswerSummaries": [
;         {
;           "ChoiceId": "string",
;           "Reason": "string",
;           "Status": "string"
;         }
;       ],
;       "Choices": [
;         {
;           "ChoiceId": "string",
;           "Description": "string",
;           "HelpfulResource": {
;             "DisplayText": "string",
;             "Url": "string"
;           },
;           "ImprovementPlan": {
;             "DisplayText": "string",
;             "Url": "string"
;           },
;           "Title": "string"
;         }
;       ],
;       "IsApplicable": boolean,
;       "PillarId": "string",
;       "QuestionId": "string",
;       "QuestionTitle": "string",
;       "Reason": "string",
;       "Risk": "string",
;       "SelectedChoices": [
;         "string"
;       ]
;     }
;   ],
;   "LensAlias": "string",
;   "LensArn": "string",
;   "MilestoneNumber": number,
;   "NextToken": "string",
;   "WorkloadId": "string"
; }