Hey! I am using the following code to retrieve the session code from Koha using Koha RestAPI. import requests import base64 domain = 'http://my-domain.com' username = 'user' password = 'password' api_key = 'my-api-key' client_id = 'id' url = f'{domain}/api/v1/auth/token' auth_header_value = base64.b64encode(f'{username}:{password}'.encode()).decode() headers = { 'Authorization': f'Basic {auth_header_value}', 'X-API-Key': api_key } response = requests.post(url, headers=headers) if response.status_code == 200: access_token = response.text print(f"Access token: {access_token}") else: print(f"Error: {response.status_code} {response.reason}") I am supposed to get a session token with response code 200. But I am getting an error 404 i.e. default response. I have done the code in perl but getting the same response. Kindly help me to solve this issue as it is my university project.
Check the REST* system preferences, especially RESTBasicAuth. I've successfully used the oauth style authentication, with a patron API key in php using curl. My code looks like this: $id = $file_content->id; $secret = $file_content->secret; $result = $this->post( 'api/v1/oauth/token', array( 'client_id' => $id, 'client_secret' => $secret, 'grant_type' => 'client_credentials', ) ); if ( !empty($result->access_token) ) { $this->bearer = $result; } On Tue, Mar 28, 2023 at 12:28 AM Muhammad Uzair <uzair.metro@gmail.com> wrote:
Hey! I am using the following code to retrieve the session code from Koha using Koha RestAPI.
import requests import base64
domain = 'http://my-domain.com' username = 'user' password = 'password' api_key = 'my-api-key' client_id = 'id'
url = f'{domain}/api/v1/auth/token' auth_header_value = base64.b64encode(f'{username}:{password}'.encode()).decode()
headers = { 'Authorization': f'Basic {auth_header_value}', 'X-API-Key': api_key }
response = requests.post(url, headers=headers)
if response.status_code == 200: access_token = response.text print(f"Access token: {access_token}") else: print(f"Error: {response.status_code} {response.reason}")
I am supposed to get a session token with response code 200. But I am getting an error 404 i.e. default response. I have done the code in perl but getting the same response.
Kindly help me to solve this issue as it is my university project. _______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel website : https://www.koha-community.org/ git : https://git.koha-community.org/ bugs : https://bugs.koha-community.org/
-- Michael Hafen Washington County School District Technology Department Systems Analyst
participants (2)
-
Michael Hafen -
Muhammad Uzair