404 when trying to get BoxFolder.Info or BoxFile.Info (JWT authentication)

New post

Comments

21 comments

  • kendomen

    Is your client_id "As-User" enabled?

    0
    Comment actions Permalink
  • bmantoni

    It wasn't, but I just enabled "Perform actions on behalf of users" and still get the 404.

     

    I'm using the getAppEnterpriseConnection, is that right? (as opposed to getAppUserConnection)

     

    Do I need to do anything differently in my code to do this As-User?

    0
    Comment actions Permalink
  • kendomen

    I usually get a 404 when I tried to make a BoxFile from a folder_id or the other way around.

    Can you share your code and I'll try running it here?

    0
    Comment actions Permalink
  • bmantoni

    Sure:

     

    EventLog eventLog = getDownloadEvents();

    while (eventLog.getSize() > 0) {
    for (BoxEvent event : eventLog) {
    String itemId = event.getSourceJSON().get("item_id").asString();
    String itemName = event.getSourceJSON().get("item_name").asString();

    BoxFile file = new BoxFile(api, itemId);
    BoxFile.Info info = file.getInfo();

    and:

    private EventLog getDownloadEvents() {
    Date from = new DateTime(new Date()).minusDays(MAX_DAYS).toDate();
    Date to = new DateTime(new Date()).plusDays(1).toDate();
    return EventLog.getEnterpriseEvents(api, from, to, BoxEvent.Type.DOWNLOAD);
    }

     Using api I get like so:

    api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(
    config.getBoxEnterpriseId(), config.getClientId(), config.getClientSecret(), jwtEncryptionPreferences, accessTokenCache); 

    Thanks for the help! 
    Edit

    I surrounded the lines where I get the info an an if statement to make sure the item is actually a BoxFile and not a BoxFolder, and still get the 404:

    {"type":"error","status":404,"code":"not_found","context_info":{"errors":[{"reason":"invalid_parameter","name":"item","message":"Invalid value 'f_44403940033'. 'item' with value 'f_44403940033' not found"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Not Found","request_id":"removed for privacy7583c5d83d6e43"}

    0
    Comment actions Permalink
  • kendomen

    I've gotten a 404 when the user has not accepted terms of acceptance but there wasn't a way for me to find the true error using the box-java-sdk.  I had to get the file id where the error occurred and run it in postman.

     

    curl https://api.box.com/2.0/files/FILE_ID
    -H "Authorization: Bearer ACCESS_TOKEN"
    0
    Comment actions Permalink
  • bmantoni

    It comes back 404 for all files. Many of these users have definitely accepted Ts&Cs as they're day-to-day users.

     

    You don't see any issue with me using the "enterprise" connection rather than this user-based connection? I'm not creating an app user - just using the enterprise connection.

    0
    Comment actions Permalink
  • kendomen

    I think you're on to something.

     

    The enterprise events expects an admin user to run it.  So I tested with a non-JWT api and it worked just fine.

    But when I use JWT and print out the current user, I get some odd user.

     

    BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(
                    ENTERPRISE_ID, CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);
            
            Date beginDate = new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 2));
            Date endDate = new Date(System.currentTimeMillis());

            BoxUser user = BoxUser.getCurrentUser(api);
            System.out.println("Name: " + user.getInfo().getName());
            System.out.println("Login: " + user.getInfo().getLogin());

            EventLog eventLog = EventLog.getEnterpriseEvents(api, beginDate, endDate, BoxEvent.Type.DOWNLOAD);

    Output:

    Name: KenJWT
    Login: ***@example.com
    com.box.sdk.BoxAPIException: The API returned an error code: 403

    0
    Comment actions Permalink
  • recordpointfree

    I am also getting this problem.

     

    Trying to get the information on a file upload from an event in the EnterpriseEvents

    GET /2.0/files/20***phone number removed for privacy***HTTP/1.1
    Host: api.box.com
    Authorization: Bearer xxx(AdminAccount)


    Response

    {
        "type": "error",
        "status": 404,
        "code": "not_found",
        "context_info": {
            "errors": [
                {
                    "reason": "invalid_parameter",
                    "name": "item",
                    "message": "Invalid value 'f_20***phone number removed for privacy***'. 'item' with value 'f_20***phone number removed for privacy***' not found"
                }
            ]
        },
        "help_url": "http://developers.box.com/docs/#errors",
        "message": "Not Found",
        "request_id": "***number removed for privacy***6598a9c32461ce"
    }

    It must be a bug I think.

     

    0
    Comment actions Permalink
  • JoeWarwick

    we have exactly the same issue.

    0
    Comment actions Permalink
  • AdamHavas

    I'm having the same problem. Error 404. But when I connect using the DEVELOPER_TOKEN it works fine.

    0
    Comment actions Permalink
  • eallan

    I am having the exact same problem, error 404 when trying to upload a file using JWTAuth. But successfully upload files to a folder when using the Developer_token and OAUTH2.0, same as AdamHavas above.

    0
    Comment actions Permalink
  • maddy0139

    i was also having the same issue. after lots of efforts i have finally got the result.

    while authenticating using JWT you should generate token for an user not an Application.

     Please see below code which is returning me my folder details.

     

    using System;
    using System.ComponentModel;
    using System.IO;
    using System.Threading.Tasks;
    using Box.V2.Config;
    using Box.V2.JWTAuth;
    using Box.V2.Models;
    
    namespace BoxExample
    {
        class Program
        {
            static void Main(string[] args)
            {
                string path = Environment.CurrentDirectory+ "\\Files\\47637819_mlfpfwfj_config.json";
    
                IBoxConfig config = null;
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    config = BoxConfig.CreateFromJsonFile(fs);
                }
                try
                {
                    methodAsync(config).Wait();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    /* The exception will be caught because you've
                       waited for the completion of the call. */
                }
    
            }
    
            static async Task methodAsync(IBoxConfig config)
            {
                BoxFolder folder = null;
                try
                {
                    // Create JWT auth using config file
                    var userId = "user id";
                    var session = new BoxJWTAuth(config);
                    var userToken = session.UserToken(userId);
    
                    //var adminToken = boxJWT.AdminToken();
                    var client = session.AdminClient(userToken);
    
    
                    folder = await client.FoldersManager.GetInformationAsync("folder id");
                    
    
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                return folder;
    
            }
        }
    }
    0
    Comment actions Permalink
  • theasteve

    Where you set this?

    0
    Comment actions Permalink
  • mchuecos1

    I have the same problem:

     

    com.box.sdk.BoxAPIResponseException: The API returned an error code [404 | drpqvtg2cliujvby] not_found - Not Found

     

    Any solution?

     

    Thanks

    0
    Comment actions Permalink
  • dzlabs

    I got same error even when trying through a user connection like this (scala using java sdk)

    val MAX_CACHE_ENTRIES = 100
    val accessTokenCache: IAccessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES)
    val boxConfig = new InputStreamReader( new FileInputStream( path ) )
    val conn = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache)
    
    val params = new CreateUserParams
    params.setSpaceAmount(1048576) // 1 MB
    val user = BoxUser.createAppUser(connection, APP_USER_NAME, params)
    
    var api = client.getUserConnection(user.getID)
    
    val file: BoxFile = new BoxFile(api, FILE_ID)
    val output = new ByteOutputStream()
    file.download(output)

     

    Here is error:

     

    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    Exception in thread "main" com.box.sdk.BoxAPIResponseException: The API returned an error code [404 | dvelsag7qd1cv6al.04a0f50840a05a124d47cf37b065dcd94] not_found - Could not find the specified resource
    at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:92)
    at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:32)
    at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:582)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:354)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:329)
    at com.box.sdk.BoxFile.download(BoxFile.java:297)
    at com.box.sdk.BoxFile.download(BoxFile.java:285)
    at dz.lab.box.ReadFileAsUser$.main(ReadFileAsUser.scala:30)
    at dz.lab.box.ReadFileAsUser.main(ReadFileAsUser.scala)

    0
    Comment actions Permalink
  • dzlabs

    I managed to read the file using the shared link as follows (it may be helpful in your case):

    val enterpriseApi = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache)
    
    // Read File Metadata
    val sharedLink = "......"
    val info = BoxItem.getSharedItem(enterpriseApi, sharedLink)
    
    println(s"File ID: ${info.getID}, Owener ID: ${info.getOwnedBy().getID} and name ${info.getOwnedBy().getName}")
    
    // Create a connection as the File owner
    val api = BoxDeveloperEditionAPIConnection.getAppUserConnection(info.getOwnedBy().getID, boxConfig)
    println(s"enterprise token ${client.connection.getAccessToken}, user token is ${api.getAccessToken}")
    
    // Read file as user
    val file: BoxFile = new BoxFile(api, info.getID)
    val output = new ByteOutputStream()
    file.download(output)
    println(new String(output.getBytes))
    0
    Comment actions Permalink
  • hsharma

    I'm also facing the issue while downloading the file from Box folder:

    Am I doing anything wrong here? Can anyone point me in the right direction?

     

    from boxsdk import JWTAuth

    from boxsdk import Client

     

    box_config = { "boxAppSettings": { "clientID": "xxxxx", "clientSecret": "xxxxx", "appAuth": { "publicKeyID": "xxxxx", "privateKey": "-----BEGIN ENCRYPTED PRIVATE KEY-----XXXXX-----END ENCRYPTED PRIVATE KEY-----\n", "passphrase": "xxxxx" } }, "enterpriseID": "xxxxx", "webhooks": { "primaryKey": "xxxxx", "secondaryKey": "xxxxx" } }

    auth = JWTAuth.from_settings_dictionary(box_config)

    client = Client(auth)

    user = client.user().get()

    me = client.user("xxxxx").get()

    try:

    file_id = 'xxxxx'

    file_content = client.as_user(user).file(file_id).content()

    except Exception as e:

    print("USER Failed")

    print(e)

    0
    Comment actions Permalink
  • mv891433

    Hello, I'm facing the problem when trying to upload a file.  But when using app token works perfectly.

     

    0
    Comment actions Permalink
  • Trinitron

    Hi folks,  When you created JWT app - it means you making api calls from complete different user! (at least it was not clear for me). And this api service user (AutomationUser_921....[at]boxdevedition.com) has different folder visibility level.  Go to this page https://app.box.com/master/content  You will find one admin and one app user there.  Here you can login as app user and look through the folders your api has access to.

    0
    Comment actions Permalink
  • mv891433

    Thanks for the information, I will check it.

     

    Regards

    0
    Comment actions Permalink
  • Sreekandan Natarajan

    I'm also having the similar issues , i was able to download the files and folder using developer token, but when i use the JWT i'm facing the 404 error.Please let me know you have any solution 

    0
    Comment actions Permalink

Please sign in to leave a comment.