Checking for deprecation or sunsetting
Cadmatic follows a formal process of marking outdated endpoints first as deprecated and then as sunset, before finally removing them from the API. This process is described in more detail in Endpoint deprecation process.
Code example
The following Python code shows how to detect if a given endpoint is either deprecated or sunset by checking whether the HTTP header of the response includes either "Deprecation" or "Sunset". The same approach can be used with any endpoint in the Web API, to automate a pre-processing step.
Copy
from requests import Session, post
base_url = "http://localhost:25000"
client_id = "FF8036A4FA288DF28F121FBB26A6922F"
client_secret = "UHcIvsh7BUT023fXpu7tBdNo2NSJI4Wz3qwOgAM5xvI="
def create_session() -> Session:
"""Create an authenticated session to use with the Web API
"""
token_url = base_url+"/api/token"
reply = post(token_url, json={
"ClientID": client_id,
"ClientSecret": client_secret})
if reply.status_code != 200:
raise Exception("Authentication failure")
token = reply.json()["token"]
session = Session()
session.headers.update({'Authorization': 'Bearer '+token})
return session
with create_session() as session:
# Use the first configured project database
projects = session.get(base_url+"/api/servers/projects").json()
project_database = projects[0]["project"]
parts = session.get(base_url+f"/api/{project_database}/parts/")
if "Deprecation" in parts.headers.keys():
print("Deprecated endpoint used")
if "Sunset" in parts.headers.keys():
print("Sunset endpoint used")