Chilkat Online Tools

Swift / MongoDB Atlas / GCP - Create One New Network Peering Connection

Back to Collection Items

func chilkatTest() {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()
    var success: Bool

    http.DigestAuth = true
    http.Login = "username"
    http.Password = "password"

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

    // The following JSON is sent in the request body.

    // {
    //   "containerId": "{{CONTAINER-ID}}",
    //   "gcpProjectId": "my-sample-project-191923",
    //   "networkName": "test1",
    //   "providerName": "GCP"
    // }

    let json = CkoJsonObject()
    json.UpdateString("containerId", value: "{{CONTAINER-ID}}")
    json.UpdateString("gcpProjectId", value: "my-sample-project-191923")
    json.UpdateString("networkName", value: "test1")
    json.UpdateString("providerName", value: "GCP")

    var resp: CkoHttpResponse? = http.PostJson3("https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/peers", contentType: "application/json", json: json)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    print("\(resp!.StatusCode.intValue)")
    print("\(resp!.BodyStr)")
    resp = nil

}

Curl Command

curl -X POST
	--digest -u 'username:password'
	-d '{
    "containerId": "{{CONTAINER-ID}}",
    "gcpProjectId": "my-sample-project-191923",
    "networkName": "test1",
    "providerName": "GCP"
}'
https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/peers

Postman Collection Item JSON

{
  "name": "GCP - Create One New Network Peering Connection",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"containerId\": \"{{CONTAINER-ID}}\",\n    \"gcpProjectId\": \"my-sample-project-191923\",\n    \"networkName\": \"test1\",\n    \"providerName\": \"GCP\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{base_url}}/api/atlas/{{version}}/groups/{{ProjectID}}/peers",
      "host": [
        "{{base_url}}"
      ],
      "path": [
        "api",
        "atlas",
        "{{version}}",
        "groups",
        "{{ProjectID}}",
        "peers"
      ]
    },
    "description": "https://docs.atlas.mongodb.com/reference/api/vpc-create-peering-connection/"
  },
  "response": [
  ]
}