| [09:02:30] | * ghpstudent[m] has joined #farmos |
| [09:08:25] | <ghpstudent[m]> | Hello all, im a (very) new user to FarmOS and i'm interested in using its API feature. My problem however, is that for some reason, i can't seem to make the API work... Whenever i try and call it using postman (eg. the "/farm.json" that is being used as an example on FarmOS api page) i get a status code "403 Forbidden". Again, im not sure what i'm doing wrong... I havent set up any authentication/authorization but, |
| [09:08:25] | <ghpstudent[m]> | unless i've missed it, it doesnt seem like a requirement. Anyone know how to make the API work? |
| [09:08:58] | <mstenta[m]> | Hi ghpstudent |
| [09:09:14] | <mstenta[m]> | Everything in farmOS requires a user login to access |
| [09:09:20] | <mstenta[m]> | So you do need to authenticate |
| [09:09:41] | <mstenta[m]> | There are various ways to do that, described here: https://farmos.org/development/api/#authentication |
| [09:09:43] | <mstenta[m]> | Hope that helps! |
| [09:16:27] | <ghpstudent[m]> | ACTION sent a long message: < https://matrix.org/_matrix/media/r0/download/matrix.org/RJXjMQfHkKaXPzZi... > |
| [09:55:58] | <mstenta[m]> | Oh yea I think I remember that... |
| [09:56:31] | <mstenta[m]> | I think it just means that, by default, you need a user with a name that begins with "restws" eg: "restws-myusername" |
| [09:56:46] | <mstenta[m]> | To change that, you need to add a line to your `settings.php` file that overrides a variable |
| [09:56:58] | <mstenta[m]> | I think there's an example in the restws readme file? |
| [09:57:28] | <mstenta[m]> | https://git.drupalcode.org/project/restws/blob/HEAD/restws_basic_auth/RE... |
| [09:57:46] | <mstenta[m]> | ACTION sent a long message: < https://matrix.org/_matrix/media/r0/download/matrix.org/afIxLgWYPhhaPZyJ... > |
| [09:57:54] | <mstenta[m]> | So, to allow ANY user, I think you would add: |
| [09:58:29] | <mstenta[m]> | $conf['restws_basic_auth_user_regex'] = '/^.*/'; |
| [09:58:35] | <mstenta[m]> | * `$conf['restws_basic_auth_user_regex'] = '/^.*/';` |
| [09:58:45] | <mstenta[m]> | But I have never done that, so you may need to play around with it |
| [10:32:06] | <ghpstudent[m]> | Thanks again for the reply! :) I'll play around with it a little and share my results |
| [10:34:11] | <mstenta[m]> | Sure thing! Good luck |
| [12:10:53] | <symbioquine[m]> | Perhaps it is worth reiterating that the regex above only applies to HTTP basic auth - i.e. auth where the username/password are passed in the `Authorization` header (populated by the curl -u option). It's only slightly more complicated to use the "Session Cookie and CSRF Token" strategy described by https://farmos.org/development/api/ which should work with any username out-of-the-box. |
| [12:28:52] | <mstenta[m]> | Yes and now we also have an oauth option! :-) |
| [12:47:59] | * friedrich[m]1 has joined #farmos |