GetAnswer DataFlex Example
Use ChilkatAx-9.5.0-win32.pkg
Procedure Test
Handle hoRest
Boolean iSuccess
Variant vAuthAws
Handle hoAuthAws
Variant vSbResponseBody
Handle hoSbResponseBody
Integer iRespStatusCode
Handle hoJResp
String sChoiceId
String sStatus
String sDescription
String sDisplayText
String sV_Url
String sImprovementPlanDisplayText
String sTitle
String sStrVal
String sHelpfulResourceDisplayText
String sHelpfulResourceUrl
String sImprovementPlanUrl
Integer iIsApplicable
String sNotes
String sPillarId
String sQuestionDescription
String sQuestionId
String sQuestionTitle
String sReason
String sRisk
String sLensAlias
String sLensArn
Integer iMilestoneNumber
String sWorkloadId
Integer i
Integer iCount_i
String sTemp1
Integer iTemp1
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
If (Not(IsComObjectCreated(hoAuthAws))) Begin
Send CreateComObject of hoAuthAws
End
Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
Set ComSecretKey Of hoAuthAws To "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.)
Set ComRegion Of hoAuthAws To "us-west-2"
Set ComServiceName Of hoAuthAws To "wellarchitected"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
Get pvComObject of hoAuthAws to vAuthAws
Get ComSetAuthAws Of hoRest vAuthAws To iSuccess
// URL: https://wellarchitected.us-west-2.amazonaws.com/
// Use the same region as specified above.
Get ComConnect Of hoRest "wellarchitected.us-west-2.amazonaws.com" 443 True True To iSuccess
If (iSuccess <> True) Begin
Get ComConnectFailReason Of hoRest To iTemp1
Showln "ConnectFailReason: " iTemp1
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.1" To iSuccess
Get ComAddHeader Of hoRest "X-Amz-Target" "GetAnswer" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComFullRequestNoBodySb Of hoRest "GET" "/workloads/{WorkloadId}/lensReviews/{LensAlias}/answers/{QuestionId}" vSbResponseBody To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iRespStatusCode
Showln "response status code = " iRespStatusCode
If (iRespStatusCode <> 200) Begin
Showln "Response Header:"
Get ComResponseHeader Of hoRest To sTemp1
Showln sTemp1
Showln "Response Body:"
Get ComGetAsString Of hoSbResponseBody To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
// 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
Get ComStringOf Of hoJResp "Answer.HelpfulResourceDisplayText" To sHelpfulResourceDisplayText
Get ComStringOf Of hoJResp "Answer.HelpfulResourceUrl" To sHelpfulResourceUrl
Get ComStringOf Of hoJResp "Answer.ImprovementPlanUrl" To sImprovementPlanUrl
Get ComIntOf Of hoJResp "Answer.IsApplicable" To iIsApplicable
Get ComStringOf Of hoJResp "Answer.Notes" To sNotes
Get ComStringOf Of hoJResp "Answer.PillarId" To sPillarId
Get ComStringOf Of hoJResp "Answer.QuestionDescription" To sQuestionDescription
Get ComStringOf Of hoJResp "Answer.QuestionId" To sQuestionId
Get ComStringOf Of hoJResp "Answer.QuestionTitle" To sQuestionTitle
Get ComStringOf Of hoJResp "Answer.Reason" To sReason
Get ComStringOf Of hoJResp "Answer.Risk" To sRisk
Get ComStringOf Of hoJResp "LensAlias" To sLensAlias
Get ComStringOf Of hoJResp "LensArn" To sLensArn
Get ComIntOf Of hoJResp "MilestoneNumber" To iMilestoneNumber
Get ComStringOf Of hoJResp "WorkloadId" To sWorkloadId
Move 0 To i
Get ComSizeOfArray Of hoJResp "Answer.ChoiceAnswers" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "Answer.ChoiceAnswers[i].ChoiceId" To sChoiceId
Get ComStringOf Of hoJResp "Answer.ChoiceAnswers[i].Notes" To sNotes
Get ComStringOf Of hoJResp "Answer.ChoiceAnswers[i].Reason" To sReason
Get ComStringOf Of hoJResp "Answer.ChoiceAnswers[i].Status" To sStatus
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "Answer.Choices" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "Answer.Choices[i].ChoiceId" To sChoiceId
Get ComStringOf Of hoJResp "Answer.Choices[i].Description" To sDescription
Get ComStringOf Of hoJResp "Answer.Choices[i].HelpfulResource.DisplayText" To sDisplayText
Get ComStringOf Of hoJResp "Answer.Choices[i].HelpfulResource.Url" To sV_Url
Get ComStringOf Of hoJResp "Answer.Choices[i].ImprovementPlan.DisplayText" To sImprovementPlanDisplayText
Get ComStringOf Of hoJResp "Answer.Choices[i].ImprovementPlan.Url" To sImprovementPlanUrl
Get ComStringOf Of hoJResp "Answer.Choices[i].Title" To sTitle
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "Answer.SelectedChoices" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "Answer.SelectedChoices[i]" To sStrVal
Move (i + 1) To i
Loop
// A sample JSON response body parsed by the above code:
// {
// "Answer": {
// "ChoiceAnswers": [
// {
// "ChoiceId": "string",
// "Notes": "string",
// "Reason": "string",
// "Status": "string"
// }
// ],
// "Choices": [
// {
// "ChoiceId": "string",
// "Description": "string",
// "HelpfulResource": {
// "DisplayText": "string",
// "Url": "string"
// },
// "ImprovementPlan": {
// "DisplayText": "string",
// "Url": "string"
// },
// "Title": "string"
// }
// ],
// "HelpfulResourceDisplayText": "string",
// "HelpfulResourceUrl": "string",
// "ImprovementPlanUrl": "string",
// "IsApplicable": boolean,
// "Notes": "string",
// "PillarId": "string",
// "QuestionDescription": "string",
// "QuestionId": "string",
// "QuestionTitle": "string",
// "Reason": "string",
// "Risk": "string",
// "SelectedChoices": [
// "string"
// ]
// },
// "LensAlias": "string",
// "LensArn": "string",
// "MilestoneNumber": number,
// "WorkloadId": "string"
// }
End_Procedure