Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

How To Use Box CLI API Command to Search for folder by exact name

New post

Comments

1 comment

  • Rui Barbosa

    Hi Timothy,

    I'm wondering if you really have the enterprise content flag turned on.

    Anyway if you know who owns the content then the as-user flag should work for you.

    Consider the following JWT app user associated with the CLI:

    ❯ box users:get --fields id,name --csv
    type,id,name
    user,20130487697,JWT

    And the as-suer I'm looking for is:

    ❯ box users --fields type,id,name --csv
    type,id,name
    ...
    user,18622116055,Rui Barbosa

    And I'll be searching for these folders:

    ❯ box folders:items 191494027812 --csv --fields type,id,name,parent --as-user=18622116055
    type,id,name,parent.type,parent.id,parent.sequence_id,parent.etag,parent.name
    folder,192444166451,Audio,folder,191494027812,2,2,Media Samples
    folder,192444586290,Images,folder,191494027812,2,2,Media Samples
    folder,192442970500,Video,folder,191494027812,2,2,Media Samples

    So a simple search will work like this:

    ❯ box search "Media Samples" --type folder --fields type,id,name --csv --as-user 18622116055
    type,id,name
    folder,191494027812,Media Samples
    folder,165803865043,Preview Samples

    And for an exact match we do:

    ❯ box search "\"Media Samples\"" --type folder --fields type,id,name --csv --as-user 18622116055
    type,id,name
    folder,191494027812,Media Samples

    Now if I run this using the owner:

    ❯ box search "Media Samples" --type folder --fields type,id,name --csv --as-user 18622116055 --owner-user-ids 18622116055
    type,id,name
    folder,191494027812,Media Samples
    folder,165803865043,Preview Samples

    It still works, because it is still consistent with the as-user. However if if I remove the as-user the results come back empty:

    ❯ box search "Media Samples" --type folder --fields type,id,name --csv  --owner-user-ids 18622116055

    The service user associated with the JWT authentication for this CLI has these configurations:

    • Enterprise access
    • All content actions (read/write all files)
    • All administrative actions
    • Make API calls using the as-user header
    • Generate user access token

    However the content permissions, in a "normal" situation, still apply, meaning if the owner user did not explicitly give permissions to the CLI user, the CLI user is not going to find the content. This CLI service user does have the capability of impersonating another user that it can see on the box users command.

    Think of the as-user flag as which user is the CLI impersonating, and the owner-user-ids as and additional filter for what the security context already has access to, meaning the owner-users-ids will not give the CLI user greater access.

    By "normal" I mean without the enterprise_content flag turned on. This is unusual and requires a support ticket to be turned on, hence my starting question.

    If you did request the enterprise content to be turned on, please do open a support ticket for further investigation. 

     

     

    0
    Comment actions Permalink

Please sign in to leave a comment.