Manage API assets
Operations on API assets (specs, paths, objects, queries, fields).
For a jump-start, read more about an example for crawling OpenAPI specifications, or grab the code from: atlanhq/atlan-java-samples
In general, these should be:
- Created in top-down order (connection, then spec/object/query, then path/field)
- Deleted in bottom-up order (paths/fields, then specs/objects/queries, then connections)1
Asset structure
Connection
An API connection requires a name and qualifiedName. For creation, specific settings are also required to distinguish it as an API connection rather than another type of connection. In addition, at least one of adminRoles, adminGroups, or adminUsers must be provided.
- Java
- Python
- Kotlin
- Raw REST API
String adminRoleGuid = client.getRoleCache().getIdForName("$admin"); // (1)
Connection connection = Connection.creator( // (2)
"api-connection", // (3)
AtlanConnectorType.API, // (4)
List.of(adminRoleGuid), // (5)
List.of("group2"), // (6)
List.of("jsmith")) // (7)
.build();
AssetMutationResponse response = connection.save(client); // (8)
String connectionQualifiedName = response.getCreatedAssets().get(0).getQualifiedName(); // (9)
- Retrieve the GUID for the admin role, to use later for defining the roles that can administer the connection.
- Build up the minimum request to create a connection.
- Provide a human-readable name for your connection, such as
productionordevelopment. - Set the type of connection to API.
- List the workspace roles that should be able to administer the connection (or null if none). All users with that workspace role (current and future) will be administrators of the connection. Note that the values here need to be the GUIDs of the workspace roles. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - List the group names that can administer this connection (or null if none). All users within that group (current and future) will be administrators of the connection. Note that the values here are the names of the groups. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - List the user names that can administer this connection (or null if none). Note that the values here are the usernames of the users. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - Actually call Atlan to create the connection. Because this operation will persist the asset in Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant. - Retrieve the qualifiedName for use in subsequent creation calls. (You'd probably want to do some null checking first.)
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import Connection, APISpec, APIPath, APIObject, APIQuery, APIField
from pyatlan.model.enums import AtlanConnectorType, APIQueryParamTypeEnum
client = AtlanClient()
admin_role_guid = client.role_cache.get_id_for_name("$admin") # (1)
connection = Connection.creator( # (2)
client=client, # (3)
name="api-connection", # (4)
connector_type=AtlanConnectorType.API, # (5)
admin_roles=[admin_role_guid], # (6)
admin_groups=["group2"], # (7)
admin_users=["jsmith"] # (8)
)
response = client.asset.save(connection) # (9)
connection_qualified_name = response.assets_created(asset_type=Connection)[0].qualified_name # (10)
- Retrieve the GUID for the admin role, to use later for defining the roles that can administer the connection.
- Build up the minimum request to create a connection.
- You must provide a client instance.
- Provide a human-readable name for your connection, such as
productionordevelopment. - Set the type of connection to API.
- List the workspace roles that should be able to administer the connection (or
Noneif none). All users with that workspace role (current and future) will be administrators of the connection. Note that the values here need to be the GUIDs of the workspace roles. At least one ofadmin_roles,admin_groups, oradmin_usersmust be provided. - List the group names that can administer this connection (or
Noneif none). All users within that group (current and future) will be administrators of the connection. Note that the values here are the names of the groups. At least one ofadmin_roles,admin_groups, oradmin_usersmust be provided. - List the user names that can administer this connection (or
Noneif none). Note that the values here are the usernames of the users. At least one ofadmin_roles,admin_groups, oradmin_usersmust be provided. - Actually call Atlan to create the connection.
- Retrieve the
qualified_namefor use in subsequent creation calls. (You'd probably want to do some null checking first.)
val adminRoleGuid = client.roleCache.getIdForName("\$admin"); // (1)
val connection = Connection.creator( // (2)
"api-connection", // (3)
AtlanConnectorType.API, // (4)
listOf(adminRoleGuid), // (5)
listOf("group2"), // (6)
listOf("jsmith")) // (7)
.build()
val response = connection.save(client) // (8)
val connectionQualifiedName = response.createdAssets[0].qualifiedName // (9)
- Retrieve the GUID for the admin role, to use later for defining the roles that can administer the connection.
- Build up the minimum request to create a connection.
- Provide a human-readable name for your connection, such as
productionordevelopment. - Set the type of connection to API.
- List the workspace roles that should be able to administer the connection (or null if none). All users with that workspace role (current and future) will be administrators of the connection. Note that the values here need to be the GUIDs of the workspace roles. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - List the group names that can administer this connection (or null if none). All users within that group (current and future) will be administrators of the connection. Note that the values here are the names of the groups. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - List the user names that can administer this connection (or null if none). Note that the values here are the usernames of the users. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - Actually call Atlan to create the connection. Because this operation will persist the asset in Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant. - Retrieve the qualifiedName for use in subsequent creation calls. (You'd probably want to do some null checking first.)
{
"entities": [
{
"typeName": "Connection", // (1)
"attributes": {
"name": "api-connection", // (2)
"connectorName": "api", // (3)
"qualifiedName": "default/api/123456789", // (4)
"category": "API", // (5)
"adminRoles": [ // (6)
"e7ae0295-c60a-469a-bd2c-fb903943aa02"
],
"adminGroups": [ // (7)
"group2"
],
"adminUsers": [ // (8)
"jsmith"
]
}
}
]
}
- The
typeNamemust be exactlyConnection. - Human-readable name for your connection, such as
productionordevelopment. - The
connectorNamemust be exactlyapi. - The
qualifiedNameshould follow the pattern:default/api/<epoch>, where<epoch>is the time in milliseconds at which the connection is being created. - The
categorymust beAPI. - List any workspace roles that can administer this connection. All users with that workspace role (current and future) will be administrators of the connection. Note that the values here need to be the GUIDs of the workspace roles. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - List any groups that can administer this connection. All users within that group (current and future) will be administrators of the connection. Note that the values here are the names of the groups. At least one of
adminRoles,adminGroups, oradminUsersmust be provided. - List any users that can administer this connection. Note that the values here are the usernames of the users. At least one of
adminRoles,adminGroups, oradminUsersmust be provided.
Atlan creates the policies that grant access to a connection, including the ability to retrieve the connection and to create assets within it, asynchronously. It can take several seconds (even up to approximately 30 seconds) before these are in place after creating the connection.
You may therefore need to wait before you'll be able to create the assets below within the connection.
To confirm access, retrieve the connection after it has been created. The SDKs' retry loops will automatically retry until the connection can be successfully retrieved. At that point, your API token has permission to create the other assets.
Note: if you are reusing an existing connection rather than creating one via your API token, you must give your API token a persona that has access to that connection. Otherwise all attempts to create, read, update, or delete assets within that connection will fail due to a lack of permissions.
APISpec
An API spec requires a name and a qualifiedName. For creation, you also need to specify the connectionQualifiedName of the connection for the spec.
- Java
- Python
- Kotlin
- Raw REST API
APISpec apiSpec = APISpec.creator( // (1)
"api-spec", // (2)
connectionQualifiedName) // (3)
.build();
AssetMutationResponse response = apiSpec.save(client); // (4)
apiSpec = response.getResult(apiSpec); // (5)
- Build up the minimum request to create a spec.
- Provide a human-readable name for your spec.
- Provide the qualifiedName of the connection for this spec.
- Actually call Atlan to create the spec. Because this operation will persist the asset in Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant. - Retrieve the created spec for use in subsequent creation calls. (You'd probably want to do some null checking first.)
apiSpec = APISpec.creator( # (1)
name = "api-spec", # (2)
connection_qualified_name = connection_qualified_name # (3)
)
response = client.asset.save(apiSpec) # (4)
spec_qualified_name = response.assets_created(asset_type=APISpec)[0].qualified_name # (5)
- Build up the minimum request to create an spec.
- Provide a human-readable name for your spec.
- Provide the
qualified_nameof the connection for this spec. - Actually call Atlan to create the spec.
- Retrieve the created spec for use in subsequent creation calls. (You'd probably want to do some null checking first.)
var apiSpec = APISpec.creator( // (1)
"api-spec", // (2)
connectionQualifiedName) // (3)
.build()
val response = apiSpec.save(client) // (4)
apiSpec = response.getResult(apiSpec) // (5)
- Build up the minimum request to create a spec.
- Provide a human-readable name for your spec.
- Provide the qualifiedName of the connection for this spec.
- Actually call Atlan to create the spec. Because this operation will persist the asset in Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant. - Retrieve the created spec for use in subsequent creation calls. (You'd probably want to do some null checking first.)
{
"entities": [
{
"typeName": "APISpec", // (1)
"attributes": {
"name": "api-spec", // (2)
"qualifiedName": "default/api/123456789/api-spec", // (3)
"connectionQualifiedName": "default/api/123456789", // (4)
"connectorName": "api" // (5)
}
}
]
}
- The
typeNamemust be exactlyAPISpec. - Human-readable name for your spec.
- The
qualifiedNameshould follow the pattern:default/api/<epoch>/<specName>, wheredefault/api/<epoch>is the qualifiedName of the connection for this spec and<specName>is the name of this spec. - The
connectionQualifiedNamemust be the exact qualifiedName of the connection for this spec. - The
connectorNamemust be exactlyapi.
APIPath
An API path requires a name and a qualifiedName. For creation, you also need to specify the connectionQualifiedName of the connection for the path and the apiSpec the path is in. If the name of your path does no give the URI of the endpoint it represents, be sure to also specify the apiPathRawURI.
- Java
- Python
- Kotlin
- Raw REST API
APIPath apiPath = APIPath.creator( // (1)
"/api/path", // (2)
apiSpec) // (3)
.build();
AssetMutationResponse response = apiPath.save(client); // (4)
- Build up the minimum request to create a path.
- Provide the unique endpoint URI for this path. (The SDK will also use this by default as the name for the path. If you want a different name, simply add a
.name()call onto the builder with your preferred name.) - Provide the spec for this path. If you didn't already have the object, you could also use
APISpec.refByGuid()with the GUID of the spec, orAPISpec.refByQualifiedName()with thequalifiedNameof the spec. - Actually call Atlan to create the path. Because this operation will persist the asset in Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant.
apiPath = APIPath.creator( # (1)
path_raw_uri = "/api/path", # (2)
spec_qualified_name = spec_qualified_name # (3)
)
response = client.asset.save(apiPath) # (4)
- Build up the minimum request to create an path.
- Provide the unique endpoint URI for this path.
- Provide the
qualified_nameof the API path. - Actually call Atlan to create the path.
val apiPath = APIPath.creator( // (1)
"/api/path", // (2)
apiSpec) // (3)
.build()
val response = apiPath.save(client) // (4)
- Build up the minimum request to create a path.
- Provide the unique endpoint URI for this path. (The SDK will also use this by default as the name for the path. If you want a different name, simply add a
.name()call onto the builder with your preferred name.) - Provide the spec for this path. If you didn't already have the object, you could also use
APISpec.refByGuid()with the GUID of the spec, orAPISpec.refByQualifiedName()with thequalifiedNameof the spec. - Actually call Atlan to create the path. Because this operation will persist the asset in Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant.
{
"entities": [
{
"typeName": "APIPath", // (1)
"attributes": {
"name": "/api/path", // (2)
"apiPathRawURI": "/api/path", // (3)
"qualifiedName": "default/api/123456789/api-spec/api/path", // (4)
"connectionQualifiedName": "default/api/123456789", // (5)
"connectorName": "api", // (6)
"apiSpec": { // (7)
"typeName": "APISpec", // (8)
"uniqueAttributes": { // (9)
"qualifiedName": "default/api/123456789/api-spec"
}
}
}
}
]
}
- The
typeNamemust be exactlyAPIPath. - Human-readable name for your path.
- The
apiPathRawURIshould be the unique endpoint URI this path represents. - The
qualifiedNameshould follow the pattern:default/api/<epoch>/<specName>/<apiPathRawURI>, wheredefault/api/<epoch>/<specName>is the qualifiedName of the spec for this path and<apiPathRawURI>is the unique endpoint URI the path represents. - The
connectionQualifiedNamemust be the exact qualifiedName of the connection for this path. - The
connectorNamemust be exactlyapi. - The spec in which this path exists is embedded in the
apiSpecattribute. - The
typeNamefor this embedded reference must beAPISpec. - To complete the reference, you must include a
uniqueAttributesobject with the qualifiedName of the spec. Note: the spec must already exist in Atlan before creating the path.
APIObject
An API object requires a name and a qualifiedName. For creation, you also need to specify the connectionQualifiedName of the connection for the object. Optionally, you can also provide the count of API field that exists in the object as apiFieldCount.
- Python
- Raw REST API
apiObject = APIObject.creator( # (1)
name = "api-object", # (2)
connection_qualified_name = connection_qualified_name, # (3)
api_field_count = 2 # (4)
)
response = client.asset.save(apiObject) # (5)
object_qualified_name = response.assets_created(asset_type=APIObject)[0].qualified_name # (6)
- Build up the minimum request to create an object.
- Provide a human-readable name for your object.
- Provide the
qualified_nameof the connection for this object. - Provide the count of fields that exist in the object. Use None if no field exists in this object.
- Actually call Atlan to create the object.
- Retrieve the created object for use in subsequent creation calls. (You'd probably want to do some null checking first.)
{
"entities": [
{
"typeName": "APIObject", // (1)
"attributes": {
"name": "api-object", // (2)
"qualifiedName": "default/api/123456789/api-object", // (3)
"connectionQualifiedName": "default/api/123456789", // (4)
"connectorName": "api", // (5)
"apiFieldCount": 2 // (6)
}
}
]
}
- The
typeNamemust be exactlyAPIObject. - Human-readable name for your object.
- The
qualifiedNameshould follow the pattern:default/api/<epoch>/<objectName>, wheredefault/api/<epoch>is the qualifiedName of the connection for this object and<objectName>is the name of this object. - The
connectionQualifiedNamemust be the exact qualifiedName of the connection for this object. - The
connectorNamemust be exactlyapi. - The
apiFieldCountshould be the count of the fields present in the object. This isn't a required attribute and can be excluded.
APIQuery
An API query requires a name and a qualifiedName. For creation, you also need to specify the connectionQualifiedName of the connection for the query.
Optionally, you can provide other attribute which enrich the query asset. Like apiInputFieldCount to store the count of input API fields in the query. apiQueryOutputType and apiQueryOutputTypeSecondary to store the query output types. If the query refers to an object in its output, it requires apiIsObjectReference and apiObjectQualifiedName to be populated.
- Python
- Raw REST API
apiQuery = APIQuery.creator( # (1)
name = "api-query", # (2)
connection_qualified_name = connection_qualified_name, # (3)
api_input_field_count = 2, # (4)
api_query_output_type="api-object-ref", # (5)
api_query_output_type_secondary="Object", # (6)
is_object_reference=True, # (7)
reference_api_object_qualified_name="default/api/123456789/api-object-ref" # (8)
)
response = client.asset.save(apiQuery) # (9)
query_qualified_name = response.assets_created(asset_type=APIQuery)[0].qualified_name # (10)
- Build up the minimum request to create a query.
- Provide a human-readable name for your query.
- Provide the
qualified_nameof the connection for this query. - Provide the count of input fields that exist in the query. Use
Noneif no input field exists in this query. - Provide the primary type for the output of the query. E.g.: If Object/api-obj-ref, then api-obj-ref is primary.
- Provide the secondary type for the output of the query. E.g.: If Object/api-obj-ref, then Object is secondary.
- If the Output of the query refers to an object make it True or else False.
- If
is_object_referenceis True, provide the qualified name of the object this query refers to in output. OrNone. - Actually call Atlan to create the query.
- Retrieve the created query for use in subsequent creation calls. (You'd probably want to do some null checking first.)
{
"entities": [
{
"typeName": "APIQuery", // (1)
"attributes": {
"name": "api-query", // (2)
"qualifiedName": "default/api/123456789/api-query", // (3)
"connectionQualifiedName": "default/api/123456789", // (4)
"connectorName": "api", // (5)
"apiInputFieldCount": 2, // (6)
"apiQueryOutputType": "api-object-ref", // (7)
"apiQueryOutputTypeSecondary": "Object", // (8)
"apiIsObjectReference": true, // (9)
"apiObjectQualifiedName": "default/api/123456789/api-object-ref" // (10)
}
}
]
}
- The
typeNamemust be exactlyAPIQuery. - Human-readable name for your query.
- The
qualifiedNameshould follow the pattern:default/api/<epoch>/<queryName>, wheredefault/api/<epoch>is the qualifiedName of the connection for this query and<queryName>is the name of this query. - The
connectionQualifiedNamemust be the exact qualifiedName of the connection for this query. - The
connectorNamemust be exactlyapi. - The
apiInputFieldCountshould be the count of the input fields present in the object. For no input fields, remove the attribute from the request. - The
apiQueryOutputTypeis the primary type for the output of the query. E.g.: If Object/api-obj-ref, then api-obj-ref is primary. - The
apiQueryOutputTypeSecondaryis the secondary type for the output of the query. E.g.: If Object/api-obj-ref, then Object is secondary. - The
apiIsObjectReferenceshould be true when the query refers to an object in its output. - The
apiObjectQualifiedNameis the qualified name of the object this query refers to in its output. Remove attribute whenapiIsObjectReferenceis false.
APIField
An API field requires a name and a qualifiedName. For creation, you also need to specify the connectionQualifiedName of the connection for the field and either the apiObject or the apiQuery the field is in.
Optionally, you can provide other attribute which enrich the field asset. Like apiFieldType and apiFieldTypeSecondary to store the field types. If the field refers to an object, it requires apiIsObjectReference and apiObjectQualifiedName to be populated.
APIField inside APIObject
- Python
- Raw REST API
apifield = APIField.creator( # (1)
name = "api-field", # (2)
parent_api_object_qualified_name = object_qualified_name, # (3)
parent_api_query_qualified_name = None, # (4)
connection_qualified_name = connection_qualified_name, # (5)
api_field_type="api-object-ref", # (6)
api_field_type_secondary="Object", # (7)
is_api_object_reference=True, # (8)
reference_api_object_qualified_name="default/api/123456789/api-object-ref", # (9)
api_query_param_type=None # (10)
)
response = client.asset.save(apifield) # (11)
- Build up the minimum request to create a field.
- Provide the human-readable name for this field.
- Provide the
qualified_nameof the API object, this field exists in. Nonefor when this object exists in an object and not in a query.- Provide the
qualified_nameof the connection for this field. - Provide the primary type of the field.
- Provide the secondary type of the field.
- True when the field refers to an object. Else False.
- Provide the
qualified_nameof the API object this field refers to.Nonewhenis_api_object_referenceis False. Nonewhen field is inside an object. Holds Enum value when inside a query as input.- Actually call Atlan to create the path.
{
"entities": [
{
"typeName": "APIField", // (1)
"attributes": {
"name": "api-field", // (2)
"qualifiedName": "default/api/123456789/api-object/api-field", // (3)
"connectionQualifiedName": "default/api/123456789", // (4)
"connectorName": "api", // (5)
"apiFieldType": "String", // (6)
"apiFieldTypeSecondary": "String", // (7)
"apiObject": { // (8)
"typeName": "APIObject", // (9)
"uniqueAttributes": { // (10)
"qualifiedName": "default/api/123456789/api-object"
}
},
"apiIsObjectReference": true, // (11)
"apiObjectQualifiedName": "default/api/123456789/api-object-ref" // (12)
}
}
]
}
- The
typeNamemust be exactlyAPIField. - Human-readable name for your field.
- The
qualifiedNameshould follow the pattern:default/api/<epoch>/<objectName>/<fieldName>, wheredefault/api/<epoch>/<objectName>is the qualifiedName of the object for this field and<fieldName>is the human-readable name of the field. - The
connectionQualifiedNamemust be the exact qualifiedName of the connection for this field. - The
connectorNamemust be exactlyapi. - The
apiFieldTypeis the primary type of the field. - The
apiFieldTypeSecondaryis the secondary type of the field. - The object in which this field exists is embedded in the
apiObjectattribute. - The
typeNamefor this embedded reference must beAPIObject. - To complete the reference, you must include a
uniqueAttributesobject with the qualifiedName of the object. Note: the object must already exist in Atlan before creating the path. - The
apiIsObjectReferenceshould be true when this field refers to an object. - The
apiObjectQualifiedNameshould incldue the reference object qualified_name whenapiIsObjectReferenceis true.
APIField inside APIQuery
- Python
- Raw REST API
apifield = APIField.creator( # (1)
name = "api-field", # (2)
parent_api_object_qualified_name = None, # (3)
parent_api_query_qualified_name = query_qualified_name, # (4)
connection_qualified_name = connection_qualified_name, # (5)
api_field_type="api-object-ref", # (6)
api_field_type_secondary="Object", # (7)
is_api_object_reference=True, # (8)
reference_api_object_qualified_name="default/api/123456789/api-object-ref", # (9)
api_query_param_type=APIQueryParamTypeEnum.INPUT # (10)
)
response = client.asset.save(apifield) # (11)
- Build up the minimum request to create a field.
- Provide the human-readable name for this field.
Nonefor when this object exists in a query and not in an object.- Provide the
qualified_nameof the API query, this field exists in. - Provide the
qualified_nameof the connection for this field. - Provide the primary type of the field.
- Provide the secondary type of the field.
- True when the field refers to an object. Else False.
- Provide the
qualified_nameof the API object this field refers to.Nonewhenis_api_object_referenceis False. - Provide the enum value INPUT, if the field is an input to the query.
- Actually call Atlan to create the path.
{
"entities": [
{
"typeName": "APIField", // (1)
"attributes": {
"name": "api-field", // (2)
"qualifiedName": "default/api/123456789/api-query/api-field", // (3)
"connectionQualifiedName": "default/api/123456789", // (4)
"connectorName": "api", // (5)
"apiFieldType": "String", // (6)
"apiFieldTypeSecondary": "String", // (7)
"apiQuery": { // (8)
"typeName": "APIQuery", // (9)
"uniqueAttributes": { // (10)
"qualifiedName": "default/api/123456789/api-query"
}
},
"apiIsObjectReference": true, // (11)
"apiObjectQualifiedName": "default/api/123456789/api-object-ref", // (12)
"apiQueryParamType": "Input" // (13)
}
}
]
}
- The
typeNamemust be exactlyAPIField. - Human-readable name for your field.
- The
qualifiedNameshould follow the pattern:default/api/<epoch>/<queryName>/<fieldName>, wheredefault/api/<epoch>/<queryName>is the qualifiedName of the query for which this field is an input and<fieldName>is the human-readable name of the field. - The
connectionQualifiedNamemust be the exact qualifiedName of the connection for this field. - The
connectorNamemust be exactlyapi. - The
apiFieldTypeis the primary type of the field. - The
apiFieldTypeSecondaryis the secondary type of the field. - The query in which this field exists is embedded in the
apiQueryattribute. - The
typeNamefor this embedded reference must beAPIQuery. - To complete the reference, you must include a
uniqueAttributesobject with the qualifiedName of the query. Note: the object must already exist in Atlan before creating the path. - The
apiIsObjectReferenceshould be true when this field refers to an object. - The
apiObjectQualifiedNameshould incldue the reference object qualified_name whenapiIsObjectReferenceis true. - The
apiQueryParamTypeshould be present when the field is an input to a query. The value must exactly be "Input".
Available relationships
Every level of the API structure is an Asset, and can therefore be related to the following other assets.