Authentication and file upload
Hi,
I am attempting to make a script using the .NET SDK that will automatically login and upload a file when run. I am having trouble understanding how to get JWT with OAuth working. I've used the dev token successfully to test my code, but can't seem to figure out the proper way to use the client created with Adminclient and the JSON Config file. Should I be making an As-User to be able to call Filesmanager.uploadasync()? Below is my code. I get the same error when using a service account client and an App User.
Here is the error I am receiving:
exception when uploading: Box.V2.Exceptions.BoxException: The API returned an error [NotFound | 1xzugdfv55z9c2d5] not_found - Not Found
at Box.V2.Extensions.BoxResponseExtensions.ParseResults[T](IBoxResponse`1 response, IBoxConverter converter)
at Box.V2.Managers.BoxResourceManager.ToResponseAsync[T](IBoxRequest request, Boolean queueRequest)
at Box.V2.Managers.BoxFilesManager.UploadAsync(BoxFileRequest fileRequest, Stream stream, IEnumerable`1 fields, Nullable`1 timeout, Byte[] contentMD5, Boolean setStreamPositionToZero, Uri uploadUri)
Any help is appreciated, thanks!
// Read in config file IBoxConfig configJWT = null; using (FileStream fs = new FileStream(@"mypath", FileMode.Open)) { configJWT = BoxConfig.CreateFromJsonFile(fs); } // Create JWT auth using config file var boxJWT = new BoxJWTAuth(configJWT); // Create admin client var adminToken = boxJWT.AdminToken(); BoxClient clientJWT = boxJWT.AdminClient(adminToken); // Make API calls/work with files try { newFile = await appUserClient.FilesManager.UploadAsync(req, stream); } catch(BoxException bex) { }
-
I'm having the exact same issue.
Although if I specify a folder ID of 0 (root) the uploadAsync indicates that it runs successfully, yet my files do not appear in the root folder when I look using the web client.
I'm assuming some sort of permissions issue, but looking at the options available I cannot figure out what to change to grant the appropriate permissions.
-
Here's a response I received when asking the same question on GitHub:
It looks like the issue you’re seeing is related to the app user not having access to the folder you’re trying to upload, rather than an authentication problem. Each app user is it’s own separate account, and does not start with any folders in it. Where did the folder you’re trying to upload into get created?
I guess the key is that when you create an app user, it does not natively have access to other accounts. Maybe the key is to implement the as-user functionality.
-
That's the path I started down yesterday.
Providing my userid to the asUser field in adminClient
var adminToken = boxJWT.AdminToken();
var client = boxJWT.AdminClient(adminToken, asUser: "***number removed for privacy***");I'm now stuck at a new exception:
+ InnerException {Box.V2.Exceptions.BoxException: The API returned an error [Forbidden | jxtzckfv74ryya3l] access_denied_insufficient_permissions - Access denied - insufficient permission
at Box.V2.Extensions.BoxResponseExtensions.ParseResults[T](IBoxResponse`1 response, IBoxConverter converter)
at Box.V2.Managers.BoxResourceManager.ToResponseAsync[T](IBoxRequest request, Boolean queueRequest)
at Box.V2.Managers.BoxFoldersManager.GetInformationAsync(String id, IEnumerable`1 fields)
I'm currently trying to work through https://community.box.com/t5/Developer-Troubleshooting/API-Content-API-403-quot-access-denied-insufficient-permissions/ta-p/48536 to see if I'm missing anything in order to have correct permissions.
Please sign in to leave a comment.
Comments
4 comments