NB: all the path given are relative to your Lizmap Web Client instance folder.
Copy the gobsapi directory inside the lizmap/lizmap-modules/ of a working
Lizmap Web Client instance to have a new lizmap/lizmap-modules/gobsapi/ folder
containing the files module.xml, events.xml, and folders.
Then modify the file lizmap/var/config/localconfig.ini.php
to add gobsapi.access=2 in the [modules] section, such as
Copy the folder gobsapi/install/gobsapi inside the Lizmap folder lizmap/var/config/
to have a new folder lizmap/var/config/gobsapi with a file config.ini.php inside
If your Lizmap Web Client uses SAMLv2 to authenticate the users,
you need to force the gobsapi module to use another driver.
The SAML protocol is based on URL redirections, which are not suitable for the G-Obs API end point.
You can override the configuration to force the gobsapi.php entry point to use another driver.
To do so, you must first edit the file localconfig.ini.php and change the [module] section into:
1 2 3 4 5 6 7 8 9101112131415
[modules];; uncomment it if you want to use ldap for authentication;; see documentation to complete the ldap configurationldapdao.access=0lizmap.installparam=multiauth.access=0;; we deactivate gobs & saml which must be activated;; only for the entry points index and admin;; by editing their configuration files lizmap/var/config/index/config.ini.php;; and lizmap/var/config/admin/config.ini.phpgobs.access=0saml.access=0;; we then activate the gobsapi modulegobsapi.access=2
We have deactivated gobs & saml in the main config (localconfig):
they must now be activated only for the entry points index and admin
by editing their configuration files lizmap/var/config/index/config.ini.php and lizmap/var/config/admin/config.ini.php.
;<?php die(''); ?>;for security reasons , don't remove or modify the first linestartModule=viewstartAction="default:index"[coordplugins]jacl2=1saml="saml/saml.coord.ini.php"saml.name=auth[modules]dataviz.access=2dynamicLayers.access=2jelix.access=2lizmap.access=2view.access=2filter.access=2action.access=2jacl2db_admin.access=1jauthdb_admin.access=1master_admin.access=1saml.access=2saml.installparam="localconfig;useradmin=mdouchin;emailadmin=mdouchin@3liz.com"saml.path="app:my-packages/vendor/jelix/saml-module/saml"gobs.access=2[coordplugin_auth];; uncomment it if you want to use ldap for authentication;; see documentation to complete the ldap configurationdriver=saml
;<?php die(''); ?>;for security reasons , don't remove or modify the first linestartModule=master_adminstartAction="default:index"[responses]html=adminHtmlResponsehtmlauth=adminLoginHtmlResponse[modules]admin.access=2jauthdb_admin.access=2jacl2db_admin.access=2master_admin.access=2jcommunity.access=2saml.access=2saml.installparam="localconfig;useradmin=mdouchin;emailadmin=mdouchin@3liz.com"saml.path="app:my-packages/vendor/jelix/saml-module/saml"gobs.access=2[coordplugins]jacl2=1saml="saml/saml.coord.ini.php"saml.name=auth[coordplugin_auth];; uncomment it if you want to use ldap for authentication;; see documentation to complete the ldap configurationdriver=saml
[modules]jelix.access=1lizmap.access=1view.access=1jacl2db_admin.access=1jauthdb_admin.access=1master_admin.access=1;; on active le module gobsapigobsapi.access=2;; et ldapdaoldapdao.access=1jacl2.access=1jauth.access=1jauthdb.access=1[coordplugins]jacl2=1auth="gobsapi/auth.coord.ini.php"[coordplugin_jacl2]on_error=2error_message="jacl2~errors.action.right.needed"on_error_action="jelix~error:badright"
Then you are ready to test. For example with curl (you need curl to pass JWT token in Authorization header).
Full API Documentation is available: https://docs.3liz.org/lizmap-gobsapi-module/api/
# login# we get the authentication TOKEN variable by first log the user inTOKEN=$(curl-s-XGET-H'Content-Type: application/json'"$BASEURL/user/login?username=gobsapi_writer&password=al_password"|jq-r'.token')&&echo$TOKEN# OR# we can use Basic authentication to avoid using username & password in the URLTOKEN=$(curl-s-XGET-H'Content-Type: application/json'-u"gobsapi_writer:al_password""$BASEURL/user/login"|jq-r'.token')&&echo$TOKEN
returns the token, for example
1
dacf5135c6686417c3916a649adbd146
Get the user projects
123
# User Projects# we use the $TOKEN variable in the Authorization headerecho$(curl-XGET-H'Accept: application/json'-H"Authorization: Bearer ${TOKEN}"$BASEURL/user/projects)
Get the observation of a given indicator between two dates
123
# getObservationsByIndicator# between seven days ago and nowecho$(curl-XGET-H'Accept: application/json'-H"Authorization: Bearer ${TOKEN}"-H"lastSyncDate: $(date'+%Y-%m-%d %H:%M:%S'-d'7 days ago')"-H"requestSyncDate: $(date'+%Y-%m-%d %H:%M:%S')"$BASEURL/project/test_project_a/indicator/hiker_position/observations)
returns all the matching observations.
Get the deleted observation on the server between two dates
You can activate the debug mode by manually editing the configuration file lizmap/var/config/gobsapi.ini.php
and modify the variable log_api_calls' with thedebug` value:
12
[gobsapi]log_api_calls=debug
You will then be able to see the API calls log written in the file lizmap/var/log/messages.log
1
tail-flizmap/var/log/messages.log
Messages will be like
1234567
2021-02-09 17:18:52 127.0.0.1 default GOBSAPI - ################
2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - path: getProjectByKey
2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - input_data: {"projectKey":"lizmapdemo~a_fake_project","module":"gobsapi","action":"project:getProjectByKey"}
2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - http_code: 404
2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - status: error
2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - message: The given project key does not refer to a known project
2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - ################