How can I add new data source programmatically

Hi!

Basically I have an automated process that creates new database and I would like to create a new Data Source into Redash by the process. Is there any possibilities for that?

Toomas

Yes. You can use Redash’s internal API to create data sources. The API is not documented per se but can be easily be inspected from the source code.

Just remember to use an admin group member’s API key.

is there any documentation with examples for this ? the names of the configuration variables that are required for each type of datasouce

1 Like

This API isn’t documented.

But you can see which variables are needed in the configuration_schema for any query runner. For example, the postgres query runner can be found here. I pasted the applicable portion below:

{
            "type": "object",
            "properties": {
                "user": {"type": "string"},
                "password": {"type": "string"},
                "host": {"type": "string", "default": "127.0.0.1"},
                "port": {"type": "number", "default": 5432},
                "dbname": {"type": "string", "title": "Database Name"},
                "sslmode": {
                    "type": "string",
                    "title": "SSL Mode",
                    "default": "prefer",
                    "extendedEnum": [
                        {"value": "disable", "name": "Disable"},
                        {"value": "allow", "name": "Allow"},
                        {"value": "prefer", "name": "Prefer"},
                        {"value": "require", "name": "Require"},
                        {"value": "verify-ca", "name": "Verify CA"},
                        {"value": "verify-full", "name": "Verify Full"},
                    ],
                },
                "sslrootcertFile": {
                    "type": "string",
                    "title": "SSL Root Certificate"
                },
                "sslcertFile": {
                    "type": "string",
                    "title": "SSL Client Certificate"
                },
                "sslkeyFile": {
                    "type": "string",
                    "title": "SSL Client Key"
                },
            },
            "order": ["host", "port", "user", "password"],
            "required": ["dbname"],
            "secret": ["password"],
            "extra_options": ["sslmode", "sslrootcertFile", "sslcertFile", "sslkeyFile"],
        }

So you can send the following fields:

  • user
  • password
  • host
  • port
  • dbname
  • sslmode

…along with the SSL cert file keys.

1 Like

Hello Jessie!

I have the same problem for postgres,

this is the json i am sending in the POST

Solved, change “postgres” to “pg”