Chilkat Online Tools

unicodeC / MongoDB Atlas / Modify Cloud Backup Backup Policy

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    CkHttpW_putDigestAuth(http,TRUE);
    CkHttpW_putLogin(http,L"username");
    CkHttpW_putPassword(http,L"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 = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateInt(json,L"referenceHourOfDay",12);
    CkJsonObjectW_UpdateInt(json,L"referenceMinuteOfHour",30);
    CkJsonObjectW_UpdateString(json,L"policies[0].id",L"5f8dc2299b9d310a7fde98e6");
    CkJsonObjectW_UpdateString(json,L"policies[0].policyItems[0].id",L"5f8dc2299b9d310a7fde98e7");
    CkJsonObjectW_UpdateString(json,L"policies[0].policyItems[0].frequencyType",L"hourly");
    CkJsonObjectW_UpdateInt(json,L"policies[0].policyItems[0].frequencyInterval",6);
    CkJsonObjectW_UpdateInt(json,L"policies[0].policyItems[0].retentionValue",2);
    CkJsonObjectW_UpdateString(json,L"policies[0].policyItems[0].retentionUnit",L"days");
    CkJsonObjectW_UpdateString(json,L"policies[0].policyItems[1].id",L"5f8dc2299b9d310a7fde98e9");
    CkJsonObjectW_UpdateString(json,L"policies[0].policyItems[1].frequencyType",L"weekly");
    CkJsonObjectW_UpdateInt(json,L"policies[0].policyItems[1].frequencyInterval",1);
    CkJsonObjectW_UpdateInt(json,L"policies[0].policyItems[1].retentionValue",3);
    CkJsonObjectW_UpdateString(json,L"policies[0].policyItems[1].retentionUnit",L"weeks");
    CkJsonObjectW_UpdateBool(json,L"updateSnapshots",TRUE);

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PATCH",L"https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_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": [
  ]
}