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

How to get a Downscoped Token for a file or folder

New post

Comments

4 comments

  • jcleblanc

    Hi ,

     

    I believe this is due to the resource that you're using. Box uses standard resource identifiers for files and folders, which looks like this:

     

    https://api.box.com/2.0/{FILES OR FOLDERS}/{RESOURCE-ID}

     

    So this is what it might looks like for a file example and folder example:

    String fileResource = "https://api.box.com/2.0/files/12345";
    String folderResource = "https://api.box.com/2.0/folders/67890";

     

    Here's an example of that in the Java SDK docs. 

     

    Let me know if you run into any issues,

    Jon

    0
    Comment actions Permalink
  • dzlabs

    Still running into The API returned an error code [400] invalid_resource - The target resource is invalid.

    Just to give more context, the file i'm trying to read is publicaly availalble to anyone with the sharing link, also the connection i'm using is a service account connection created as follow:

    val MAX_CACHE_ENTRIES = 100
    val boxConfig = BoxConfig.readFrom( new InputStreamReader( new FileInputStream( path ) ) )
    val accessTokenCache: IAccessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES)
    val api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache)
    api.setExpires(600000)
        

    I've been struggling to understand I could read such shared files from within an application!

    0
    Comment actions Permalink
  • Kourtney

     

     

    Would you be able to share the following: 

     

    • Client ID of your application (found in the config tab of the dev console) 
    • Full body response of the error 
    • Example date/time/timezone of the error 

    Alternatively, you can open a support ticket a support.box.com. We can take a look in our backend logs to get some more information on what's going on here! 

     

    Best, 

    Kourtney 

    Box Technical Support Engineer

    0
    Comment actions Permalink
  • dbachowski

    I'm receiving the exact same error with the Python SDK. This works:

    token_info = client.downscope_token(..., item=None)

     But this does not:

    folder = client.folder(folder_id='12345678')
    token_info = client.downscope_token(..., item=folder)

     

    0
    Comment actions Permalink

Please sign in to leave a comment.