Python authentication

Hello,

My names Ben and this is the first time I’ve dealt with API calls so a little patience would make me feel very welcome :slight_smile:

I’m trying to build a script that will request the latest data for an application and save this data into a file. This script will sit on a virtual machine and be executed on a schedule. I have built the script and things are going well, where I’m struggling is with the authentication tokens/refresh tokens.

The idea of saving the data to a file might sound strange, but I’m working within the boundaries of another system we use.

While I have been developing the script, I used a token from a Postman session. This allowed me to bypass the authentication process while I get everything else sorted. I’ve tried to get my head around the simplest form of authentication, look for examples but I’ve come up blank.

If someone is able to help with a simple authentication process example it would be highly appreciated.

Thanks,

Ben

You could always do the same thing in PHP, and then pass the token to your python script

just like this:
$url = ‘https://eu.airvantage.net/api/oauth/token’;
$data = array(‘grant_type’ => ‘password’, ‘username’ => $username, ‘password’ => $password, ‘client_id’ => $clientid, ‘client_secret’ => $secret);

// use key ‘http’ even if you send the request to https://…
$options = array(
‘http’ => array(
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
‘method’ => ‘POST’,
‘content’ => http_build_query($data)
)
);
$context = stream_context_create($options);
$hrresult = file_get_contents($url, false, $context);
if ($hrresult === FALSE) { /* Handle error */ }
$hrate=json_decode($hrresult, true);