Chilkat Online Tools

C / MongoDB Atlas / Modify Cloud Backup Backup Policy

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkHttpResponse resp;

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

    http = CkHttp_Create();

    CkHttp_putDigestAuth(http,TRUE);
    CkHttp_putLogin(http,"username");
    CkHttp_putPassword(http,"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
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateInt(json,"referenceHourOfDay",12);
    CkJsonObject_UpdateInt(json,"referenceMinuteOfHour",30);
    CkJsonObject_UpdateString(json,"policies[0].id","5f8dc2299b9d310a7fde98e6");
    CkJsonObject_UpdateString(json,"policies[0].policyItems[0].id","5f8dc2299b9d310a7fde98e7");
    CkJsonObject_UpdateString(json,"policies[0].policyItems[0].frequencyType","hourly");
    CkJsonObject_UpdateInt(json,"policies[0].policyItems[0].frequencyInterval",6);
    CkJsonObject_UpdateInt(json,"policies[0].policyItems[0].retentionValue",2);
    CkJsonObject_UpdateString(json,"policies[0].policyItems[0].retentionUnit","days");
    CkJsonObject_UpdateString(json,"policies[0].policyItems[1].id","5f8dc2299b9d310a7fde98e9");
    CkJsonObject_UpdateString(json,"policies[0].policyItems[1].frequencyType","weekly");
    CkJsonObject_UpdateInt(json,"policies[0].policyItems[1].frequencyInterval",1);
    CkJsonObject_UpdateInt(json,"policies[0].policyItems[1].retentionValue",3);
    CkJsonObject_UpdateString(json,"policies[0].policyItems[1].retentionUnit","weeks");
    CkJsonObject_UpdateBool(json,"updateSnapshots",TRUE);

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);

    resp = CkHttp_PTextSb(http,"PATCH","https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(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": [
  ]
}