Carbon Footprint

Carbon Footprint API

The Footprint endpoint calculates and returns the carbon footprint(s) for one or more products within a single transaction, given a well-formed JSON request containing required properties, as shown in the examples below. Note that all footprint requests must include your API key from your Cooler account.

Parameters

KEY

TYPE

DESCRIPTION

EXAMPLE

productName*

string

name or title of the product

Samsung A7 Galaxy

productDescription*

string

*product description

Keep up with life with your fast paced life with a phone that fits you, like the Samsung Galaxy A14 5G from Total by Verizon. With the speed of 5G and a powerful Galaxy processor, you can experience your day virtually lag-free.

productPrice*

number

price of the product

500

postalCode

string

postal code of the product when it ships to the customer or your store

49503

newProduct

boolean

new=true, used=false

true

externalId

string

your system’s product id

your_product_id

Reponse Data


{
  "id": "1900b667-fbcf-4f0e-9512-b0f3b4e4e9f7",
  "items": [
    {
      "id": "35c627b9-8249-427a-a050-5e3360e67503",
      "submission": {
        "id": "f2480103-0aba-4c78-826e-c03a92e130ec",
        "zip": "02062",
        "currency": "USD",
        "title": "Samsung A7 Galaxy",
        "price": 500,
        "description": "Samsung A7 Galaxy",
        "newProduct": true, 
        "externalId": "id_you_assigned"
      },
      "footprint": {
        "id": "812c7561-8448-445a-b43b-43e0659e87a4",
        "currency": "USD",
        "expiresAt": "2025-01-20T22:41:10.430Z",
        "carbonFootprint": 1234,
        "carbonFootprintSavings": null
      }
    }
  ],
  "dateCreated": "2025-01-13T22:41:10.149Z",
  "dateUpdated": "2025-01-13T22:41:10.149Z"
}

Code Examples

The following code examples use our test key—remember to replace the key with your own in your own code when calling the endpoints for production.

Javascript

const apiUrl = "https://api.cooler.dev/v2/footprint/products";
const headers = {
  "Content-Type": "application/json",
  "Cooler-Api-Key": "cooler_test_acaf38b8-5d04-4aa4-87fe-91a67fc13a05",
};

// Define the request payload
const requestBody = {
  items: [
    {
      productPrice: 500,
      productName: "Samsung A7 Galaxy",
      productDescription: "Samsung A7 Galaxy",
    },
  ],
};

// Make the POST request using fetch
fetch(apiUrl, {
  method: "POST", // Specify the HTTP method
  headers: headers, // Include headers
  body: JSON.stringify(requestBody), // Convert the payload to JSON
})
  .then((response) => {
    // Check if the response status is OK (200-299)
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    return response.json(); // Parse the JSON response
  })
  .then((data) => {
    console.log("Response:", data); // Log the successful response
  })
  .catch((error) => {
    console.error("An error occurred:", error.message); // Log any errors
  });

Curl

curl https://api.cooler.dev/v2/footprint/products \
  --request POST \
  --header "Content-Type: application/json" \
  --header "Cooler-Api-Key: cooler_test_acaf38b8-5d04-4aa4-87fe-91a67fc13a05" \
  --data '{
    "items": [
      {
        "productPrice": 500,
        "productName": "Samsung A7 Galaxy",
        "productDescription": "Samsung A7 Galaxy"
      }
    ]
  }'

Last updated