<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    <p>Hi David,</p>
    <p>To test Rest API I strongly recommend the use of "RESTer" which
      is an extension for Firefox.</p>
    <p>I'm sending here the "requests collection" I've made for my own
      use.</p>
    <p>When you open RESTer, there is a menu on the right (if not, click
      on the top left 3-bar icon).<br>
    </p>
    <p>First thing is to go on "Organize" and import the request
      collection.</p>
    <p>2nd step : Click on "Environment", then + button in the lower
      right corner.</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 class="moz-txt-link-freetext" href="http://localhost:8080">http://localhost:8080</a><br>
    </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.</p>
    <p>401 is Authentication Failure error, this is how I solved :<br>
    </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.</p>
    <p>Go to Auth tab, click on "Generate new Token" -> "Basic" and
      provide credentials (koha/koha)<br>
    </p>
    <p>To use basic Auth of course you'll have to enable BasicAuth in
      the Syspref.</p>
    <p>Click on the newly generated token so that it has a tick on its
      left.<br>
    </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.</p>
    <p>I find this way of working very useful to maintain the collection
      of curl commands.</p>
    <p>Sry that this email is a bit long, it may not directly solve your
      issue but I hope it may :)</p>
    <p>If there is any interest I can maybe make a screencast to show
      how to setup the whole thing.<br>
    </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 ^^)<br>
    </p>
    <p>Best regards,</p>
    <p>Arthur<br>
    </p>
    <div class="moz-cite-prefix">On 12/03/2020 05:41,
      <a class="moz-txt-link-abbreviated" href="mailto:dcook@prosentient.com.au">dcook@prosentient.com.au</a> wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:005301d5f828$72bac240$583046c0$@prosentient.com.au">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1176384751;
        mso-list-type:hybrid;
        mso-list-template-ids:-1103319802 201916431 201916441 201916443 201916431 201916441 201916443 201916431 201916441 201916443;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hi all,<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I’m finally getting around to playing with
          the REST API, but it’s not quite working as expected.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></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:<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <ol style="margin-top:0cm" type="1" start="1">
          <li class="MsoListParagraph"
            style="margin-left:0cm;mso-list:l0 level1 lfo1">200 OK<o:p></o:p></li>
          <ol style="margin-top:0cm" type="a" start="1">
            <li class="MsoListParagraph"
              style="margin-left:0cm;mso-list:l0 level2 lfo1"><a
                href="http://localhost:8080/api/v1/.html"
                moz-do-not-send="true">http://localhost:8080/api/v1/.html</a><o:p></o:p></li>
            <li class="MsoListParagraph"
              style="margin-left:0cm;mso-list:l0 level2 lfo1"><a
                href="http://localhost:8080/api/v1/"
                moz-do-not-send="true">http://localhost:8080/api/v1/</a>
              or <a href="http://localhost:8080/api/v1/.json"
                moz-do-not-send="true">http://localhost:8080/api/v1/.json</a>
              <o:p></o:p></li>
          </ol>
          <li class="MsoListParagraph"
            style="margin-left:0cm;mso-list:l0 level1 lfo1">500 Internal
            Server error (with no obvious messages in the server logs
            other than a missing “Routing to a callback”)<o:p></o:p></li>
          <ol style="margin-top:0cm" type="a" start="1">
            <li class="MsoListParagraph"
              style="margin-left:0cm;mso-list:l0 level2 lfo1"><a
                href="http://localhost:8080/api/v1/items"
                moz-do-not-send="true">http://localhost:8080/api/v1/items</a><o:p></o:p></li>
            <li class="MsoListParagraph"
              style="margin-left:0cm;mso-list:l0 level2 lfo1"><a
                href="http://localhost:8080/api/v1/patrons"
                moz-do-not-send="true">http://localhost:8080/api/v1/patrons</a><o:p></o:p></li>
            <li class="MsoListParagraph"
              style="margin-left:0cm;mso-list:l0 level2 lfo1"><a
                href="http://localhost:8080/api/v1/libraries"
                moz-do-not-send="true">http://localhost:8080/api/v1/libraries</a><o:p></o:p></li>
          </ol>
        </ol>
        <p class="MsoNormal"><o:p> </o:p></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.)<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></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.
          <o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></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}’. <o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></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…<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">David Cook<o:p></o:p></p>
        <p class="MsoNormal">Systems Librarian<o:p></o:p></p>
        <p class="MsoNormal">Prosentient Systems<o:p></o:p></p>
        <p class="MsoNormal">72/330 Wattle St<o:p></o:p></p>
        <p class="MsoNormal">Ultimo, NSW 2007<o:p></o:p></p>
        <p class="MsoNormal">Australia<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Office: 02 9212 0899<o:p></o:p></p>
        <p class="MsoNormal">Direct: 02 8005 0595<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Koha-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Koha-devel@lists.koha-community.org">Koha-devel@lists.koha-community.org</a>
<a class="moz-txt-link-freetext" href="https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel">https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel</a>
website : <a class="moz-txt-link-freetext" href="http://www.koha-community.org/">http://www.koha-community.org/</a>
git : <a class="moz-txt-link-freetext" href="http://git.koha-community.org/">http://git.koha-community.org/</a>
bugs : <a class="moz-txt-link-freetext" href="http://bugs.koha-community.org/">http://bugs.koha-community.org/</a>
</pre>
    </blockquote>
  </body>
</html>