Getting started
Welcome to the Consupedia API Getting Started guide! If you're ready to harness Consupedia's sustainability data for your applications, services, or data analytics, you're in the right place. This guide aims to give you the key information to understand, select, and integrate our APIs effectively.
Following this guide, you'll get acquainted with the various integrations and services we offer, understanding which ones are best suited for your specific needs.
Whether you're an experienced developer or just starting with API integrations, our goal is to make your journey with the Consupedia API seamless. Alongside this guide, our comprehensive API reference documentation, tutorials, and dedicated support team are ready to equip you with the tools necessary for a successful integration with our sustainability data.
So let's start this journey together towards building more sustainable and informed applications!
Create an account
Before you start using our services you need to create an account and acquire an API-key.
At this time, this is done by contacting Consupedia's sale team at info@consupedia.com or the contact form on consupedia.com/team.
Subscribe to a product
In order to get sustainability data about a product, you need to subscribe to a it. You do this by using the subscription endpoint of the Connect API. The endpoint is POST /subscribe/ and you should send an array of the GTIN/EANS's (14 digits) you want to subscribe to.
Let's say we want to get sustainability data of a bottle of 'Coca Cola' with GTIN 05000112637922.
curl -X POST 'https://connect.consupedia.com/api/v2/subscribe/' \
-H 'X-API-KEY: your_api_key' \
-H 'Content-Type: application/json' \
-d '[
{
"gtin": "05000112637922",
}
]'Replace your_api_key with your own key.
We will get back a response with the result:
{
"status": "success",
"message": "Products subscribed",
"client": "Your name",
"productsSubscribed": 1,
"unknownProductsSubscribed": 0,
"productsSkipped": 0
}Get sustainability data
Now that we have subscribed to a product, we can get data. Since we only need data for our Coca Cola bottle, we will use the single endpoint of the Connect API. The endpoint is GET /products/:gtin.
curl -X GET 'https://connect.consupedia.com/api/v2/product/05000112637922' \
-H 'X-API-KEY: your_api_key' \
-H 'Content-Type: application/json' \'We will get back a response with the available data:
{
"id": 6450,
"gtin": "05000112637922",
"name": "Kolsyrad Läskedryck",
"climateScore": 80,
"CO2e": 0.09,
"novaScore": null,
"nutriScore": "E",
"healthScore": 15,
"antibioticsResistanceScore": 97.9,
"overconsumptionRisk": "",
"allergenList": "",
"socialJusticeScore": 75,
"equalityScore": 96,
"workerRightsScore": 94.7,
"animalProtectionScore": 85.7,
"childLaborScore": 100,
"biodiversityScore": 68.8,
"pesticidesUseScore": null,
"fertilizersUseScore": 94,
"landUseScore": null,
"waterScore": 58,
"transportScore": 95,
"packageInformation": "",
"isEco": null
}Receive data on update
Sustainability data, including Consupedia's dataset, is continually changing. For example, you might want to keep track of updates to the data for a Coca Cola bottle. One way to do this is to set up a regular task, or 'cron job', to query the product endpoint. However, a more efficient way is to use the Webhook service. This service sends you updates immediately when they occur, keeping you in the loop without the need for constant manual checking.
The steps we need to take to setup a webhook:
- Setup a small webservice that is exposed to the World Wide Web. See an example in node.js below.
- Generate a secret token and provide it to Consupedia along with the address to your webservice. You must also have this secret token securely stored on your server.
- When you receive a webhook request, retrieve the X-Hub-Signature-256 header from the request. This is the hash signature that Consupedia has computed from the payload and the secret token.
- Compute your own hash of the payload using the same algorithm and compare it with the hash signature from the request. If they match, the request is genuine.
- Now we can update our product database with the latest information from Consupedia as soon as it is available.
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const app = express();
const secret = 'your_secret_token'; // Replace with your actual secret token
app.use(bodyParser.json({
verify: (req, res, buf) => {
req.rawBody = buf;
}
}));
app.post('/webhook', (req, res) => {
// Retrieve the X-Hub-Signature-256 header
const signature = req.get('X-Hub-Signature-256');
// Compute our own hash of the payload
const hash = crypto.createHmac('sha256', secret)
.update(req.rawBody)
.digest('hex');
// Compare our hash with the hash signature from the request
if (signature !== `sha256=${hash}`) {
console.log('Request signature does not match computed signature');
return res.status(401).send('Invalid signature');
}
const data = req.body
console.log('Received data:', data);
// Now we can use our data!
res.status(200).send('OK');
});
const port = 3000;
app.listen(port, () => {
console.log(`Server is running and listening on port ${port}`);
});Next Steps
Get familiar with all the functionality of the Connect API here. If you have your own product data, it is possible to send the data when creating subscriptions.
For any technical support, send an email to tech-support@consupedia.com.