Chilkat Online Tools

StartRouteAnalysis Foxpro Example

AWS Network Manager

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcDestinationCidrBlock
LOCAL lcDefinition
LOCAL lnIsMiddlebox
LOCAL lcNameTag
LOCAL lcRegisteredGatewayArn
LOCAL lcResourceArn
LOCAL lcResourceType
LOCAL lnSequence
LOCAL lcResourceDefinition
LOCAL lnResourceIsMiddlebox
LOCAL lcResourceNameTag
LOCAL lcResourceRegisteredGatewayArn
LOCAL lcResourceResourceArn
LOCAL lcResourceResourceType
LOCAL lcIpAddress
LOCAL lcTransitGatewayArn
LOCAL lcTransitGatewayAttachmentArn
LOCAL lcReasonCode
LOCAL lcV_String
LOCAL lcResultCode
LOCAL lcGlobalNetworkId
LOCAL lnIncludeReturnPath
LOCAL lcOwnerAccountId
LOCAL lcCompletionStatusReasonCode
LOCAL lcReasonContextString
LOCAL lcCompletionStatusResultCode
LOCAL lcRouteAnalysisId
LOCAL lcSourceIpAddress
LOCAL lcSourceTransitGatewayArn
LOCAL lcSourceTransitGatewayAttachmentArn
LOCAL lnStartTimestamp
LOCAL lcStatus
LOCAL lnUseMiddleboxes
LOCAL i
LOCAL lnCount_i

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

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.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.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "networkmanager"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://networkmanager.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("networkmanager.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
ENDIF

* The following code creates the JSON request body.
* The JSON created by this code is shown below.

* Use this online tool to generate code from sample JSON:
* Generate Code to Create JSON

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("Destination.IpAddress","string")
loJson.UpdateString("Destination.TransitGatewayAttachmentArn","string")
loJson.UpdateInt("IncludeReturnPath",123)
loJson.UpdateString("Source.IpAddress","string")
loJson.UpdateString("Source.TransitGatewayAttachmentArn","string")
loJson.UpdateInt("UseMiddleboxes",123)

* The JSON request body created by the above code:

* {
*   "Destination": {
*     "IpAddress": "string",
*     "TransitGatewayAttachmentArn": "string"
*   },
*   "IncludeReturnPath": boolean,
*   "Source": {
*     "IpAddress": "string",
*     "TransitGatewayAttachmentArn": "string"
*   },
*   "UseMiddleboxes": boolean
* }

loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","StartRouteAnalysis")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/global-networks/{globalNetworkId}/route-analyses",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)

* 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

lcIpAddress = loJResp.StringOf("RouteAnalysis.Destination.IpAddress")
lcTransitGatewayArn = loJResp.StringOf("RouteAnalysis.Destination.TransitGatewayArn")
lcTransitGatewayAttachmentArn = loJResp.StringOf("RouteAnalysis.Destination.TransitGatewayAttachmentArn")
lcReasonCode = loJResp.StringOf("RouteAnalysis.ForwardPath.CompletionStatus.ReasonCode")
lcV_String = loJResp.StringOf("RouteAnalysis.ForwardPath.CompletionStatus.ReasonContext.string")
lcResultCode = loJResp.StringOf("RouteAnalysis.ForwardPath.CompletionStatus.ResultCode")
lcGlobalNetworkId = loJResp.StringOf("RouteAnalysis.GlobalNetworkId")
lnIncludeReturnPath = loJResp.IntOf("RouteAnalysis.IncludeReturnPath")
lcOwnerAccountId = loJResp.StringOf("RouteAnalysis.OwnerAccountId")
lcCompletionStatusReasonCode = loJResp.StringOf("RouteAnalysis.ReturnPath.CompletionStatus.ReasonCode")
lcReasonContextString = loJResp.StringOf("RouteAnalysis.ReturnPath.CompletionStatus.ReasonContext.string")
lcCompletionStatusResultCode = loJResp.StringOf("RouteAnalysis.ReturnPath.CompletionStatus.ResultCode")
lcRouteAnalysisId = loJResp.StringOf("RouteAnalysis.RouteAnalysisId")
lcSourceIpAddress = loJResp.StringOf("RouteAnalysis.Source.IpAddress")
lcSourceTransitGatewayArn = loJResp.StringOf("RouteAnalysis.Source.TransitGatewayArn")
lcSourceTransitGatewayAttachmentArn = loJResp.StringOf("RouteAnalysis.Source.TransitGatewayAttachmentArn")
lnStartTimestamp = loJResp.IntOf("RouteAnalysis.StartTimestamp")
lcStatus = loJResp.StringOf("RouteAnalysis.Status")
lnUseMiddleboxes = loJResp.IntOf("RouteAnalysis.UseMiddleboxes")
i = 0
lnCount_i = loJResp.SizeOfArray("RouteAnalysis.ForwardPath.Path")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcDestinationCidrBlock = loJResp.StringOf("RouteAnalysis.ForwardPath.Path[i].DestinationCidrBlock")
    lcDefinition = loJResp.StringOf("RouteAnalysis.ForwardPath.Path[i].Resource.Definition")
    lnIsMiddlebox = loJResp.IntOf("RouteAnalysis.ForwardPath.Path[i].Resource.IsMiddlebox")
    lcNameTag = loJResp.StringOf("RouteAnalysis.ForwardPath.Path[i].Resource.NameTag")
    lcRegisteredGatewayArn = loJResp.StringOf("RouteAnalysis.ForwardPath.Path[i].Resource.RegisteredGatewayArn")
    lcResourceArn = loJResp.StringOf("RouteAnalysis.ForwardPath.Path[i].Resource.ResourceArn")
    lcResourceType = loJResp.StringOf("RouteAnalysis.ForwardPath.Path[i].Resource.ResourceType")
    lnSequence = loJResp.IntOf("RouteAnalysis.ForwardPath.Path[i].Sequence")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("RouteAnalysis.ReturnPath.Path")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcDestinationCidrBlock = loJResp.StringOf("RouteAnalysis.ReturnPath.Path[i].DestinationCidrBlock")
    lcResourceDefinition = loJResp.StringOf("RouteAnalysis.ReturnPath.Path[i].Resource.Definition")
    lnResourceIsMiddlebox = loJResp.IntOf("RouteAnalysis.ReturnPath.Path[i].Resource.IsMiddlebox")
    lcResourceNameTag = loJResp.StringOf("RouteAnalysis.ReturnPath.Path[i].Resource.NameTag")
    lcResourceRegisteredGatewayArn = loJResp.StringOf("RouteAnalysis.ReturnPath.Path[i].Resource.RegisteredGatewayArn")
    lcResourceResourceArn = loJResp.StringOf("RouteAnalysis.ReturnPath.Path[i].Resource.ResourceArn")
    lcResourceResourceType = loJResp.StringOf("RouteAnalysis.ReturnPath.Path[i].Resource.ResourceType")
    lnSequence = loJResp.IntOf("RouteAnalysis.ReturnPath.Path[i].Sequence")
    i = i + 1
ENDDO

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

* {
*   "RouteAnalysis": {
*     "Destination": {
*       "IpAddress": "string",
*       "TransitGatewayArn": "string",
*       "TransitGatewayAttachmentArn": "string"
*     },
*     "ForwardPath": {
*       "CompletionStatus": {
*         "ReasonCode": "string",
*         "ReasonContext": {
*           "string": "string"
*         },
*         "ResultCode": "string"
*       },
*       "Path": [
*         {
*           "DestinationCidrBlock": "string",
*           "Resource": {
*             "Definition": "string",
*             "IsMiddlebox": boolean,
*             "NameTag": "string",
*             "RegisteredGatewayArn": "string",
*             "ResourceArn": "string",
*             "ResourceType": "string"
*           },
*           "Sequence": number
*         }
*       ]
*     },
*     "GlobalNetworkId": "string",
*     "IncludeReturnPath": boolean,
*     "OwnerAccountId": "string",
*     "ReturnPath": {
*       "CompletionStatus": {
*         "ReasonCode": "string",
*         "ReasonContext": {
*           "string": "string"
*         },
*         "ResultCode": "string"
*       },
*       "Path": [
*         {
*           "DestinationCidrBlock": "string",
*           "Resource": {
*             "Definition": "string",
*             "IsMiddlebox": boolean,
*             "NameTag": "string",
*             "RegisteredGatewayArn": "string",
*             "ResourceArn": "string",
*             "ResourceType": "string"
*           },
*           "Sequence": number
*         }
*       ]
*     },
*     "RouteAnalysisId": "string",
*     "Source": {
*       "IpAddress": "string",
*       "TransitGatewayArn": "string",
*       "TransitGatewayAttachmentArn": "string"
*     },
*     "StartTimestamp": number,
*     "Status": "string",
*     "UseMiddleboxes": boolean
*   }
* }

RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp