Get external artifacts
Example: Get the artifacts list of an external connector
Last update: 2024-01-27
This request retrieves and prints information about external connector artifacts using a pre-established connection to your connector.
The following operations are demonstrated:
Load environment variables (your connector configs) from a .env file.
Establish a connection to your TSG connector.
Retrieve and print information about external connector self-description
Extract (from self-descriptions) information regarding available artifacts
Important
Ensure that the required environment variables (Your Connector API_KEY, CONNECTOR_ID, ACCESS_URL and AGENT_ID) are set in the .env file before using this request.
The connector API_KEY can be retrieved by loging into the TSG connector UI and navigating to the ‘API Keys’ tab.
Execute the code below to get your connector self-description artifacts list.
1if __name__ == "__main__":
2 from pprint import pprint
3 from loguru import logger
4 from dotenv import dotenv_values
5 from tsg_client.controllers import TSGController
6
7 # Comment the line below to enable internal logger:
8 logger.disable("")
9
10 # Load environment variables:
11 config = dotenv_values('.env')
12
13 # Example of external connector configs (TNO Playground)
14 EXTERNAL_CONNECTOR = {
15 "CONNECTOR_ID": 'urn:playground:tsg:connectors:TestConnector',
16 "ACCESS_URL": 'https://test-connector.playground.dataspac.es',
17 "AGENT_ID": 'urn:playground:tsg:TNO'
18 }
19
20 # Connect to our TSG connector:
21 conn = TSGController(
22 api_key=config['API_KEY'],
23 connector_id=config['CONNECTOR_ID'],
24 access_url=config['ACCESS_URL'],
25 agent_id=config['AGENT_ID']
26 )
27
28 # Get external connector info (self-descriptions):
29 self_description = conn.get_connector_selfdescription(
30 access_url=EXTERNAL_CONNECTOR['ACCESS_URL'],
31 connector_id=EXTERNAL_CONNECTOR['CONNECTOR_ID'],
32 agent_id=EXTERNAL_CONNECTOR['AGENT_ID']
33 )
34
35 resource_type = "ids:ContractOffer"
36
37 # Get artifacts list (note that you can refine your search using the
38 # cursom filters below):
39 artifacts = conn.parse_catalog_artifacts(
40 self_description,
41 catalog_id=self_description.catalogs[0].id,
42 resource_type=resource_type,
43 creation_date_gt="2021-08-10T00:00:00.000Z",
44 creation_date_lt="2030-01-01T00:00:00.000Z",
45 return_last_artifact=True,
46 valid_contract_only=False
47 )
48
49 print("-" * 79)
50 print(f"> Connector {EXTERNAL_CONNECTOR['CONNECTOR_ID']} in "
51 f"catalog {self_description.catalogs[0].id} with "
52 f"resource type {resource_type} has this list artifacts:")
53 pprint(artifacts)