Chilkat Online Tools

PowerBuilder / MongoDB Atlas / Modify Cloud Backup Backup Policy

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.DigestAuth = 1
loo_Http.Login = "username"
loo_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.

// {
//   "referenceHourOfDay": 12,
//   "referenceMinuteOfHour": 30,
//   "policies": [
//     {
//       "id": "5f8dc2299b9d310a7fde98e6",
//       "policyItems": [
//         {
//           "id": "5f8dc2299b9d310a7fde98e7",
//           "frequencyType": "hourly",
//           "frequencyInterval": 6,
//           "retentionValue": 2,
//           "retentionUnit": "days"
//         },
//         {
//           "id": "5f8dc2299b9d310a7fde98e9",
//           "frequencyType": "weekly",
//           "frequencyInterval": 1,
//           "retentionValue": 3,
//           "retentionUnit": "weeks"
//         }
//       ]
//     }
//   ],
//   "updateSnapshots": true
// }

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateInt("referenceHourOfDay",12)
loo_Json.UpdateInt("referenceMinuteOfHour",30)
loo_Json.UpdateString("policies[0].id","5f8dc2299b9d310a7fde98e6")
loo_Json.UpdateString("policies[0].policyItems[0].id","5f8dc2299b9d310a7fde98e7")
loo_Json.UpdateString("policies[0].policyItems[0].frequencyType","hourly")
loo_Json.UpdateInt("policies[0].policyItems[0].frequencyInterval",6)
loo_Json.UpdateInt("policies[0].policyItems[0].retentionValue",2)
loo_Json.UpdateString("policies[0].policyItems[0].retentionUnit","days")
loo_Json.UpdateString("policies[0].policyItems[1].id","5f8dc2299b9d310a7fde98e9")
loo_Json.UpdateString("policies[0].policyItems[1].frequencyType","weekly")
loo_Json.UpdateInt("policies[0].policyItems[1].frequencyInterval",1)
loo_Json.UpdateInt("policies[0].policyItems[1].retentionValue",3)
loo_Json.UpdateString("policies[0].policyItems[1].retentionUnit","weeks")
loo_Json.UpdateBool("updateSnapshots",1)

loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)

loo_Resp = loo_Http.PTextSb("PATCH","https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbRequestBody
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody

Curl Command

curl -X PATCH
	--digest -u 'username:password'
	-d '{
    "referenceHourOfDay": 12,
    "referenceMinuteOfHour": 30,
    "policies": [
        {
            "id": "5f8dc2299b9d310a7fde98e6",
            "policyItems": [
                {
                    "id": "5f8dc2299b9d310a7fde98e7",
                    "frequencyType": "hourly",
                    "frequencyInterval": 6,
                    "retentionValue": 2,
                    "retentionUnit": "days"
                },
                {
                    "id": "5f8dc2299b9d310a7fde98e9",
                    "frequencyType": "weekly",
                    "frequencyInterval": 1,
                    "retentionValue": 3,
                    "retentionUnit": "weeks"
                }
            ]
        }
    ],
    "updateSnapshots": true
}'
https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule

Postman Collection Item JSON

{
  "name": "Modify Cloud Backup Backup Policy",
  "request": {
    "method": "PATCH",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"referenceHourOfDay\": 12,\n    \"referenceMinuteOfHour\": 30,\n    \"policies\": [\n        {\n            \"id\": \"5f8dc2299b9d310a7fde98e6\",\n            \"policyItems\": [\n                {\n                    \"id\": \"5f8dc2299b9d310a7fde98e7\",\n                    \"frequencyType\": \"hourly\",\n                    \"frequencyInterval\": 6,\n                    \"retentionValue\": 2,\n                    \"retentionUnit\": \"days\"\n                },\n                {\n                    \"id\": \"5f8dc2299b9d310a7fde98e9\",\n                    \"frequencyType\": \"weekly\",\n                    \"frequencyInterval\": 1,\n                    \"retentionValue\": 3,\n                    \"retentionUnit\": \"weeks\"\n                }\n            ]\n        }\n    ],\n    \"updateSnapshots\": true\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{base_url}}/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule",
      "host": [
        "{{base_url}}"
      ],
      "path": [
        "api",
        "atlas",
        "{{version}}",
        "groups",
        "{{ProjectID}}",
        "clusters",
        "{{CLUSTER-NAME}}",
        "backup",
        "schedule"
      ]
    },
    "description": "https://docs.atlas.mongodb.com/reference/api/cloud-backup/schedule/get-all-schedules/"
  },
  "response": [
  ]
}