C Box: Copy Folder

Back to Index

Used to create a copy of a folder in another folder. The original version of the folder will not be altered. The a response status code of 202 is expected for success.

Documentation: https://developer.box.com/reference#copy-a-folder

CURL Command

curl https://api.box.com/2.0/folders/FOLDER_ID/copy \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \
-d '{"parent": {"id" : DESTINATION_FOLDER_ID}}' \
-X POST

C Example

#include <C_CkRest.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jsonResponse;
    const char *type;
    const char *id;
    const char *sequence_id;
    const char *etag;
    const char *name;
    const char *created_at;
    const char *modified_at;
    const char *description;
    int size;
    int path_collectionTotal_count;
    const char *created_byType;
    const char *created_byId;
    const char *created_byName;
    const char *created_byLogin;
    const char *modified_byType;
    const char *modified_byId;
    const char *modified_byName;
    const char *modified_byLogin;
    const char *owned_byType;
    const char *owned_byId;
    const char *owned_byName;
    const char *owned_byLogin;
    const char *shared_linkUrl;
    BOOL shared_linkDownload_url;
    BOOL shared_linkVanity_url;
    BOOL shared_linkIs_password_enabled;
    BOOL shared_linkUnshared_at;
    int shared_linkDownload_count;
    int shared_linkPreview_count;
    const char *shared_linkAccess;
    BOOL shared_linkPermissionsCan_download;
    BOOL shared_linkPermissionsCan_preview;
    const char *folder_upload_emailAccess;
    const char *folder_upload_emailEmail;
    const char *parentType;
    const char *parentId;
    BOOL parentSequence_id;
    BOOL parentEtag;
    const char *parentName;
    const char *item_status;
    int item_collectionTotal_count;
    int item_collectionOffset;
    int item_collectionLimit;
    int i;
    int count_i;
    BOOL sequence_id_bool;
    BOOL etag_bool;
    const char *sha1;

    rest = CkRest_Create();

    //  URL: https://api.box.com/2.0/folders/FOLDER_ID/copy
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.box.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateNumber(json,"parent.id","DESTINATION_FOLDER_ID");

    CkRest_AddHeader(rest,"Authorization","Bearer BOX_ACCESS_TOKEN");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestSb(rest,"POST","/2.0/folders/FOLDER_ID/copy",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

    type = CkJsonObject_stringOf(jsonResponse,"type");
    id = CkJsonObject_stringOf(jsonResponse,"id");
    sequence_id = CkJsonObject_stringOf(jsonResponse,"sequence_id");
    etag = CkJsonObject_stringOf(jsonResponse,"etag");
    name = CkJsonObject_stringOf(jsonResponse,"name");
    created_at = CkJsonObject_stringOf(jsonResponse,"created_at");
    modified_at = CkJsonObject_stringOf(jsonResponse,"modified_at");
    description = CkJsonObject_stringOf(jsonResponse,"description");
    size = CkJsonObject_IntOf(jsonResponse,"size");
    path_collectionTotal_count = CkJsonObject_IntOf(jsonResponse,"path_collection.total_count");
    created_byType = CkJsonObject_stringOf(jsonResponse,"created_by.type");
    created_byId = CkJsonObject_stringOf(jsonResponse,"created_by.id");
    created_byName = CkJsonObject_stringOf(jsonResponse,"created_by.name");
    created_byLogin = CkJsonObject_stringOf(jsonResponse,"created_by.login");
    modified_byType = CkJsonObject_stringOf(jsonResponse,"modified_by.type");
    modified_byId = CkJsonObject_stringOf(jsonResponse,"modified_by.id");
    modified_byName = CkJsonObject_stringOf(jsonResponse,"modified_by.name");
    modified_byLogin = CkJsonObject_stringOf(jsonResponse,"modified_by.login");
    owned_byType = CkJsonObject_stringOf(jsonResponse,"owned_by.type");
    owned_byId = CkJsonObject_stringOf(jsonResponse,"owned_by.id");
    owned_byName = CkJsonObject_stringOf(jsonResponse,"owned_by.name");
    owned_byLogin = CkJsonObject_stringOf(jsonResponse,"owned_by.login");
    shared_linkUrl = CkJsonObject_stringOf(jsonResponse,"shared_link.url");
    shared_linkDownload_url = CkJsonObject_IsNullOf(jsonResponse,"shared_link.download_url");
    shared_linkVanity_url = CkJsonObject_IsNullOf(jsonResponse,"shared_link.vanity_url");
    shared_linkIs_password_enabled = CkJsonObject_BoolOf(jsonResponse,"shared_link.is_password_enabled");
    shared_linkUnshared_at = CkJsonObject_IsNullOf(jsonResponse,"shared_link.unshared_at");
    shared_linkDownload_count = CkJsonObject_IntOf(jsonResponse,"shared_link.download_count");
    shared_linkPreview_count = CkJsonObject_IntOf(jsonResponse,"shared_link.preview_count");
    shared_linkAccess = CkJsonObject_stringOf(jsonResponse,"shared_link.access");
    shared_linkPermissionsCan_download = CkJsonObject_BoolOf(jsonResponse,"shared_link.permissions.can_download");
    shared_linkPermissionsCan_preview = CkJsonObject_BoolOf(jsonResponse,"shared_link.permissions.can_preview");
    folder_upload_emailAccess = CkJsonObject_stringOf(jsonResponse,"folder_upload_email.access");
    folder_upload_emailEmail = CkJsonObject_stringOf(jsonResponse,"folder_upload_email.email");
    parentType = CkJsonObject_stringOf(jsonResponse,"parent.type");
    parentId = CkJsonObject_stringOf(jsonResponse,"parent.id");
    parentSequence_id = CkJsonObject_IsNullOf(jsonResponse,"parent.sequence_id");
    parentEtag = CkJsonObject_IsNullOf(jsonResponse,"parent.etag");
    parentName = CkJsonObject_stringOf(jsonResponse,"parent.name");
    item_status = CkJsonObject_stringOf(jsonResponse,"item_status");
    item_collectionTotal_count = CkJsonObject_IntOf(jsonResponse,"item_collection.total_count");
    item_collectionOffset = CkJsonObject_IntOf(jsonResponse,"item_collection.offset");
    item_collectionLimit = CkJsonObject_IntOf(jsonResponse,"item_collection.limit");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"path_collection.entries");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        type = CkJsonObject_stringOf(jsonResponse,"path_collection.entries[i].type");
        id = CkJsonObject_stringOf(jsonResponse,"path_collection.entries[i].id");
        sequence_id_bool = CkJsonObject_IsNullOf(jsonResponse,"path_collection.entries[i].sequence_id");
        etag_bool = CkJsonObject_IsNullOf(jsonResponse,"path_collection.entries[i].etag");
        name = CkJsonObject_stringOf(jsonResponse,"path_collection.entries[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"item_collection.entries");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        type = CkJsonObject_stringOf(jsonResponse,"item_collection.entries[i].type");
        id = CkJsonObject_stringOf(jsonResponse,"item_collection.entries[i].id");
        sequence_id = CkJsonObject_stringOf(jsonResponse,"item_collection.entries[i].sequence_id");
        etag = CkJsonObject_stringOf(jsonResponse,"item_collection.entries[i].etag");
        sha1 = CkJsonObject_stringOf(jsonResponse,"item_collection.entries[i].sha1");
        name = CkJsonObject_stringOf(jsonResponse,"item_collection.entries[i].name");
        i = i + 1;
    }



    CkRest_Dispose(rest);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "type": "folder",
  "id": "11446498",
  "sequence_id": "1",
  "etag": "1",
  "name": "Pictures",
  "created_at": "2012-12-12T10:53:43-08:00",
  "modified_at": "2012-12-12T11:15:04-08:00",
  "description": "Some pictures I took",
  "size": 629644,
  "path_collection": {
    "total_count": 1,
    "entries": [
      {
        "type": "folder",
        "id": "0",
        "sequence_id": null,
        "etag": null,
        "name": "All Files"
      }
    ]
  },
  "created_by": {
    "type": "user",
    "id": "17738362",
    "name": "sean rose",
    "login": "sean@box.com"
  },
  "modified_by": {
    "type": "user",
    "id": "17738362",
    "name": "sean rose",
    "login": "sean@box.com"
  },
  "owned_by": {
    "type": "user",
    "id": "17738362",
    "name": "sean rose",
    "login": "sean@box.com"
  },
  "shared_link": {
    "url": "https://www.box.com/s/vspke7y05sb214wjokpk",
    "download_url": null,
    "vanity_url": null,
    "is_password_enabled": false,
    "unshared_at": null,
    "download_count": 0,
    "preview_count": 0,
    "access": "open",
    "permissions": {
      "can_download": true,
      "can_preview": true
    }
  },
  "folder_upload_email": {
    "access": "open",
    "email": "upload.Picture.k13sdz1@u.box.com"
  },
  "parent": {
    "type": "folder",
    "id": "0",
    "sequence_id": null,
    "etag": null,
    "name": "All Files"
  },
  "item_status": "active",
  "item_collection": {
    "total_count": 1,
    "entries": [
      {
        "type": "file",
        "id": "5000948880",
        "sequence_id": "3",
        "etag": "3",
        "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
        "name": "tigers.jpeg"
      }
    ],
    "offset": 0,
    "limit": 100
  }
}