Chilkat Online Tools

DeleteBGPPeer Foxpro Example

AWS Direct Connect

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcAddressFamily
LOCAL lcAmazonAddress
LOCAL lnAsn
LOCAL lcAuthKey
LOCAL lcAwsDeviceV2
LOCAL lcAwsLogicalDeviceId
LOCAL lcBgpPeerId
LOCAL lcBgpPeerState
LOCAL lcBgpStatus
LOCAL lcCustomerAddress
LOCAL lcCidr
LOCAL lcKey
LOCAL lcValue
LOCAL lcAddressFamily
LOCAL lcAmazonAddress
LOCAL lnAmazonSideAsn
LOCAL lnV_Asn
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("asn",123)
loJson.UpdateString("bgpPeerId","string")
loJson.UpdateString("customerAddress","string")
loJson.UpdateString("virtualInterfaceId","string")

* The JSON request body created by the above code:

* {
*   "asn": number,
*   "bgpPeerId": "string",
*   "customerAddress": "string",
*   "virtualInterfaceId": "string"
* }

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

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

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

* {
*   "virtualInterface": {
*     "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