Skip to main content

Prerequisites

  • A Hey Chocolate account with an API key (sign up here)
  • A tool to make GraphQL requests (cURL, Postman, or any GraphQL client)

Step 1: Get your API key

Navigate to the Dashboard and create a new API key under Settings > API Keys.
Keep your API key secret. Never expose it in client-side code. Use server-side requests or a backend proxy.

Step 2: Make your first query

Send a GraphQL request to the Hey Chocolate API endpoint:
curl -X POST https://api.heychocolate.com/graphql \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your_api_key_here" \
  -d '{
    "query": "{ products(first: 5) { edges { node { id name sectorTag impactScore { co2Equivalent mkiScore unit } } } } }"
  }'
Response:
{
  "data": {
    "products": {
      "edges": [
        {
          "node": {
            "id": "prod_abc123",
            "name": "Bio-based Window Frame",
            "sectorTag": "HIGHTECH_MANUFACTURING",
            "impactScore": {
              "co2Equivalent": 12.4,
              "mkiScore": 0.87,
              "unit": "kg_co2e"
            }
          }
        }
      ]
    }
  }
}

Step 3: Calculate an impact score

Use the calculateImpact mutation to compute a real-time sustainability score:
mutation {
  calculateImpact(input: {
    productId: "prod_abc123"
    quantity: 100
    transportMethod: TRUCK
    distance: 250
    distanceUnit: KM
  }) {
    totalCo2Equivalent
    mkiScore
    equivalency {
      description
      value
      icon
    }
  }
}
Response:
{
  "data": {
    "calculateImpact": {
      "totalCo2Equivalent": 1240.0,
      "mkiScore": 87.0,
      "equivalency": {
        "description": "Equivalent to driving a car",
        "value": "4,800 km",
        "icon": "car"
      }
    }
  }
}

Step 4: Explore further