Unicode C++ Dropbox: Dropbox Delete a File

Back to Index

Deletes a file on Dropbox

Documentation: https://www.dropbox.com/developers/documentation/http/documentation#files-delete

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/delete_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Homework/math/Prime_Numbers.txt\"}"

Unicode C++ Example

#include <CkRestW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //  URL: https://api.dropboxapi.com/2/files/delete_v2
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect(L"api.dropboxapi.com",port,bTls,bAutoReconnect);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    //  See the Online Tool for Generating JSON Creation Code
    CkJsonObjectW json;
    json.UpdateString(L"path",L"/Homework/math/Prime_Numbers.txt");

    rest.AddHeader(L"Authorization",L"Bearer DROPBOX-ACCESS-TOKEN");
    rest.AddHeader(L"Content-Type",L"application/json");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/2/files/delete_v2",sbRequestBody,sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    //  See the Online Tool for Generating JSON Parse Code
    int i;
    int count_i;
    int j;
    int count_j;

    const wchar_t *metadataTag = jsonResponse.stringOf(L"metadata.\".tag\"");
    const wchar_t *metadataName = jsonResponse.stringOf(L"metadata.name");
    const wchar_t *metadataId = jsonResponse.stringOf(L"metadata.id");
    const wchar_t *metadataClient_modified = jsonResponse.stringOf(L"metadata.client_modified");
    const wchar_t *metadataServer_modified = jsonResponse.stringOf(L"metadata.server_modified");
    const wchar_t *metadataRev = jsonResponse.stringOf(L"metadata.rev");
    int metadataSize = jsonResponse.IntOf(L"metadata.size");
    const wchar_t *metadataPath_lower = jsonResponse.stringOf(L"metadata.path_lower");
    const wchar_t *metadataPath_display = jsonResponse.stringOf(L"metadata.path_display");
    bool metadataSharing_infoRead_only = jsonResponse.BoolOf(L"metadata.sharing_info.read_only");
    const wchar_t *metadataSharing_infoParent_shared_folder_id = jsonResponse.stringOf(L"metadata.sharing_info.parent_shared_folder_id");
    const wchar_t *metadataSharing_infoModified_by = jsonResponse.stringOf(L"metadata.sharing_info.modified_by");
    bool metadataHas_explicit_shared_members = jsonResponse.BoolOf(L"metadata.has_explicit_shared_members");
    const wchar_t *metadataContent_hash = jsonResponse.stringOf(L"metadata.content_hash");
    i = 0;
    count_i = jsonResponse.SizeOfArray(L"metadata.property_groups");
    while (i < count_i) {
        jsonResponse.put_I(i);
        const wchar_t *template_id = jsonResponse.stringOf(L"metadata.property_groups[i].template_id");
        j = 0;
        count_j = jsonResponse.SizeOfArray(L"metadata.property_groups[i].fields");
        while (j < count_j) {
            jsonResponse.put_J(j);
            const wchar_t *name = jsonResponse.stringOf(L"metadata.property_groups[i].fields[j].name");
            const wchar_t *value = jsonResponse.stringOf(L"metadata.property_groups[i].fields[j].value");
            j = j + 1;
        }

        i = i + 1;
    }
    }

Sample JSON Response Body

{
  "metadata": {
    ".tag": "file",
    "name": "Prime_Numbers.txt",
    "id": "id:a4ayc_80_OEAAAAAAAAAXw",
    "client_modified": "2015-05-12T15:50:38Z",
    "server_modified": "2015-05-12T15:50:38Z",
    "rev": "a1c10ce0dd78",
    "size": 7212,
    "path_lower": "/homework/math/prime_numbers.txt",
    "path_display": "/Homework/math/Prime_Numbers.txt",
    "sharing_info": {
      "read_only": true,
      "parent_shared_folder_id": "84528192421",
      "modified_by": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
    },
    "property_groups": [
      {
        "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
        "fields": [
          {
            "name": "Security Policy",
            "value": "Confidential"
          }
        ]
      }
    ],
    "has_explicit_shared_members": false,
    "content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
  }
}