Uploading File to Box using API through OAUTH2 with JWT
Hey, I want to upload the file to the root folder and subfolder from my box using a script. For this, I used the box API.
For authorization, I used authentication with the JWT approach following this link and then following it up further:
https://developer.box.com/docs/authentication-with-jwt
Using this, When I make an upload request to the root folder(folder_id=0), the file gets uploaded successfully but not able to see on UI. And when file uploaded to subfolder getting error 'Context info: {'errors': [{'message': "Invalid value 'd_5***phone number removed for privacy***'. 'parent' with value 'd_5***phone number removed for privacy***' not found", 'name': 'parent', 'reason': 'invalid_parameter'}]}'. Can someone help me upload the file to the root folder and subfolder?
This is my code:
from boxsdk import JWTAuth
from boxsdk import Client
sdk = JWTAuth(
client_id=MY_CLIENT_ID,
client_secret=MY_CLIENT_SECRET,
enterprise_id=MY_ENTERPRISE_ID,
jwt_key_id=MY_JET_KEY_ID,
rsa_private_key_file_sys_path=PATH_TO_RSA_PRIVATE_KEY,
rsa_private_key_passphrase=str.encode(MY_RSA_KEY_PASSPHRASE)
)
client = Client(sdk)
access_token = sdk.authenticate_instance()
# Failing with error 'Context info: {'errors': [{'message': "Invalid value 'd_51215348811'. 'parent' with value 'd_51215348811' not found", 'name': 'parent', 'reason': 'invalid_parameter'}]}'
upload_to_subdirectory = client.folder("***number removed for privacy***11").upload(MY_FILE_PATH, FILENAME)
# Here file gets uplaoded successfully, but not shown on UI
upload_to_root_directory = client.folder("0").upload(MY_FILE_PATH, FILENAME)
-
When you're using JWT, the token it "defaults" to using is that of the service account. Do you know who your token is associated with? When you say you're uploading something and then not seeing it in the UI, are you looking in your own folder structure? If so, this is expected behavior. You can only view the folder tree of the service account by going to the admin console and using the content manager. Use the search bar to search for your application name!
Please sign in to leave a comment.
Comments
1 comment