#!/usr/bin/perl

$post = `curl -i -s -X POST -H 'Content-type: application/json' -H 'X-Okapi-Tenant: $tenantId' -d '{"username": "$username", "password": "$password"}' https://okapi-drew.folio.ebsco.com/authn/login`;

@parts = split(/\n/,$post);
foreach $part (@parts) {
	if ($part =~ /^x-okapi-token:/) {
		$xOkapiToken = "X-Okapi-Token: " . substr($part,15);
		$xOkapiToken =~ s/^M//g; 
		$note2self = "*** that looks like ^M but it is not - it is Ctrl+V Ctrl+M ***";
	}
}

open(w,">okapi-token.txt");
print w "$xOkapiToken";
close(w);