I am trying to send a get request to Airtable to get metadata but I keep getting errors.
I have tried the below.
base_schema_url = 'https://api.airtable.com/v0/meta/bases/BaseId(replaced this)/tables'
secret_meta_token = '123'
#attempt 1
r = requests.get(base_schema_url, headers={'Authorization': secret_meta_token})
print(r.text)
#attempt 2
r = requests.get(base_schema_url,
headers={'Content-Type':'application/json',
'Authorization': 'Bearer {}'.format(secret_meta_token)})
print(r.text)
#attempt 3
header = {'PRIVATE-TOKEN': secret_meta_token}
r = requests.get(base_schema_url, headers=header)
print(r.text)
I have a feeling it's because I need to pass in the user API + the Meta token but I'm not too sure how to do it.
The metadata API uses a separate key that you need to send a formal request to the Airtable team by registering at the link provided at the top of the page.
import requests
user_account_api = xxx
meta_api = xxx
base_id = xxx
headers = {
"Authorization":f"Bearer {user_account_api}",
"x-airtable-client-secret": meta_api
}
response = requests.get(f"https://api.airtable.com/v0/meta/bases/{base_id}/tables", headers=headers)
print(response.text)
Related
I am trying to make a GET request to an endpoint which uses AWS Authorization. I made request using postman, It works. But when i tried following method in python, it's giving error.
CODE
url = 'XXX'
payload = {}
amc_api_servicename = 'sts'
t = datetime.utcnow()
headers = {
'X-Amz-Date': t.strftime('%Y%m%dT%H%M%SZ'),
'Authorization': 'AWS4-HMAC-SHA256 Credential={}/{}/{}/{}/aws4_request,SignedHeaders=host;x-amz-date,Signature=3ab1067335503c5b1792b811eeb84998f3902e5fde925ec8678e0ff99373d08b'.format(amc_api_accesskey, current_date, amc_api_region, amc_api_servicename )
}
print(url, headers)
response = requests.request("GET", url, headers=headers, data=payload)
ERROR
The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method.
Please point me in the right direction.
import boto3
client = boto3.client('sts')
respone=client.assume_role(RoleArn='your i am urn',RoleSessionName='PostmanNNN')
I have credentials with scope 'Manage users'.
I manage to create access_token but credentials work for API v1 (/api/1/users) but not for v2 (/api/2/users).
The error message I get is: {"message":"Unauthorized","name":"UnauthorizedError","statusCode":401}
I've tried it from python and postman.
Anyone working with users V2 and managed to make it work?
r = requests.post(
url='https://api.us.onelogin.com/auth/oauth2/v2/token',
auth=(CLIENT_ID, CLIENT_SECRET),
json={'grant_type': 'client_credentials'}
)
response = r.json()
auth_token = response['access_token']
r = requests.get(
url='https://api.us.onelogin.com/api/1/users',
headers= {'Authorization': f'bearer:{auth_token}'}
)
print(r.status_code)
>> 200
r = requests.get(
url='https://api.us.onelogin.com/api/2/users',
headers= {'Authorization': f'bearer:{auth_token}'}
)
print(r.status_code)
>>401
I was able to reproduce your issue using Postman.
Your Input
Authorization:bearer:<access_token>
Correct Input:
Authorization:bearer <access_token>
Notice the whitespace between bearer and <access_token>. I am assuming you downloaded OneLogin provided Postman Collection. With their Collection, it doesn't work.
I'm trying to login to an API to retrieve an access token using a consumer secret and key. Following several threads on stackoverflow, I've gotten this far:
consumer = "<myconsumerkey>:<myconsumersecret>"
b64val = base64.b64encode(consumer.encode()).decode()
headers = {"Authorization": "Basic %s" % b64val, "Content-Type": 'application/x-www-form-urlencode'}
response = requests.post('https://mysite/token', headers=headers, verify=False)
This always throws a 415 error. I've read the requests api documentation so many times I'm going crazy where is my malfunction here?
I do not know why, but adding
data = {'grant_type': 'client_credentials'}
to the post worked. The code is:
def login():
consumer = consumer_key + ":" + consumer_secret
b64val = base64.b64encode(consumer.encode()).decode()
headers = {"Authorization": "Basic %s" % b64val}
data = {'grant_type': 'client_credentials'}
response = requests.post('https://mywebsite:8243/token', headers=headers, data=data)
How can I access Airtable's pagination by including a given offset in either the url or query?
My attempt below at including in the url has failed with the error "KeyError: 'offset'".
I've been able to access the 1st offset per the function at_page(). For simplicity's sake, I took the result from the function and hardcoded it to the variable offset_01.
Thank you!
import requests
import pandas as pd
offset_01 = 'itrCG3VDp2c34x1j1/recKTJGYMICe13iA8'
url = 'https://api.airtable.com/v0/PRIVATETABLEKEY/accounts' + \
'&offset=' + offset_01
headers = {'Authorization': 'Bearer PRIVATEAPIKEY'}
# Calling API
response = requests.get(
url,
headers=headers,
)
json_response = response.json()
# Finding AT page offset
def at_page(at_json):
df_initial = pd.DataFrame(at_json)
at_offset = df_initial['offset'][0]
return at_offset
offset = at_page(json_response)
Figured it out:
It’s the params={‘offset’: ‘itrXXXXXX/recXXXXXX’} query that allows access to the next 100 records:
# Calling API
response = requests.get(
url,
headers=headers,
params={'offset': 'itrXXXXXX/recXXXXXX'}
)
json_response = response.json()
Hope this helps someone. Cheers!
I'm trying to request post to my web server a notification but it shows error 401.
I already tested my API key in postman and it works but when I used it in python it shows error 401 or error:unathenticated.
Here's my code
import requests
req = requests.post('https://sampleweb.com/api/v1/devices/1/notifications',
json={ 'Authorization': 'Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9',
"notification": { "message":"hey", "level": 4}})
print(req.json())
file = open("alert_content.txt", "a")
file.write(req.text + "\n")
file.close()
I've searched and read some documentations regarding to my question and I already solved it. Here's the code.
import requests
url = "https://sampleweb.com/api/v1/devices/1/notifications"
auth = {'Authorization': 'Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ',
'content-type':'application/json'}
params = {"notification":{"message":message,"level":level}}
req = requests.post(url, headers= auth, json = params)
print(req.json())
file = open("alert_content.txt", "a")
file.write(req.text + "\n")
file.close()
The authorization needs the content-type and the params or parameters needed to be in json format. Now it works.