Manage Data Sources
This chapter shows you how to test connections, back up, and manage data sources in GoodData.
Test Database Connection
You can test a connection to any database, even if it hasn’t been registered in GoodData.
Registered Data Source
Send a POST
request to this API endpoint /api/v1/actions/dataSources/{dataSourceId}/test
.
curl $HOST_URL/api/v1/actions/dataSources/<dataSourceId>/test \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{}' \
-X POST | jq .
Invoke-RestMethod -Method Post -Uri "$HOST_URL/api/v1/actions/dataSources/<dataSourceId>/test" `
-ContentType 'application/json' `
-H @{
'Accept' = 'application/json'
'Authorization' = "Bearer $API_TOKEN"
} | ConvertTo-Json
If the connection works, the server returns:
{
"successful": true
}
Unregistered Data Source
Send a POST
request to this API endpoint: /api/v1/actions/dataSource/test
. Using a PostgreSQL database as an example:
curl $HOST_URL/api/v1/actions/dataSource/test \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{
"url": "jdbc:postgresql://<some_hostname>:<some_port>/<dbname>",
"schema": "<schema_name>",
"type": "POSTGRESQL",
"username": "<username>",
"password": "<password>"
}' \
-X POST | jq .
Invoke-RestMethod -Method Post -Uri "$HOST_URL/api/v1/actions/dataSource/test" `
-ContentType 'application/json' `
-H @{
'Accept' = 'application/json'
'Authorization' = "Bearer $API_TOKEN"
} `
-Body '{
"url": "jdbc:postgresql://<some_hostname>:<some_port>/<dbname>",
"schema": "<schema_name>",
"type": "POSTGRESQL",
"username": "<username>",
"password": "<password>"
}' | ConvertTo-Json
If the connection works, the server returns:
{
"successful": true
}
Data Source Passwords
The passwords for data source users can be stored using the declarative API, but cannot be read from it.
Before submitting a PUT request to the data sources’ declarative API interface, ensure that you have the necessary passwords for your data sources to prevent any connection issues. You can either include the passwords directly in your PUT request or use the Entity API interface to update a specific password if you prefer not to include it in the PUT request to the declarative API interface.
When you use the declarative API interface for data sources, you must either specify the username and password for the data source in the PUT request or specify nothing at all.
Create A Backup Of All Data Sources
The following example retrieves the entire declarative layout of your data sources and stores the output in a JSON file named data-sources-layout.json. The passwords are not retrieved as it is not possible to retrieve passwords through the API. Refer to the Data Source Passwords section for more information.
curl -H "Authorization: Bearer $API_TOKEN" \
$HOST_URL/api/v1/layout/dataSources > data-sources-layout.json
Restore All Data Sources
The following example replaces the current data source declarative layout with that of a previously retrieved declarative layout. If the previously retrieved declarative layout has not been updated to include the data source passwords, the data source passwords must be inserted afterwards.
curl -H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-X PUT \
$HOST_URL/api/v1/layout/dataSources -d @data-sources-layout.json
Data Source Declarative Layout Document
The following example shows a truncated physical model for the data sources declarative layout. The password is replaced with a dummy value.
{
"dataSources": [
{
"id": "pg_local_docker-demo",
"name": "pg_local_docker-demo",
"pdm": {
"tables": [
{
"columns": [
{
"dataType": "STRING",
"isPrimaryKey": false,
"name": "category"
},
{
"dataType": "INT",
"isPrimaryKey": true,
"name": "product_id"
},
{
"dataType": "STRING",
"isPrimaryKey": false,
"name": "product_name"
}
],
"id": "products",
"path": [
"products"
],
"type": "VIEW"
}
]
},
"schema": "demo",
"type": "POSTGRESQL",
"url": "jdbc:postgresql://postgres:5432/tiger",
"username": "postgres",
"password": "<password>"
}
]
}
You can also issue a PUT request to the data sources declarative API endpoint with an empty physical model.
{
"dataSources": [
{
"id": "pg_local_docker-demo",
"name": "pg_local_docker-demo",
"pdm": {
"tables": []
},
"schema": "demo",
"type": "POSTGRESQL",
"url": "jdbc:postgresql://postgres:5432/tiger",
"username": "postgres",
"password": "<password>"
}
]
}