Bayou Energy QuickStart
Bayou Energy is the fastest way to access your customer's utility data. This page will help you get started with the product
If you haven't already, create an account here, https://staging.bayou.energy/users/sign_up
import requests
import time
# Bayou has two environments, staging, as shown below, and production, bayou_domain="bayou.energy"
bayou_domain = "staging.bayou.energy"
# Get and manage API keys at f"https://{bayou_domain}/dashboard/keys"
# API reference: https://docs.bayou.energy/v2.0/reference/authentication
bayou_api_key = "your key here"
# Create a new customer. API reference: https://docs.bayou.energy/v2.0/reference/post_customers
customer = requests.post(f"https://{bayou_domain}/api/v2/customers", json={
"utility": "speculoos_power", # Speculoos is Bayou's fake utility for testing, https://docs.bayou.energy/v2.0/reference/utility-support
"email" : "[email protected]" # Email address isn't a required field, https://docs.bayou.energy/docs/merge-customer-code-with-your-project
}, auth=(bayou_api_key, '')).json()
# We'll provide the customer onboarding link and credentials to complete the form in your terminal.
print(f"""
Fill the customer credentials using the following link: {customer['onboarding_link']}
For credentials: The email is [email protected] and the password is validpassword. We'll wait while you complete the form!
""")
# Bayou recommends listening for webhook events for updates about customer authentication and data availability.
# API reference: https://docs.bayou.energy/v2.0/reference/how-to-set-up-webhooks
# Below Bayou automatically refreshes customer records to simulate testing webhooks locally (this is the QUICKstart),
while not customer["has_filled_credentials"]: # Maps to customer_has_filled_credentials, https://docs.bayou.energy/v2.0/reference/customer_has_filled_credentials
time.sleep(3)
# We refresh the customer data until they have filled credentials
customer = requests.get(f"https://{bayou_domain}/api/v2/customers/{customer['id']}", auth=(bayou_api_key, '')).json()
print("The customer, in this case you, has filled credentials. First we'll call the /bills endpoint and print the first 12 bills. Fetching bills now!\n")
time.sleep(3) # Pause for 3 seconds to allow you to see that the above terminal message
while not customer["bills_are_ready"]: # Maps to bills_ready: https://docs.bayou.energy/v2.0/reference/event-informing-that-the-initial-bill-discovery-is-done-for-a-specific-customer
time.sleep(3)
# We refresh the customer data until their bills are ready
customer = requests.get(f"https://{bayou_domain}/api/v2/customers/{customer['id']}", auth=(bayou_api_key, '')).json()
# Get all bills for a specific customer. API reference: https://docs.bayou.energy/v2.0/reference/get_customers-customer-id-bills
bills = requests.get(f"https://{bayou_domain}/api/v2/customers/{customer['id']}/bills", auth=(bayou_api_key, '')).json()
# Now that we've fetched all bills, we're printing 12 for readability
print("\n")
for bill in bills[:12]:
print(bill)
time.sleep(10) # Pause for 10 seconds to allow you to quickly review bill data
print("\n","Now we'll call the /intervals endpoint and print the first 10 intervals for each meter. Fetching intervals now!")
time.sleep(3) # Pause for 3 seconds to allow you to see that the above terminal message
while not customer["intervals_are_ready"]:
time.sleep(3)
# We refresh the customer data until their intervals are ready
customer = requests.get(f"https://{bayou_domain}/api/v2/customers/{customer['id']}", auth=(bayou_api_key, '')).json()
# Get all intervals for a specific customer. API reference: https://docs.bayou.energy/v2.0/reference/get_customers-customer-id-intervals
intervals = requests.get(f"https://{bayou_domain}/api/v2/customers/{customer['id']}/intervals", auth=(bayou_api_key, '')).json()
for meter in intervals["meters"]:
print("\n",f"Intervals for meter {meter['id']}:")
# Now that we've fetched all intervals, we're printing 10 from each meter for readability
for interval in meter["intervals"][:10]:
print(interval)
time.sleep(10) # Pause for 10 seconds to allow you to quickly review interval data
print("""
Congratulations!
You’re ready to get customer utility data instantly with Bayou.
As a recommended next step, visit Bayou’s documentation for moving from QuickStart to deployment:
https://docs.bayou.energy/docs/merge-customer-code-with-your-project
Want to chat with the Bayou team? Book time here, https://calendly.com/jamesbayouenergy/30min or text James our CEO at +1 504 722 8987.
""")
const axios = require('axios');
// Bayou has two environments, staging, as shown below, and production, bayou_domain="bayou.energy"
const bayouDomain = "staging.bayou.energy";
// Get and manage API keys at `https://${bayouDomain}/dashboard/keys`
// API reference: https://docs.bayou.energy/v2.0/reference/authentication
const bayouApiKey = "your_api_key";
const authHeaders = { 'Authorization': `Basic ${Buffer.from(`${bayouApiKey}:`).toString('base64')}` };
async function createCustomer() {
// Create a new customer. API reference: https://docs.bayou.energy/v2.0/reference/post_customers
const response = await axios.post(`https://${bayouDomain}/api/v2/customers`, {
utility: "speculoos_power", // Speculoos is Bayou's fake utility for testing, https://docs.bayou.energy/v2.0/reference/utility-support
}, {
headers: {
'Content-Type': 'application/json',
...authHeaders,
},
});
let customer = response.data;
// We'll provide the customer onboarding link and credentials to complete the form in your terminal.
console.log(`
Fill the customer credentials using the following link: ${customer.onboarding_link}
For credentials: The email is [email protected] and the password is validpassword. We'll wait while you complete the form!
`);
// Bayou recommends listening for webhook events for updates about customer authentication and data availability.
// API reference: https://docs.bayou.energy/v2.0/reference/how-to-set-up-webhooks
// Below Bayou automatically refreshes customer records to simulate testing webhooks locally (this is the QUICKstart),
// Maps to customer_has_filled_credentials, https://docs.bayou.energy/v2.0/reference/customer_has_filled_credentials
while (!customer.has_filled_credentials) {
// We refresh the customer data until they have filled credentials
const response = await axios.get(`https://${bayouDomain}/api/v2/customers/${customer.id}`, { headers: authHeaders });
customer = response.data;
await new Promise(resolve => setTimeout(resolve, 3000));
}
console.log("The customer, in this case you, has filled credentials. First, we'll call the /bills endpoint and print the first 12 bills. Fetching bills now!\n");
await new Promise(resolve => setTimeout(resolve, 3000)); // Pause for 3 seconds to allow you to see that the above terminal message
// Maps to bills_ready: https://docs.bayou.energy/v2.0/reference/event-informing-that-the-initial-bill-discovery-is-done-for-a-specific-customer
while (!customer.bills_are_ready) {
// We refresh the customer data until their bills are ready
const response = await axios.get(`https://${bayouDomain}/api/v2/customers/${customer.id}`, { headers: authHeaders });
customer = response.data;
await new Promise(resolve => setTimeout(resolve, 3000));
}
// Get all bills for a specific customer. API reference: https://docs.bayou.energy/v2.0/reference/get_customers-customer-id-bills
const billResponse = await axios.get(`https://${bayouDomain}/api/v2/customers/${customer.id}/bills`, { headers: authHeaders });
const bills = billResponse.data;
// Now that we've fetched all bills, we're printing 12 for readability
console.log("\nFirst 12 bills:\n");
bills.slice(0, 12).forEach(bill => {
console.log(bill);
});
await new Promise(resolve => setTimeout(resolve, 10000)); // Pause for 10 seconds to allow you to quickly review bill data
console.log("\nNow we'll call the /intervals endpoint and print the first 10 intervals for each meter. Fetching intervals now!");
await new Promise(resolve => setTimeout(resolve, 3000)); // Pause for 3 seconds to allow you to see that the above terminal message
while (!customer.intervals_are_ready) {
// We refresh the customer data until their intervals are ready
const response = await axios.get(`https://${bayouDomain}/api/v2/customers/${customer.id}`, { headers: authHeaders });
customer = response.data;
await new Promise(resolve => setTimeout(resolve, 3000));
}
// Get all intervals for a specific customer. API reference: https://docs.bayou.energy/v2.0/reference/get_customers-customer-id-intervals
const intervalsResponse = await axios.get(`https://${bayouDomain}/api/v2/customers/${customer.id}/intervals`, { headers: authHeaders });
const intervals = intervalsResponse.data;
console.log("\nIntervals for each meter:\n");
intervals.meters.forEach(meter => {
// Now that we've fetched all intervals, we're printing 10 from each meter for readability
console.log(`\nIntervals for meter ${meter.id}:`);
meter.intervals.slice(0, 10).forEach(interval => {
console.log(interval);
});
});
await new Promise(resolve => setTimeout(resolve, 10000)); // Pause for 10 seconds to allow you to quickly review interval data
console.log(`Congratulations!
You’re ready to get customer utility data instantly with Bayou.
As a recommended next step, visit Bayou’s documentation for moving from QuickStart to deployment:
https://docs.bayou.energy/docs/merge-customer-code-with-your-project
Want to chat with the Bayou team? Book time here, https://calendly.com/jamesbayouenergy/30min or text James our CEO at +1 504 722 8987.`);
}
// Call the main function to start the process
createCustomer();
require 'net/http'
require 'uri'
require 'json'
require 'base64'
# Bayou has two environments, staging, as shown below, and production, bayou_domain="bayou.energy"
bayou_domain = "staging.bayou.energy"
# Get and manage API keys at f"https://#{bayou_domain}/dashboard/keys"
# API reference: https://docs.bayou.energy/v2.0/reference/authentication
bayou_api_key = "your_api_key"
auth_headers = {:'Authorization' => "Basic #{Base64.strict_encode64("#{bayou_api_key}:")}"}
# Create a new customer. API reference: https://docs.bayou.energy/v2.0/reference/post_customers
http = Net::HTTP.new(bayou_domain, 443)
http.use_ssl = true
response = http.post("/api/v2/customers", {
"utility" => "speculoos_power", # Speculoos is Bayou's fake utility for testing, https://docs.bayou.energy/v2.0/reference/utility-support
}.to_json,
{'Content-Type' => 'application/json', **auth_headers})
customer = JSON.parse(response.body)
# We'll provide the customer onboarding link and credentials to complete the form in your terminal.
puts <<~EOS
Fill the customer credentials using the following link: #{customer['onboarding_link']}
For credentials: The email is [email protected] and the password is validpassword. We'll wait while you complete the form!
EOS
# Bayou recommends listening for webhook events for updates about customer authentication and data availability.
# API reference: https://docs.bayou.energy/v2.0/reference/how-to-set-up-webhooks
# Below Bayou automatically refreshes customer records to simulate testing webhooks locally (this is the QUICKstart),
while not customer["has_filled_credentials"] do # Maps to customer_has_filled_credentials, https://docs.bayou.energy/v2.0/reference/customer_has_filled_credentials
sleep(3)
# We refresh the customer data until they have filled credentials
response = http.get("/api/v2/customers/#{customer['id']}", auth_headers)
customer = JSON.parse(response.body)
end
puts "The customer, in this case you, has filled credentials. First, we'll call the /bills endpoint and print the first 12 bills. Fetching bills now!\n"
sleep(3) # Pause for 3 seconds to allow you to see that the above terminal message
while not customer["bills_are_ready"] do # Maps to bills_ready: https://docs.bayou.energy/v2.0/reference/event-informing-that-the-initial-bill-discovery-is-done-for-a-specific-customer
sleep(3)
# We refresh the customer data until their bills are ready
response = http.get("/api/v2/customers/#{customer['id']}", auth_headers)
customer = JSON.parse(response.body)
end
# Get all bills for a specific customer. API reference: https://docs.bayou.energy/v2.0/reference/get_customers-customer-id-bills
response = http.get("/api/v2/customers/#{customer['id']}/bills", auth_headers)
bills = JSON.parse(response.body)
# Now that we've fetched all bills, we're printing 12 for readability
puts "\n"
bills.first(12).each do |bill|
puts bill
end
sleep(10) # Pause for 10 seconds to allow you to quickly review bill data
puts "\nNow we'll call the /intervals endpoint and print the first 10 intervals for each meter. Fetching intervals now!"
sleep(3) # Pause for 3 seconds to allow you to see that the above terminal message
while not customer["intervals_are_ready"] do
sleep(3)
# We refresh the customer data until their intervals are ready
response = http.get("/api/v2/customers/#{customer['id']}", auth_headers)
customer = JSON.parse(response.body)
end
# Get all intervals for a specific customer. API reference: https://docs.bayou.energy/v2.0/reference/get_customers-customer-id-intervals
response = http.get("/api/v2/customers/#{customer['id']}/intervals", auth_headers)
intervals = JSON.parse(response.body)
intervals["meters"].each do |meter|
puts "\nIntervals for meter #{meter['id']}:"
# Now that we've fetched all intervals, we're printing 10 from each meter for readability
meter["intervals"].first(10).each do |interval|
puts interval
end
end
sleep(10) # Pause for 10 seconds to allow you to quickly review interval data
puts <<~EOS
Congratulations!
You’re ready to get customer utility data instantly with Bayou.
As a recommended next step, visit Bayou’s documentation for moving from QuickStart to deployment:
https://docs.bayou.energy/docs/merge-customer-code-with-your-project
Want to chat with the Bayou team? Book time here, https://calendly.com/jamesbayouenergy/30min or text James our CEO at +1 504 722 8987.
EOS
Updated 29 days ago