Retrieve the value of [Environment Default] for the "schema" property of a component, using the API

When using the single schema strategy, it is recommended to configure the desired schema in the « Default Schema » property of an environment, and leave in every components the « [Environment Default] » default value if a schema is required in the component’s properties.

When using the API, the components with a « Schema » property I retrieve do not have the actual schema but the « [Environment Default] » value instead.

 

To get the default schema of an environment, I have seen that I could use an « automatic variable » named « environment_default_schema » (as described in this link: https://documentation.matillion.com/docs/2943424).

Would the following endpoint answers me with the default schema of the specified environment?

 

http://<InstanceAddress>/rest/v1/group/name/<groupName>/project/name/<projectName>/environment/name/<environmentName>/variable/name/environment_default_schema/value

 

The problem I encounter is that, if a project has many environments defined, there would be as many default schema as there are environments. 

 

But since a table belongs to a schema, changing the schema will change the available tables to choose from.

Having a table name returned from the API, how can I find the environment from which that table comes from, using the API?

 

Thank you in advance for any help,

 

Cyrille Dakhlia

I believe you would need to call the "https://<InstanceAddress>/rest/v1/group/name/<groupName>/project/name/<projectName>/environment" end point to get a list of environments, then call "https://<InstanceAddress>/rest/v1/group/name/<groupName>/project/name/<projectName>/environment/name/<environmentName>/export" for each environment which has an element "defaultEnvironment" which will be True if it is the default environment. That last endpoint will give you the Warehouse (port) if using Snowflake, database, schema, and role for the environment.

You have to call the first end point to get the list, then you have to call the second endpoint for each environment to see which one is set to default. So if you have two environments, you will need to call the second endpoint twice if the first environment you call if for is not the default environment.

 

As an example, here is a dummy scenario. I call the first endpoint to get the environments, and you see there are 2 environments - Florida_SF_Connection and NJ_SF_Connection :

Now I call the second endpoint for the NJ_SF_Connection:

 

That one has “defaultEnvironment” as false, so that is not the default. Next I call the second endpoint for the Florida_SF_Connection:

 

And that is the one with “defaultEnvironment” set to True, so I have my default environment - Florida_SF_Connection.

Thank you for your answer.

 

If you allow me to rephrase just to make sure I have understood correctly,

after calling the appropriate endpoint to get the list of environments of a specified project, there will be among them only one having a field "defaultEnvironment" set to True? (Which also means that there is a notion of default environment I didn't know, is that right?)

If the notion of default environment exists and if it has a standard meaning, I am still thinking about the fact that it might not help me completely.

Please, allow me to explain:

the "[Environment Default]" value from the schema property of my component finds its true identity in, I suppose, the default_schema variable of the selected environment (or also in the "schema" field of the environment export, if I understood correctly). But the selected environment is not necessarily the default environment.

 

More over, the mere concept of a selected environment would be contradictory with the statelessness of the RESTful API.

Therefore, there is no concept of selected environment, as answered in my previous question.

In that case, I wouldn't be able to determine which environment is referred by the "[Environment Default]" value of my component. Is that right?

 

I hope what I said makes sense, and if I made a mistake in the reasoning, I would be very grateful to be told!

Thank you so much for illustrating with an example, this part is very clear now. I was surprised because I couldn't see that "defaultEnvironment" field in the documentation, so I didn't know it existed!

@DataGuy​ , do you have any insight regarding this?

No problem. Unfortunately the API documentation does not give details on what is returned, so I use Postman to run the endpoints and see what comes back.

I was looking for something else and just found a way to get the default environment with one call, but the JSON that is returned is huge so I think my original answer is still the best - not as much to search or load into memory. The other way is to use the endpoint: "https://<InstanceAddress>/rest/v1/group/name/<groupName>/project/name/<projectName>/export".

If you are looking at a schema that is set to "[Environment Default]" in the return of the API, then you have a way to do it. Environment default is not a UI setting but a way for the jobs to use what is set as default, so if the environment needs to change, once you you change the default in the project, it is changed for all of the jobs without doing anything else.

There is no reason to go to API if intention is to get default schema name in Matillion job as we can use automatic variable https://docs.matillion.com/metl/docs/2943424/#automatic-variables

Indeed, thank you for thinking about me hahaha.

I prefer your first proposition as it is more economical! 😁