Box File Request API
AnsweredHello,
I've been trying for weeks to get the new File Request API working. I'm using the Python SDK and my app is configured with JWT. For now, I'm just using the Python SDK to generate the bearer access token and putting it into Postman.
When I use the SDK generated bearer access token, the server returns a 500 error. However, if I make the exact same call using a Dev Token from the Dev Console it returns the file request as expected. I do, however, know that the bearer token I generate via the SDK is valid because if I use it to make any other call (get folder info, for example), it works as expected. The issue is only when making a call to https://api.box.com/2.0/file_requests/FILE_REQUEST_ID.
Thanks in advance.
-
Hey Kevin,
Hmm that's very strange. I'll need some details in order to further troubleshoot. If you're comfortable providing more information here, I'll need:
- App's client ID
- Date/time/timezone of an example 500
- File ID you were trying to generate this file request for
Alternately, you can open a support ticket with the information above.
Best,
Kourtney, Box Developer Advocate
-
Hi,
For what it's worth, I can confirm the same problem (internal server error when trying to copy a file request with primary access token, but it works with a dev token):
App client ID zld8nzl5kya1us4va23nb51mhcnsl7we
Timestamp Thu, 18 Feb 2021 19:48:22 GMT
File request ID 636458360
Thanks for looking into this issue,
Michael
-
Hey Kevin,
Apologies on the delay getting back to you. I believe I was just able to reproduce the behavior you're seeing and have connected with the assigned agent to go ahead and open a bug ticket with our engineering team. To ensure we cover all of our bases and get this addressed for you as quickly as possible you may also want to open an issue directly to the Github repository.
Best,
Kourtney, Box Developer Advocate
-
No, not resolved. But here's the code:
from boxsdk import JWTAuth
import requests
import json
f_req_id = "599230332" # File request template ID
folder_id = "126334743164" # Folder ID to apply file request template
config = json.load(open("production_config.json"))
box_auth = JWTAuth.from_settings_file("production_config.json")
access_token = box_auth.authenticate_instance()
req_data = {"folder": {"id": folder_id, "type": "folder"}}
url = "https://api.box.com/2.0/file_requests/" + f_req_id
headers = {"Authorization": f"Bearer {access_token}"}
payload = json.dumps(req_data)
session = requests.Session()
response = session.post(url=url, data=payload, headers=headers)
print(response.content) -
@Kevin Ford, I was able to get this working. The file request I'm trying to access was not loaded by the service account but by a user. In all other instances this has happened I've had to use the as-user functionality in the API. This turned out to be the same issue here, I had to generate a user token and that worked. Code below. I hope this helps you!
from boxsdk import JWTAuth, Client
import requests
config = JWTAuth.from_settings_file("config.json")
client = Client(config)
as_user_id = '123456789'
user = client.user(user_id=as_user_id)
access_token = config.authenticate_user(user)
Please sign in to leave a comment.
Comments
12 comments