How to call API endpoint using python
Post date: Nov 1, 2016 3:31:28 AM
Let's say you want to call an endpoint that requires API key. This post shows you how to do it using terminal and python.
Terminal:
curl -d '{"id": 1234}' -H "x-api-key: thisismyapikey" https://thisistheapiendpoint.com/myapi
For python, we use module requests, and this is the equivalent python command:
import requests
# for POST request
r = requests.post('https://thisistheapiendpoint.com/myapi', headers={"x-api-key": "thisismyapikey"}, data = '{"id":1234}')