API Response Error - API Key


I am having trouble getting authenticated to the API.
I am using Python 3.
Below is my code to make the request and print the response.
I have registered and have an API Key, in my code it goes where ‘key_here’ is listed below.

Please let me know if I am formatting this incorrectly.
The server is not recognizing my API key and returns an error.

import requests, json

openstates_url = "https://openstates.org/graphql"

query_json = { 'query' : '{ people(first: 3) { edges { node { name }}}}' }

api_key = "key_here"

headers = {'Authorization': 'Bearer ' + api_key}

openstates_request = requests.post(url = openstates_url, json = query_json, headers = headers)


<Response [403]>
{“error”: “no valid key”, “note”: “https://openstates.org/api/register/ for API key. contact@openstates.org to raise limits”}


You need to use the “X-API-KEY” header instead of “Authorization”, and the value should contain only your key.


Awesome, thank you! It works perfectly.


Hi Srasmussen! I am new to this forum and was also looking for something similar on financepolice.com Thanks for sharing the is “X-API-KEY” thingy. It saved a lot of time for me.


This topic was automatically closed 70 days after the last reply. New replies are no longer allowed.