Error in getting Access Token through command line

New Contributor

Error in getting Access Token through command line

Created an app in developer console. Using that access token from that app to upload/download files from box. But, the access token expires every 60 mins and I want to generate the access token every 59 mins and use it for my command to upload/download files. I'm trying to use the below command to generate the access token:

curl https://api.box.com/oauth2/token \
-d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \
-X POST
The output of the command says that "{"error":"invalid_client","error_description":"The client credentials are invalid"}". I am using the client_id and client_secret from the app that I created. your_code in the above command is my old Access token I hope. I'm not sure what I'm missing here. Do I need to use the refresh token to generate Access token? if so, how should I get refresh token in command line?

3 REPLIES
Box Certified Professional

Re: Error in getting Access Token through command line

Hey @ppamidi,

 

You'll have better luck on this post over at the Box Developer Forum. This forum is mostly end users and admins.

 

Best of luck,

 

Bob

Indiana University
University Information Technology Services
New Contributor

Error in getting Access Token through command line

Created an app in developer console. Using that access token from that app to upload/download files from box. But, the access token expires every 60 mins and I want to generate the access token every 59 mins and use it for my command to upload/download files. I'm trying to use the below command to generate the access token:

curl https://api.box.com/oauth2/token \
-d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \
-X POST
The output of the command says that "{"error":"invalid_client","error_description":"The client credentials are invalid"}". I am using the client_id and client_secret from the app that I created. your_code in the above command is my old Access token I hope. I'm not sure what I'm missing here. Do I need to use the refresh token to generate Access token? if so, how should I get refresh token in command line?

Highlighted
First-time Contributor

Re: Error in getting Access Token through command line

He's not alone, we are in the very same situation.

We installed this so called API.

We can call box configure environments add then get enviro-conf and successfully delete the enviro-conf, which proves we succeed in establishing part of the connection.

But when we try box tokens get... "The API returned an error [BadRequest].

 

We tried using curl, which we shouldn't have to if this "API" did the job.

 

All tutorials we found use web interface, but this is NOT an option here.

 

So, let's put it simply.

At the point we stand, we have:

- the client_id

- the client_secret

- a public key ID

- an enterprise ID

We have no:

- code

- bearer

- token

After adding the enviro-conf from a simple command window, what other box-only command lines will be required in order to:
- actually be logged onto our ...box.com/folder/0

- recurse in our box tree

- check for folder/file existence

- create/remove folder

- upload/replace file

?

Some command-line only tutorials, step-by-step for dummies, would be welcome!