How do I download files using a User Token instead of an Application Token?

  • 0
  • 1
  • Question
  • Updated 6 months ago
  • In Progress
Hello. I sometimes write scripts that manipulate QuickBase record attachments from outside of quickbase. Usually just like a "curl" request from the command line.
In the past the instructions outlined here have worked very well. I just get an API ticket from API_Authenticate (using my username and password):,

https://mysite.quickbase.com/db/main?a=API_Authenticate&username=me@mysite.org&password=XXXXXXXXXX

then run a command like this from the terminal:

curl https://mysite.quickbase.com/up/XXXXXXXXX/a/rXXXXX/eXX/v0?ticket=<authentication_ticket_from_API_Authenticate> > Desktop/mydownload.pdf

And the file in question appear in mydownload.pdf on my Desktop

BUT HERE'S THE PROBLEM: I'm trying to use User Tokens now, since they're just much nicer and easier to keep track of, but as far as I can tell there is no way to get an authentication ticket when exclusively using User Tokens for authentication. For example, running something like:

https://mysite.quickbase.com/up/XXXXXXXXX/a/rXXXXX/eXX/v0?usertoken=<my_user_token>

gives me a message that "User token is invalid" (despite the fact that it is a known working user token). Running the following API_Authenticate call in order to try to get a ticket from the user token:

https://mysite.quickbase.com/db/main?a=API_Authenticate&usertoken=<my_user_token>

gives me the following error:

<qdbapi>

  <action>API_Authenticate</action>
  <errcode>3</errcode>
  <errtext>Insufficient permissions</errtext>
  <errdetail>You don't have sufficient permissions to access that page. User Tokens cannot be used to call this API</errdetail>
  <username>me</username></qdbapi>

And this is a token that is associated with an account that has full access to the app, so I am confident it's not a permissions thing.

Are there any potential workarounds to this?
Photo of Shaund Grey

Shaund Grey

  • 80 Points 75 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,978 Points 1k badge 2x thumb
I think you need to create an apptoken. 
http://help.quickbase.com/user-assistance/#app_tokens.html
Photo of Shaund Grey

Shaund Grey

  • 80 Points 75 badge 2x thumb
I have tried that - when I run this:

https://mysite.quickbase.com/up/XXXXXXXXX/a/rXXXXX/eXX/v0?apptoken=my_apptoken

It just takes me to a quickbase sign-in page. When I try to get an application ticket using an apptoken, like so:

https://mysite.quickbase.com/db/main?a=API_Authenticate&apptoken=my_apptoken

I get an error message telling me that I "must specify a valid username and password or a valid ticket to use API_Authenticate"
(Edited)
Shaund,
User tokens are a substitute for authentication, as well as the apptoken.  You need to assign the user token to the app you want to access. You don't need to authenticate to the app to use api calls - as long as you have the user token in the parameters...
Here's a complete write up on user tokens:
https://help.quickbase.com/api-guide/create_user_tokens.html
Good luck..
Neil
Photo of Shaund Grey

Shaund Grey

  • 80 Points 75 badge 2x thumb
Thank you. I've checked, and I do indeed have the user token assigned to the app that i want to download files attachments from.

Now that I have that, how do I download files from the app using it?
Photo of Daniel

Daniel

  • 178 Points 100 badge 2x thumb
I can confirm that the usertoken query param does work when using the URL for a file attachment returned from a doQuery operation.

Not sure this helps for your use case.