Introduction
Renewable energy projects displace or ‘offset’ fossil fuel power plants that would have otherwise polluted. This is true for generators like photovoltaics and wind, as well as flexibility assets like batteries. Our historic marginal emission data and forecast marginal emission provide asset and location specific data on carbon avoidance.
Calculate abatement for a file
Flow
To get the carbon abatement, developers need to upload the file through a presigned URL to AITL servers. This triggers a pipeline to calculate carbon abatement which is returned to the developer through an API. Please see the following steps to understand how to fetch carbon abatement for your data
Generate URL to upload
You will have to create a new presigned URL for every new file that you would like to upload
When a presigned URL is generated, a temporary, pre-autenticated upload space is created on the backend allowing developers to upload their file. The upload function returns a file hash which - ensure to save the hash to get the carbon abatement for the file you have uploaded in the APIs described after the Upload section. Generating this URL will not upload the file - it just informs that backend that you are an authenticated user that who is trying to upload a file. Uploading the file through the presigned URL is covered in the next step.
import requests
file_name = 'yourfile.csv' #CSV support only
url = 'https://34rq17drb9.execute-api.eu-central-1.amazonaws.com/dev'
resource_path = '/upload/{file_name}' #Please ensure to substitute the name of your file with the extension here
r = requests.get(url)
print(r.json())
Make sure you substitute
file_name
with the extention as per the file that you are uploading.
The above API returns the below response
{
"data": {
"url": "YOUR PRESIGNED URL ",
"hash": "dc0c339e-b50b-4ee7-aa14-bb05e3ad3bea"
},
"message": "Success"
}
Uploading through URL
With the presigned url you can construct the following request - this uploads the file to AITL's backend
import requests
url = "YOUR_PRESIGNED_URL"
file_name = 'yourfile.csv'
headers = {
'x-amz-meta-filename': file_name,
'Content-Type': 'text/csv'
}
with open('file_name','rb') as payload:
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
This API will not return a response on successful upload
Fetch carbon abated
Using the hash value returned by the upload API, developers can fetch the carbon abatement value for the file uploaded
import requests
file_hash = 'hash' # hash object from the upload API
url = 'https://34rq17drb9.execute-api.eu-central-1.amazonaws.com/dev'
resource_path = '/carbonabatement/{file_hash}' #Please ensure to substitute the name of your file with the extension here
response = requests.request("GET", url+resource_path)
print(response.text)
The above command returns JSON structured like this:
{
"data": {
"total_carbon_abated": 7.99
},
"message": "Success"
}
Get carbon abated for a time range
Using the from_date and to_date, developers can fetch value for carbon abated in that timeframe
import requests
url = 'https://y2qd62321f.execute-api.eu-central-1.amazonaws.com/dev?from_date={from_date}&to_date={to_date}'
# In the headers, pass the api key like this
headers = {
'authorizationToken': <api key>
}
response = requests.request("GET", url.format(**{'from_date':'2022-02-14 00:00:00', 'to_date':'2022-02-15 00:00:00'}),headers=headers)
print(response.text)
The above command returns JSON structured like this:
{
"data": [
{
"carbon_abatement": {},
"last_updated": "2022-04-16 13:38:42.709132+00:00",
"total": 7.99
}
],
"message": "Success"
}
Errors
The Cepro uses the following error codes:
Error Code | Meaning |
---|---|
400 | Bad Request -- Your request is invalid. |
401 | Unauthorized -- Your API key is wrong. |
403 | Forbidden -- Your headers are either incorrect on the presigned URL or your presigned URL has expired. |
404 | Not Found -- The specified kitten could not be found. |
500 | Internal Server Error |