<div dir="auto">Hi all.<div dir="auto"><br></div><div dir="auto">Cookie auth shouldn't be a problem per se. We only use the cookie for getting the user and then the code is the same no matter the autentication method.</div><div dir="auto"><br></div><div dir="auto">But</div><div dir="auto"><br></div><div dir="auto">There's always a 'but', right?</div><div dir="auto"><br></div><div dir="auto">I've been fighting some devs that introduce the use of C4::Context->userenv and then probably have side effects of a cookie is found ... Even if the api is called using (say) oauth.</div><div dir="auto"><br></div><div dir="auto">We should get rid of this side effects from our codebase. In the meantime, share some more info on the endpoint you're hitting so we can debug it and fix it!</div><div dir="auto"><br></div><div dir="auto">Cheers</div><div dir="auto"><br></div><div dir="auto">PS I need to submit some work I did for handling unhandled exceptions in a more useful way. I suggest you concat $_ to the case of 500 on the endpoint you're using to get more info.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El jue., 12 de marzo de 2020 19:31,  <<a href="mailto:dcook@prosentient.com.au">dcook@prosentient.com.au</a>> escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-AU" link="#0563C1" vlink="purple"><div class="m_4878582236916694696WordSection1"><p class="MsoNormal">Hi Arthur,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Thanks for your comprehensive reply. Sorry I just noticed it after replying to everyone else who CCed me directly.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I’m not interested in using browser extensions, but thanks for sharing your experience. <u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">It looks like the 500 Internal Server Errors probably related to Koha not handling a cookie/browser session as expected. The errors went away if I used a different browser or an Incognito mode. (Hence why it also worked with curl.) I suppose that could be a bug in Koha, but probably not a significant enough one to deal with right now. <br><br>Sure enough, when I log into the <a href="http://localhost:8080" target="_blank" rel="noreferrer">http://localhost:8080</a>, I can now get the output of <a href="http://localhost:8080/api/v1/libraries" target="_blank" rel="noreferrer">http://localhost:8080/api/v1/libraries</a> because of the cookie indicating my browser session. If I log out, I now get ‘{"error":"Something went wrong, check the logs."}’, when really I should probably get a 401. Raised this issue for it <a href="https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24862" target="_blank" rel="noreferrer">https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24862</a>. <u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">The RESTPublicAPI thing also looks like a bug as I keep getting this error: {"error":"Authorization failure. Missing required permission(s).","required_permissions":null}. At least when I try using RESTBasicAuth. I haven’t tried with RESTOAuth2ClientCredentials or cookie authentication. I’ll probably just end up blocking RESTPublicAPI anyway, but I’ve raised a ticket anyway <a href="https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24861" target="_blank" rel="noreferrer">https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24861</a>. <u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">David Cook<u></u><u></u></p><p class="MsoNormal">Systems Librarian<u></u><u></u></p><p class="MsoNormal">Prosentient Systems<u></u><u></u></p><p class="MsoNormal">72/330 Wattle St<u></u><u></u></p><p class="MsoNormal">Ultimo, NSW 2007<u></u><u></u></p><p class="MsoNormal">Australia<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Office: 02 9212 0899<u></u><u></u></p><p class="MsoNormal">Direct: 02 8005 0595<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Koha-devel <<a href="mailto:koha-devel-bounces@lists.koha-community.org" target="_blank" rel="noreferrer">koha-devel-bounces@lists.koha-community.org</a>> <b>On Behalf Of </b>Arthur Suzuki<br><b>Sent:</b> Thursday, 12 March 2020 8:23 PM<br><b>To:</b> <a href="mailto:koha-devel@lists.koha-community.org" target="_blank" rel="noreferrer">koha-devel@lists.koha-community.org</a><br><b>Subject:</b> Re: [Koha-devel] REST API not working in koha-testing-docker?<u></u><u></u></span></p></div></div><p class="MsoNormal"><u></u> <u></u></p><p>Hi David,<u></u><u></u></p><p>To test Rest API I strongly recommend the use of "RESTer" which is an extension for Firefox.<u></u><u></u></p><p>I'm sending here the "requests collection" I've made for my own use.<u></u><u></u></p><p>When you open RESTer, there is a menu on the right (if not, click on the top left 3-bar icon).<u></u><u></u></p><p>First thing is to go on "Organize" and import the request collection.<u></u><u></u></p><p>2nd step : Click on "Environment", then + button in the lower right corner.<u></u><u></u></p><p>For the requests in the collection to work you'll want to define an environment called "koha" with a key called "baseurl" containing... the base url of the koha instance you want to test, for koha-testing-docker this is <a href="http://localhost:8080" target="_blank" rel="noreferrer">http://localhost:8080</a><u></u><u></u></p><p>This setup allow to quickly change the baseurl for another one (let say a client in prodution) for all the requests in the collection.<u></u><u></u></p><p>401 is Authentication Failure error, this is how I solved :<u></u><u></u></p><p>3rd step : click on a request from the "KohaTest" group.  You'll get a panel with "Headers/Body/Auth/Var" tabs where you can provide data to forge the request.<u></u><u></u></p><p>Go to Auth tab, click on "Generate new Token" -> "Basic" and provide credentials (koha/koha)<u></u><u></u></p><p>To use basic Auth of course you'll have to enable BasicAuth in the Syspref.<u></u><u></u></p><p>Click on the newly generated token so that it has a tick on its left.<u></u><u></u></p><p>If you want to use curl, then you can easily export stuffs from RESTer to Curl, click on the top-right "3-point vertical" button and select "Show curl command" -> gives the curl stuff.<u></u><u></u></p><p>I find this way of working very useful to maintain the collection of curl commands.<u></u><u></u></p><p>Sry that this email is a bit long, it may not directly solve your issue but I hope it may :)<u></u><u></u></p><p>If there is any interest I can maybe make a screencast to show how to setup the whole thing.<u></u><u></u></p><p>I'm now just pulling the last koha-testing-docker env to verify if I get same errors as you have (taking some time given my very poor bandwidth in the middle of nowhere ^^)<u></u><u></u></p><p>Best regards,<u></u><u></u></p><p>Arthur<u></u><u></u></p><div><p class="MsoNormal">On 12/03/2020 05:41, <a href="mailto:dcook@prosentient.com.au" target="_blank" rel="noreferrer">dcook@prosentient.com.au</a> wrote:<u></u><u></u></p></div><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><p class="MsoNormal">Hi all,<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I’m finally getting around to playing with the REST API, but it’s not quite working as expected.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">In koha-testing-docker (with the latest koha-testing-docker git repo and Docker images as of this writing), I’m getting the following in the browser:<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><ol style="margin-top:0cm" start="1" type="1"><li class="m_4878582236916694696MsoListParagraph" style="margin-left:0cm">200 OK<u></u><u></u></li></ol><ol style="margin-top:0cm" start="1" type="1"><ol style="margin-top:0cm" start="1" type="a"><li class="m_4878582236916694696MsoListParagraph" style="margin-left:0cm"><a href="http://localhost:8080/api/v1/.html" target="_blank" rel="noreferrer">http://localhost:8080/api/v1/.html</a><u></u><u></u></li><li class="m_4878582236916694696MsoListParagraph" style="margin-left:0cm"><a href="http://localhost:8080/api/v1/" target="_blank" rel="noreferrer">http://localhost:8080/api/v1/</a> or <a href="http://localhost:8080/api/v1/.json" target="_blank" rel="noreferrer">http://localhost:8080/api/v1/.json</a> <u></u><u></u></li></ol></ol><ol style="margin-top:0cm" start="2" type="1"><li class="m_4878582236916694696MsoListParagraph" style="margin-left:0cm">500 Internal Server error (with no obvious messages in the server logs other than a missing “Routing to a callback”)<u></u><u></u></li></ol><ol style="margin-top:0cm" start="2" type="1"><ol style="margin-top:0cm" start="1" type="a"><li class="m_4878582236916694696MsoListParagraph" style="margin-left:0cm"><a href="http://localhost:8080/api/v1/items" target="_blank" rel="noreferrer">http://localhost:8080/api/v1/items</a><u></u><u></u></li><li class="m_4878582236916694696MsoListParagraph" style="margin-left:0cm"><a href="http://localhost:8080/api/v1/patrons" target="_blank" rel="noreferrer">http://localhost:8080/api/v1/patrons</a><u></u><u></u></li><li class="m_4878582236916694696MsoListParagraph" style="margin-left:0cm"><a href="http://localhost:8080/api/v1/libraries" target="_blank" rel="noreferrer">http://localhost:8080/api/v1/libraries</a><u></u><u></u></li></ol></ol><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">If I use “curl” or a Perl script, then I get a 401 error instead of a 500 error. (Although in Koha 19.11, I can get JSON results in either the browser or with curl for those endpoints, but that’s a whole other matter.)<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">RESTBasicAuth = 1 means I can use the API via curl, but still nothing via the browser. Which is fine I guess in practice but it’s not really what you’d expect. I often use browser requests to test out GET requests for APIs. <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I don’t really get how RESTPublicAPI works either. If it’s disabled, it says ‘{"error":"Configuration prevents the usage of this endpoint by unprivileged users"}’, but that doesn’t seem accurate, since disabling that system preference blocks the /public APIs in general, right? Even if you use a privileged user, it still doesn’t work.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Actually, even with RESTPublicAPI enabled, I can’t get the /public endpoints to work. I get errors like this ‘{"error":"Authorization failure. Missing required permission(s).","required_permissions":null}’. <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">This email is getting a bit long and I think I have a million other API problems, so I might just work through one by one and open Bugzilla tickets as I go…<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">David Cook<u></u><u></u></p><p class="MsoNormal">Systems Librarian<u></u><u></u></p><p class="MsoNormal">Prosentient Systems<u></u><u></u></p><p class="MsoNormal">72/330 Wattle St<u></u><u></u></p><p class="MsoNormal">Ultimo, NSW 2007<u></u><u></u></p><p class="MsoNormal">Australia<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Office: 02 9212 0899<u></u><u></u></p><p class="MsoNormal">Direct: 02 8005 0595<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"><br><br><u></u><u></u></p><pre>_______________________________________________<u></u><u></u></pre><pre>Koha-devel mailing list<u></u><u></u></pre><pre><a href="mailto:Koha-devel@lists.koha-community.org" target="_blank" rel="noreferrer">Koha-devel@lists.koha-community.org</a><u></u><u></u></pre><pre><a href="https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel" target="_blank" rel="noreferrer">https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel</a><u></u><u></u></pre><pre>website : <a href="http://www.koha-community.org/" target="_blank" rel="noreferrer">http://www.koha-community.org/</a><u></u><u></u></pre><pre>git : <a href="http://git.koha-community.org/" target="_blank" rel="noreferrer">http://git.koha-community.org/</a><u></u><u></u></pre><pre>bugs : <a href="http://bugs.koha-community.org/" target="_blank" rel="noreferrer">http://bugs.koha-community.org/</a><u></u><u></u></pre></blockquote></div></div></blockquote></div>