# Carbon Footprint

## Carbon Footprint API <a href="#carbon-footprint-api" id="carbon-footprint-api"></a>

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](https://app.cooler.dev/settings).

#### Parameters <a href="#parameters" id="parameters"></a>

| 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 <a href="#code-examples" id="code-examples"></a>

```json

{
  "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 <a href="#code-examples" id="code-examples"></a>

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**

```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**

```shell
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"
      }
    ]
  }'
```

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cooler.dev/api-reference/carbon-footprint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
