Configuring DB Service Using system API

I am trying to access & configure the ‘database’ parameter of a postgresql service using GET/PATCH and unable to do either.

https://<server>/api/v2/system/service/<id>?fields=*&api_key=<KEY>
works and results in a full list of fields and values like below

{“id”:20,“name”:“servicename”,“label”:“PostgresDB”,“description”:“Postgres Database”,“is_active”:true,“type”:“pgsql”,“mutable”:true,
…,
…,
“config”:{“service_id”:20,“options”:null,“attributes”:null,“statements”:null,“host”:“xxx.xxx.xx.xx”,“port”:5432,“database”:“psqldb”,“username”:“user”,“password”:"**********",“schema”:“public”,“charset”:null,“sslmode”:“allow”,“timezone”:null,“application_name”:“appname”,“max_records”:10000,“allow_upsert”:false,“cache_enabled”:false,“cache_ttl”:0}}

https://<server>/api/v2/system/service/<id>?fields=id,name&api_key=<KEY>
also works

However, retrieving ONLY the config or the ‘database’ value within the config is not working.

Any inputs on retrieving and also modifying the ‘database’ value much appreciated.
Thanks much!

Hello, tabraham. What exactly do you mean, retrieving only the config or the config.database value is not working? I am able to retrieve these values using any number of methods. What specifically are you trying to do to retrieve these values that is not working?

Unless you are talking about the built-in API Docs feature, which I have found to be quite buggy at times…?

tabraham,

Also, just as a warning, not all of the data you see there will be retrieved by specifying it in the “fields” paramter, as this data is pulled from multiple places. For instance, I have a SQL database where most of the details are not configured in the dbo.service table, but in the dbo.sql_db_config table. So, my thought is this is why you are having the issues you are, if you are trying to specify specific details within the “fields” parameter via an API call. You are going to need to parse out what you want from the other response, I believe, as it is building its API call against only the dbo.service table by default.

Thanks,

Paul

Thanks Paul. In terms of intent - I was hoping to a) just retrieve the config:database value – and not the entire list of fields and b) update only the config:database parameter for a postgresql service.

In the end, decided it was not a big issue to retrieve the entire list and then just parse the database parameter (similar to suggestion in your second response). I was also able to make the PATCH work by creating a json payload with only config:database.

Thanks again.

1 Like