Hi Team,
I am trying to create an application so that I can read and write files in Box with a Python script.
I chose OAuth 2.0 with Client Credentials Grant, and have flipped between both App Access only and App + Enterprise access. Currently, I have App + Enterprise Access selected. I have checked 'Read all files' and 'Write all files' under Content Actions, and have checked 'Make API calls using the as-user header' and 'Generate user access tokens' under Advanced Features.
url = "https://api.box.com/oauth2/token"
subject_id = '827650880'
subject_type = 'enterprise'
payload=f'client_id={client_id}&client_secret={client_secret}&grant_type=client_credentials&box_subject_type={subject_type}&box_subject_id={subject_id}'
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.request("POST", url, data=payload, headers=headers)
json_response = response.json()
json_response
When I use this code, I get
{'error': 'invalid_grant',
'error_description': 'Grant credentials are invalid'}
I have tried both grant credential types (user and enterprise) with my User and Enterprise IDs. I have also tried pinging the API for authorization_code instead of client_credentials. Could you please provide support on what I am doing wrong and how I can use this method to automatically generate authorization tokens so I can create a process that can read and write files to Box without a user having to approve access each time and enter the auth_code?