Skip to main content

How to make API calls with the Python SDK [Cognite Official]


Pierre  Pernot
Seasoned Practitioner

Hello,

I’m Pierre, data engineer at Cognite. I’ll be posting, on a regular basis, some useful tips about Cognite Data Fusion and its use. If you have any questions or remarks (technical or not), don’t hesitate to reach out to me or to create a new topic in Cognite Hub.

 

 

Some of the features of the Cognite API are not available in the Python SDK. You can still use those features by making a call to the desired endpoint. The SDK facilitates this process thanks to the get, post, put and delete methods of the Cognite client (see: https://cognite-docs.readthedocs-hosted.com/projects/cognite-sdk-python/en/latest/cognite.html#cogniteclient). Once your client is set up, all the auth process is taken care of by itself, it is very straight forward.

 

Example:

payload = {...}

endpoint_url = “/api/v1/projects/my-project/context/diagram/detect/”

response = client.post(endpoint_url, payload)

 

When a payload is needed, you can refer to the documentation to get insights on its structure. (Cognite API documentation: https://docs.cognite.com/api/v1/)

 

This tip could broaden your experience with Cognite Data Fusion and facilitate the use of the API. The SDK provides you the ability to make requests to the API in a really straight-forward way. This could help you tackle some challenges, using diagram contextualisation, Cognite functions, and other great features.

 

If you have any questions, don't hesitate to reach out to in this thread or in a new post.

2 replies

HanishSharma
Practitioner
Forum|alt.badge.img+3
  • Practitioner
  • 33 replies
  • August 6, 2024

Correction on this:

You don’t need the host URL in the endpoint

endpoint_url = '/api/v1/projects/slb-stic/assets?limit=100'

response = client.get(endpoint_url)

 


Pierre  Pernot
Seasoned Practitioner
  • Author
  • Seasoned Practitioner
  • 15 replies
  • August 21, 2024

Thank you @HanishSharma, I edited the post. 


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings