Creating a Directory using the SmartFile API


I am having some difficulty in creating a Directory using the SmartFile API. I have a simple PHP function running that creates the user account (which is working fine):


function createUser($username, $fullname, $role, $home, $email, $password)
    $data = array(
        'username'    => $username,
        'name'        => $fullname,
        'role'        => $role,
        'home'        => $home,
        'email'       => $email,
        'password'    => $password,

$client = new Service_SmartFile_BasicClient(API_KEY, API_PWD);
    $response = $client->post('/user/', $data);

if($response['active'] === TRUE) {
      // create the directory here

return $response;



- but i cannot seem to get the directory (which is $home) to be created. I have looked at this resource - but not sure how theis translates into practical code



14replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • No longer need any advice with this, completed 

    Reply Like
  • In case anyone else stumbles on this question, I'll try to add some useful tidbits.

    Reply Like
  • Hello Ryan, this is great info. Can you clarify the difference between the mkdir and create api endpoints aside that create is being deprecated?

    My current test shows that using both api endpoints works fine with the php sdk. However, I came across this post that makes me wonder if I should use create vs mkdir due to the application cache issue when using ftp. I will eventually use ftp to upload the files as the volume increase. Thanks!

    Reply Like
  • The UI (both classic and new UI) still uses the path/oper/create. It should be safe to use as long as our UI is using it.

    FTP should be ok to use to create directories. It flows through a different process than the api.

    Reply Like
  • Okay, to further clarify... If I use only the api, I should use mkdir because that's newer. If I use both api and ftp, I should use create. Since if I use mkdir via the api, it can cause caching issues when listing folders created with mkdir with ftp? Thanks.

    Reply Like
  • Sounds like it would be so much easier if the caching issue in mkdir got fixed. I'll give that ticket some priority.

    Your summary sounds accurate. At worst the caching issue will only last a day and at best it will last 5 minutes. So, if you intend to create directories and access a day later via ftp, the caching issue is irrelevant.

    (The reason I say a day is because there is a nightly job that rescans the file system for changes.)

    Reply Like
  • Okay, I will use create to have maximum flexibility for both api and ftp access. Thanks for the clarification!

    Reply Like
  • Hi Ryan, as of yesterday mkdir no longer work as intended. I updated the SmartFile php client to latest one on 10/6 but still no luck. Also, I can't find others posting about this issue so was wondering if something has changed on your api side? It used to work just fine until yesterday.

    This is the function I use to create a new directory. Now making the same call to createDirectory, it keep on returning false.

    Can you check if there is anything I have to change on the php client to make it work? This is a strange issue. Thanks.


         * Create new directory. If the directory already exist, it will simply return attributes and
         * info regarding it. Thus, no overwrite or error will be raised.
         * @param $dir
         * @return bool true if successful, false otherwise
         * @throws SmartFileException
        public static function createDirectory($dir)
            $data = array(
                'path' => '/' . $dir
                $response = static::$client->post('/path/oper/mkdir/', $data);
                // check if path is set and equals $dir
                if(isset($response['path']) && strcmp($dir, $response['path']) == 0){
                    return true;
                return false;
            catch(Service_SmartFile_ResponseException $e){
                throw new SmartFileException("Service_SmartFile_ResponseException: " . $e->getMessage());
            catch(Service_SmartFile_RequestException $e){
                throw new SmartFileException("Service_SmartFile_ResponseException: " . $e->getMessage());
    Reply Like
  • Yes, we upgraded the framework behind the api and removed deprecated endpoints.

    Mkdir still works in the UI. Check the response coming back from the server for information about fields not validating properly.
    Reply Like
  • Thanks for the quick response Ryan!

    I see. Well, I grabbed your latest php sdk and changed the api base url to 2.1 and I get the same response of a "/" path when creating a "/test" directory using mkdir.

    I tried mkdir and get this incorrect result. Tried create and get 404. So something is still not right. If I try 2.2 as the api version, I get a 404 not found error. Can you give me example of how to get this to work with your api 2.2? Thanks.

    $api_base_url= '';
    $api_base_url= '';

    called createDirectory("/test")

    createDirectory response:
    [id] => 107924493
    [name] =>
    [path] => /
    [size] => 0
    [items] => 0
    [extension] =>
    [mime] => application/x-directory
    [time] => 2014-10-28T00:44:59
    [isdir] => 1
    [isfile] =>
    [url] => /api/2.1/path/info/
    [attributes] => Array

    [tags] => Array

    [links] => 0
    [remote_status] =>
    [owner] =>
    [acl] => Array
    [read] => 1
    [write] => 1
    [remove] => 1
    [list] => 1

    [has_preview] =>
    Reply Like
  • There is definately a bug in the api due to the upgrade. I have multiple reports of it at this point.

    I know you have the name in the url. However, try posting the name as a field also.

           $data = array(
                'path' => '/' . $dir,
                'name' =. $dir
    Reply Like
  • I just looked at the API code.

    You can also try concatenating it to the request url.

    $response = static::$client->post('/path/oper/mkdir/' . $dir, $data);
    Reply Like
  • I've put a fix into the code base. It will be pushed to production in the next 24 hours.

    Reply Like
  • Great, thanks Ryan. It's working again. Note that I didn't have to make any changes to the createDirectory function. Thanks for the quick fix!!

    Reply Like
Like Follow
  • 5 yrs agoLast active
  • 14Replies
  • 1795Views
  • 3 Following