Android™ Dropbox: Dropbox Create Folder

Back to Index

Create a folder. Creates the folder /Halloween/emojis

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

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/create_folder_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Halloween/emojis\",\"autorename\": false}"

Android™ Example

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://api.dropboxapi.com/2/files/create_folder_v2
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("api.dropboxapi.com",port,bTls,bAutoReconnect);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    //  See the Online Tool for Generating JSON Creation Code
    CkJsonObject json = new CkJsonObject();
    json.UpdateString("path","/Halloween/emojis");
    json.UpdateBool("autorename",false);

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

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestSb("POST","/2/files/create_folder_v2",sbRequestBody,sbResponseBody);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
        Log.i(TAG, "Response Header:");
        Log.i(TAG, rest.responseHeader());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.LoadSb(sbResponseBody);

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

    String metadataName = jsonResponse.stringOf("metadata.name");
    String metadataId = jsonResponse.stringOf("metadata.id");
    String metadataPath_lower = jsonResponse.stringOf("metadata.path_lower");
    String metadataPath_display = jsonResponse.stringOf("metadata.path_display");
    boolean metadataSharing_infoRead_only = jsonResponse.BoolOf("metadata.sharing_info.read_only");
    String metadataSharing_infoParent_shared_folder_id = jsonResponse.stringOf("metadata.sharing_info.parent_shared_folder_id");
    boolean metadataSharing_infoTraverse_only = jsonResponse.BoolOf("metadata.sharing_info.traverse_only");
    boolean metadataSharing_infoNo_access = jsonResponse.BoolOf("metadata.sharing_info.no_access");
    i = 0;
    count_i = jsonResponse.SizeOfArray("metadata.property_groups");
    while (i < count_i) {
        jsonResponse.put_I(i);
        String template_id = jsonResponse.stringOf("metadata.property_groups[i].template_id");
        j = 0;
        count_j = jsonResponse.SizeOfArray("metadata.property_groups[i].fields");
        while (j < count_j) {
            jsonResponse.put_J(j);
            String name = jsonResponse.stringOf("metadata.property_groups[i].fields[j].name");
            String value = jsonResponse.stringOf("metadata.property_groups[i].fields[j].value");
            j = j + 1;
            }

        i = i + 1;
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Sample JSON Response Body

{
  "metadata": {
    "name": "emojis",
    "id": "id:a4ayc_80_OEAAAAAAAAAXz",
    "path_lower": "/halloween/emojis",
    "path_display": "/Halloween/emojis",
    "sharing_info": {
      "read_only": false,
      "parent_shared_folder_id": "84528192421",
      "traverse_only": false,
      "no_access": false
    },
    "property_groups": [
      {
        "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
        "fields": [
          {
            "name": "Security Policy",
            "value": "Confidential"
          }
        ]
      }
    ]
  }
}