Code Examples

Examples of requests using our API endpoints

Below are some examples of queries in Javascipt and Python. For more code samples, please look at the SDKs

Get API token from Developer token

Javascript

const axios = require('axios');
async function fetchData() {
    try {
      const response = await axios.get('https://app.2050-materials.come/developer/api/getapitoken', {
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer YOUR_API_TOKEN',
        },
        mode: 'no-cors'
      });
      console.log(response.data);
    } catch (error) {
      console.error('Error fetching data: ', error);
    }
  }
  
  fetchData();

Python

Get building board products with an EPD

Step 1: Render filters and create dictionaries for filtering

Limited data: /get_products_open_api

Expanded data: /get_products

Generic Data: /get_generic_materials

Retrieve Warming Potential and EC for a High-Rise Residential building /get_co2_warming_potential

Flow to retrieve tokens, get filters, and render building boards with EPDs in Canada.

Step 1: Obtain Bearer Token

Step 2: Get Filters and Create Dictionaries for Product Types, Material Types, and Certificate Types

Step 3: Use Filters to Call get_products API and Create DataFrame

Notes:

  1. Error Handling: The code includes try-except blocks to handle potential request errors.

  2. Bearer Token: Ensure to replace {{Developer Token}} with your actual developer token.

  3. Filters: The code dynamically creates dictionaries for different filter types based on the response from the get_product_filters endpoint.

  4. DataFrame Creation: The final step converts the product data into a pandas DataFrame for easy manipulation and analysis.

Last updated

Was this helpful?