I am new to programming, and was asked to take over a project where I need to change the current Python code we use to connect to a Ver 1 RESTful API. The company has switched to their Ver 2 of the API and now require IDs and Keys for authentication instead of the basic username and password. The old code that worked for the Ver 1 API looks like this:
import requests
import simplejson as json
import pprintpp as pprint
#API_Ver1 Auth
USER = 'username'
PASS = 'password'
url = 'https://somecompany.com/api/v1/groups'
s = requests.Session()
s.auth = (USER, PASS)
r = json.loads(s.get(url).text)
groups = r["data"]
I can connect to the Ver 2 API via a terminal using a cURL string like this:
curl -v -X GET -H "X-ABC-API-ID:x-x-x-x-x"