<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>A new request with request id 11831 has been created by koha-devel-request@lists.koha-community.org. Short info on the request is : <br><br>Title : Koha-devel Digest, Vol 196, Issue 12<br>Category : <br>Description : <div>Send Koha-devel mailing list submissions to<br>    koha-devel@lists.koha-community.org<br><br>To subscribe or unsubscribe via the World Wide Web, visit<br>    https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel<br>or, via email, send a message with subject or body 'help' to<br>    koha-devel-request@lists.koha-community.org<br><br>You can reach the person managing the list at<br>    koha-devel-owner@lists.koha-community.org<br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Koha-devel digest..."<br><br><br>Today's Topics:<br><br>   1. Re: REST API integration issues . (Esharat Mia)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Wed, 16 Mar 2022 00:34:57 +0600<br>From: Esharat Mia <esharat@esharat.me><br>To: "Eric Phetteplace" <ephetteplace@cca.edu><br>Cc: "Jonathan Druart" <jonathan.druart@bugs.koha-community.org>,<br>    "koha-devel" <koha-devel@lists.koha-community.org><br>Subject: Re: [Koha-devel] REST API integration issues .<br>Message-ID:<br>    <17f8edc9fba.f1f3e970644270.5384862201471327179@esharat.me><br>Content-Type: text/plain; charset="utf-8"<br><br>I created API keys from my super admin account . when I access this url "http://localhost:8080/api/v1/patrons"  with credential from web browser , I got the patrons list in browser as json array . But got error 401 using python code.  My python code below - <br><br><br><br>> import requests <br><br>> import json <br><br>> data = { <br><br>> "client_id": "52ba706f-902c-4208-b28d-c05df607f3c4", <br><br>> "client_secret": "de1c0400-ec02-4143-972e-752931968aed", <br><br>> "grant_type": "client_credentials", <br><br>> <br><br>> } <br><br>> headers = { <br><br>> 'Content_type': 'application/x-www-form-urlencoded' <br><br>> } <br><br>> response = http://requests.post("http://localhost:8080/api/v1/oauth/token", data=data, headers=headers) <br><br>> <br><br>> credentials = response.json() <br><br>> print(credentials) <br><br>> access_token = credentials['access_token'] <br><br>> print("Access_token: ",access_token) <br><br>> auth2 = { <br><br>> 'Authorization': 'Bearer ' +access_token <br><br>> } <br><br>> response= requests.get("http://localhost:8080/api/v1/patrons", headers=auth2 <br><br>> ) <br><br>> <br><br>> print(response)<br><br><br><br><br><br><br><br><br><br><br><br><br>---- On Wed, 16 Mar 2022 00:20:06 +0600 Eric Phetteplace <ephetteplace@cca.edu> wrote ----<br><br><br><br>Could you share your complete updated code again? And it would also be helpful to see more information about the response. You could print response.headers and response.text as well as response.status_code.<br><br><br><br>I thought the space after Bearer would fix it, so if your syntax is right now, my next guess is that the patron you configured this OAuth client for does not have permission to access patron data. Make sure to use a librarian account with "Set permissions" when you create the client (you can give them "Access to all librarian functions" if you're practicing locally).<br><br><br><br>Best,ERIC PHETTEPLACE Systems Librarian, Libraries (he/him)<br><br>mailto:ephetteplace@cca.edu | o 510.594.3660 (cca)<br><br><br><br>5212 Broadway | Oakland, CA | 94618<br><br>CCA is situated on the traditional unceded lands of the Ohlone peoples.<br><br>Black-owned bookstores in Oakland: https://ashaybythebay.com/, https://www.facebook.com/marcus.books/<br><br>:(){ :|: & };:<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>On Tue, Mar 15, 2022 at 10:34 AM Esharat Mia <mailto:esharat@esharat.me> wrote:<br><br>Thanks for your response . I add space after Bearer but same error. response code 401.<br><br><br><br><br><br><br><br><br><br><br>---- On Tue, 15 Mar 2022 22:48:33 +0600 Jonathan Druart <mailto:jonathan.druart@bugs.koha-community.org> wrote ----<br><br><br><br>'Authorization': 'Bearer' +access_token <br> <br>Add a space after "Bearer" <br> <br>'Authorization': 'Bearer ' +access_token <br> <br>Le mar. 15 mars 2022 à 17:10, Esharat Mia <mailto:esharat@esharat.me> a écrit : <br>> <br>> <br>> Dear All, <br>> <br>> Here is my python code for testing REST API - <br>> <br>> import requests <br>> import json <br>> data = { <br>> "client_id": "52ba706f-902c-4208-b28d-c05df607f3c4", <br>> "client_secret": "de1c0400-ec02-4143-972e-752931968aed", <br>> "grant_type": "client_credentials", <br>> <br>> } <br>> headers = { <br>> 'Content_type': 'application/x-www-form-urlencoded' <br>> } <br>> response = http://requests.post("http://localhost:8080/api/v1/oauth/token", data=data, headers=headers) <br>> <br>> credentials = response.json() <br>> print(credentials) <br>> access_token = credentials['access_token'] <br>> print("Access_token: ",access_token) <br>> auth2 = { <br>> 'Authorization': 'Bearer' +access_token <br>> } <br>> response= requests.get("http://localhost:8080/api/v1/patrons", headers=auth2 <br>> ) <br>> <br>> print(response) <br>> <br>> When I run this code , I get access_token . Then I use this access token  and try retrieve data. But getting authentication failure or response code 401 . My output below - <br>> <br>> <br>>  (base) esharat@esharat-desktop:~/Desktop/Library$ python3 test.py <br>> <br>> {'access_token': 'MTY0NzM2MDQ3Mi00MzgwNzctMC42OTA2NTM5MzA1MDgxODQtM0pTSTcwdUhGcVdzaTlUUnhGcGVDaTFmaVg3Nm9v', 'expires_in': 3600, 'token_type': 'Bearer'} <br>> <br>> Access_token:  MTY0NzM2MDQ3Mi00MzgwNzctMC42OTA2NTM5MzA1MDgxODQtM0pTSTcwdUhGcVdzaTlUUnhGcGVDaTFmaVg3Nm9v <br>> <br>> <Response [401]> <br>> <br>> Thanks in advance . <br>> <br>> <br>> _______________________________________________ <br>> Koha-devel mailing list <br>> mailto:Koha-devel@lists.koha-community.org <br>> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel <br>> website : https://www.koha-community.org/ <br>> git : https://git.koha-community.org/ <br>> bugs : https://bugs.koha-community.org/ <br><br><br><br><br><br><br><br><br>_______________________________________________<br> Koha-devel mailing list<br> mailto:Koha-devel@lists.koha-community.org<br> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel<br> website : https://www.koha-community.org/<br> git : https://git.koha-community.org/<br> bugs : https://bugs.koha-community.org/<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20220316/1bb93aae/attachment-0001.htm><br><br>------------------------------<br><br>Subject: Digest Footer<br><br>_______________________________________________<br>Koha-devel mailing list<br>Koha-devel@lists.koha-community.org<br>https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel<br>website : https://www.koha-community.org/<br>git : https://git.koha-community.org/<br>bugs : https://bugs.koha-community.org/<br><br><br>------------------------------<br><br>End of Koha-devel Digest, Vol 196, Issue 12<br>*******************************************<br></div><br><br>NOTE: You are receiving this mail because, the Requester/Technician wanted you to get notified on this request creation.<br></body></html>