2

I made a GET request to airtable table, but with the right key and right url he give me the 401 (Unauthorized) error.

fetch("https://api.airtable.com/...")
            .then(response => response.json())
            .then(data => {
                console.log(data)
            })
            .catch(error => console.error(error))

3 Answers3

0

Are you using an encoded URL for the request? Check out this tool it will help set the URL correctly for GET request

[https://codepen.io/airtable/full/rLKkYB][1]

Also are you using the Airtable.js npm package?

Nick Cappello
  • 341
  • 3
  • 12
  • initially i made with the GET request, but these request give me only the first line of records, so i see the API documentation for list request and i put the right url with the right key, but the response is 401 (Unauthorized) every time. I'm not using airtable .js – michele banfi Sep 09 '18 at 10:02
  • Ok, can you post a little more of the code that you have? – Nick Cappello Sep 10 '18 at 11:00
  • function gg() { fetch("https://api.airtable.com/v0/appkpmjhrpinXDDSn/Table%201? maxRecords=3&view=Grid%20view?api_key=key...") .then(response => response.json()) .then(data => { console.log(data) }) .catch(error => console.error(error)) } – michele banfi Sep 10 '18 at 16:56
  • Did this help you at all and slove the issue? – Nick Cappello Sep 26 '18 at 05:04
0

401 Unauthorized Accessing a protected resource without authorization or with invalid credentials.

You are not validating the API key which prevents you from getting the authorization

var Airtable = require('airtable');
Airtable.configure({
    endpointUrl: 'https://api.airtable.com',
    apiKey: 'keyxxxxx'
});
var base = Airtable.base('');
Nick Cappello
  • 341
  • 3
  • 12
0

You need to confirm Airtable API Key and Airtable base key.

fetch("https://api.airtable.com/v0/appXXXXXXXXXXXXXX/Resources?api_key=keyXXXXXXXXXXXXXX")
    .then(response => response.json())
    .then(data => {
        console.log(data)
    })
    .catch(error => console.error(error))
Blueshark
  • 41
  • 3