Chilkat Online Tools

UpdateVirtualInterfaceAttributes Foxpro Example

AWS Direct Connect

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcBgpPeerId
LOCAL lcBgpPeerState
LOCAL lcBgpStatus
LOCAL lcCidr
LOCAL lcKey
LOCAL lcValue
LOCAL lcAddressFamily
LOCAL lcAmazonAddress
LOCAL lnAmazonSideAsn
LOCAL lnAsn
LOCAL lcAuthKey
LOCAL lcAwsDeviceV2
LOCAL lcAwsLogicalDeviceId
LOCAL lcConnectionId
LOCAL lcCustomerAddress
LOCAL lcCustomerRouterConfig
LOCAL lcDirectConnectGatewayId
LOCAL lnJumboFrameCapable
LOCAL lcLocation
LOCAL lnMtu
LOCAL lcOwnerAccount
LOCAL lcRegion
LOCAL lnSiteLinkEnabled
LOCAL lcVirtualGatewayId
LOCAL lcVirtualInterfaceId
LOCAL lcVirtualInterfaceName
LOCAL lcVirtualInterfaceState
LOCAL lcVirtualInterfaceType
LOCAL lnVlan
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 = "directconnect"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://directconnect.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("directconnect.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.UpdateInt("enableSiteLink",123)
loJson.UpdateInt("mtu",123)
loJson.UpdateString("virtualInterfaceId","string")
loJson.UpdateString("virtualInterfaceName","string")

* The JSON request body created by the above code:

* {
*   "enableSiteLink": boolean,
*   "mtu": number,
*   "virtualInterfaceId": "string",
*   "virtualInterfaceName": "string"
* }

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

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/",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

lcAddressFamily = loJResp.StringOf("addressFamily")
lcAmazonAddress = loJResp.StringOf("amazonAddress")
lnAmazonSideAsn = loJResp.IntOf("amazonSideAsn")
lnAsn = loJResp.IntOf("asn")
lcAuthKey = loJResp.StringOf("authKey")
lcAwsDeviceV2 = loJResp.StringOf("awsDeviceV2")
lcAwsLogicalDeviceId = loJResp.StringOf("awsLogicalDeviceId")
lcConnectionId = loJResp.StringOf("connectionId")
lcCustomerAddress = loJResp.StringOf("customerAddress")
lcCustomerRouterConfig = loJResp.StringOf("customerRouterConfig")
lcDirectConnectGatewayId = loJResp.StringOf("directConnectGatewayId")
lnJumboFrameCapable = loJResp.IntOf("jumboFrameCapable")
lcLocation = loJResp.StringOf("location")
lnMtu = loJResp.IntOf("mtu")
lcOwnerAccount = loJResp.StringOf("ownerAccount")
lcRegion = loJResp.StringOf("region")
lnSiteLinkEnabled = loJResp.IntOf("siteLinkEnabled")
lcVirtualGatewayId = loJResp.StringOf("virtualGatewayId")
lcVirtualInterfaceId = loJResp.StringOf("virtualInterfaceId")
lcVirtualInterfaceName = loJResp.StringOf("virtualInterfaceName")
lcVirtualInterfaceState = loJResp.StringOf("virtualInterfaceState")
lcVirtualInterfaceType = loJResp.StringOf("virtualInterfaceType")
lnVlan = loJResp.IntOf("vlan")
i = 0
lnCount_i = loJResp.SizeOfArray("bgpPeers")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcAddressFamily = loJResp.StringOf("bgpPeers[i].addressFamily")
    lcAmazonAddress = loJResp.StringOf("bgpPeers[i].amazonAddress")
    lnAsn = loJResp.IntOf("bgpPeers[i].asn")
    lcAuthKey = loJResp.StringOf("bgpPeers[i].authKey")
    lcAwsDeviceV2 = loJResp.StringOf("bgpPeers[i].awsDeviceV2")
    lcAwsLogicalDeviceId = loJResp.StringOf("bgpPeers[i].awsLogicalDeviceId")
    lcBgpPeerId = loJResp.StringOf("bgpPeers[i].bgpPeerId")
    lcBgpPeerState = loJResp.StringOf("bgpPeers[i].bgpPeerState")
    lcBgpStatus = loJResp.StringOf("bgpPeers[i].bgpStatus")
    lcCustomerAddress = loJResp.StringOf("bgpPeers[i].customerAddress")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("routeFilterPrefixes")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcCidr = loJResp.StringOf("routeFilterPrefixes[i].cidr")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("tags")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcKey = loJResp.StringOf("tags[i].key")
    lcValue = loJResp.StringOf("tags[i].value")
    i = i + 1
ENDDO

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

* {
*   "addressFamily": "string",
*   "amazonAddress": "string",
*   "amazonSideAsn": number,
*   "asn": number,
*   "authKey": "string",
*   "awsDeviceV2": "string",
*   "awsLogicalDeviceId": "string",
*   "bgpPeers": [
*     {
*       "addressFamily": "string",
*       "amazonAddress": "string",
*       "asn": number,
*       "authKey": "string",
*       "awsDeviceV2": "string",
*       "awsLogicalDeviceId": "string",
*       "bgpPeerId": "string",
*       "bgpPeerState": "string",
*       "bgpStatus": "string",
*       "customerAddress": "string"
*     }
*   ],
*   "connectionId": "string",
*   "customerAddress": "string",
*   "customerRouterConfig": "string",
*   "directConnectGatewayId": "string",
*   "jumboFrameCapable": boolean,
*   "location": "string",
*   "mtu": number,
*   "ownerAccount": "string",
*   "region": "string",
*   "routeFilterPrefixes": [
*     {
*       "cidr": "string"
*     }
*   ],
*   "siteLinkEnabled": boolean,
*   "tags": [
*     {
*       "key": "string",
*       "value": "string"
*     }
*   ],
*   "virtualGatewayId": "string",
*   "virtualInterfaceId": "string",
*   "virtualInterfaceName": "string",
*   "virtualInterfaceState": "string",
*   "virtualInterfaceType": "string",
*   "vlan": number
* }

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