Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAT instead of API key #9

Open
timothoms opened this issue Jan 23, 2023 · 9 comments
Open

PAT instead of API key #9

timothoms opened this issue Jan 23, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@timothoms
Copy link

Airtable is phasing out API keys by next year, eventually making users migrate to Personal Access Tokens (PATs). Can the set_airtable_api_key() function be used with PATs? If not, will there be a new function for this? Thanks!

@matthewjrogers
Copy link
Owner

matthewjrogers commented Jan 23, 2023

Hey there @timothoms -- thanks for bringing this to my attention!

I'm not sure if they use (or will use) PATs in the same manner as they currently use the API key. Right now, the API key stored by set_airtable_api_key() is passed to an Authorization header in the relevant GET/POST/PATCH/DELETE request. If PATs are going to be expected differently, I'll have to make some changes to keep set_airtable_api_key() compliant. I took a quick look at the API documentation and don't see anything yet.

When there's a clear path forward, I'll likely deprecate set_airtable_api_key() in favor of a new function. My guess is that the major functionality it will need is improved error handling, as it'd be easy to have permissions errors related to PAT scope the the current function might not surface in a helpful way.

@matthewjrogers matthewjrogers added the enhancement New feature or request label Jan 23, 2023
@timothoms
Copy link
Author

Great, thanks! Might be useful to keep set_airtable_api_key() until Airtable deprecates it in Jan 2024.

Does this documentation help?: https://airtable.com/developers/web/api/authentication

@matthewjrogers
Copy link
Owner

That's perfect, I hadn't seen that. That confirms that the tokens and api keys are used in the same way, so the set function will actually work as-is, though I think there should be a PAT-specific function for clarity

I'm thinking that the cadence for retiring set_airtable_api_key() would be

  1. Add deprecation warnings to set_airtable_api_key() and release a new set_airtable_pat function
  2. End of 2024, remove set_airtable_api_key

Since the PATs have scope limitations, it seems like it might be useful to have a means of storing more than one PAT and being able to select between them.

@timothoms
Copy link
Author

That sounds great, and seems the right way to go. I will try out the set_airtable_api_key()with a new PAT. (And will report back if it doesn't work as expected.) Thanks.

@coreysparks
Copy link

coreysparks commented Feb 16, 2024

@timothoms did you get this to work with a PAT? If so, could you share how you did it?

@timothoms
Copy link
Author

@timothoms did you get this to work with a PAT? If so, could you share how you did it?

Yes, this worked as a drop-in replacement for me. I created a PAT with the scope "data.records:read" and then set it once with

set_airtable_api_key("MY_NEW_PAT_HERE", install = TRUE)

If you want to immediately use it, you need to

readRenviron("~/.Renviron")

Otherwise, restarting R should do it. You can check with

Sys.getenv("AIRTABLE_API_KEY")

@coreysparks
Copy link

Thanks!
I'm getting an error, my setup looks like
`test <-
airtable(
base = "app*************",
table = c("Table Name")
)

read_airtable(test,id_to_col = T )
`
The error is
Error in read_airtable(test, id_to_col = T) :
Unauthorized (HTTP 401). Failed to Fetch Airtable records.

@timothoms
Copy link
Author

Thanks! I'm getting an error, my setup looks like `test <- airtable( base = "app*************", table = c("Table Name") )

read_airtable(test,id_to_col = T ) ` The error is Error in read_airtable(test, id_to_col = T) : Unauthorized (HTTP 401). Failed to Fetch Airtable records.

The R code looks correct to me, but there is an authorization issue. The error message indicates that the authentication token is invalid (see this). I'm guessing the problem is on the Airtable side, either the scope or access of the PAT is incorrect, or the user is not allowed the action, though the latter seems unlikely for just reading data.

@coreysparks
Copy link

I've asked someone else on my team and it may be because our airtable is behind Okta, thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants