Creates a new folder. To create a folder in the root folder, use a parent folder id = "0".
curl https://api.box.com/2.0/folders \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \
-d '{"name":"Important Docs", "parent": {"id": "BOX_FOLDER_ID"}}' \
-X POST
#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;
BOOL trashed_at;
BOOL purged_at;
const char *content_created_at;
const char *content_modified_at;
const char *owned_byType;
const char *owned_byId;
const char *owned_byName;
const char *owned_byLogin;
BOOL shared_link;
BOOL folder_upload_email;
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 *by;
const char *direction;
rest = CkRest_Create();
// URL: https://api.box.com/2.0/folders
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_UpdateString(json,"name","Important Docs");
CkJsonObject_UpdateString(json,"parent.id","BOX_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",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");
trashed_at = CkJsonObject_IsNullOf(jsonResponse,"trashed_at");
purged_at = CkJsonObject_IsNullOf(jsonResponse,"purged_at");
content_created_at = CkJsonObject_stringOf(jsonResponse,"content_created_at");
content_modified_at = CkJsonObject_stringOf(jsonResponse,"content_modified_at");
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_link = CkJsonObject_IsNullOf(jsonResponse,"shared_link");
folder_upload_email = CkJsonObject_IsNullOf(jsonResponse,"folder_upload_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);
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jsonResponse,"item_collection.order");
while (i < count_i) {
CkJsonObject_putI(jsonResponse,i);
by = CkJsonObject_stringOf(jsonResponse,"item_collection.order[i].by");
direction = CkJsonObject_stringOf(jsonResponse,"item_collection.order[i].direction");
i = i + 1;
}
CkRest_Dispose(rest);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);
}
{
"type": "folder",
"id": "47885473705",
"sequence_id": "0",
"etag": "0",
"name": "Important Docs",
"created_at": "2018-03-16T06:54:57-07:00",
"modified_at": "2018-03-16T06:54:57-07:00",
"description": "",
"size": 0,
"path_collection": {
"total_count": 1,
"entries": [
{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
}
]
},
"created_by": {
"type": "user",
"id": "2787704945",
"name": "chilkat",
"login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
},
"modified_by": {
"type": "user",
"id": "2787704945",
"name": "chilkat",
"login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
},
"trashed_at": null,
"purged_at": null,
"content_created_at": "2018-03-16T06:54:57-07:00",
"content_modified_at": "2018-03-16T06:54:57-07:00",
"owned_by": {
"type": "user",
"id": "2787704945",
"name": "chilkat",
"login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
},
"shared_link": null,
"folder_upload_email": null,
"parent": {
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
},
"item_status": "active",
"item_collection": {
"total_count": 0,
"entries": [
],
"offset": 0,
"limit": 100,
"order": [
{
"by": "type",
"direction": "ASC"
},
{
"by": "name",
"direction": "ASC"
}
]
}
}