Public
Edited
Nov 4, 2024
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ping = fetch("https://api.sencrop.com/v1/ping").then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
accessData = fetch(`${endPoint}/oauth2/token`, {
body: '{"grant_type": "client_credentials", "scope": "user"}',
headers: {
Authorization: `Basic ${base64.encode(
`${applicationId}:${applicationSecret}`
)}`,
"Content-Type": "application/json"
},
method: "POST"
}).then((response) => {
return response.json();
})
Insert cell
accessToken = accessData.access_token
// You can replace accessData.access_token by your token (as a string)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
userData = fetch(`${endPoint}/me`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
}).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
devices = fetch(
`${endPoint}/users/${userId}/devices?includeHistory=${includeHistoryUser}`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
specificDevice = fetch(
`${endPoint}/users/${userId}/devices/${devices.items[0]}?includeHistory=false`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
organisationDevice = fetch(
`${endPoint}/organisations/${organisationDevices}/devices?limit=${limitOrga}&start=${indexToChoose}`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dailyData = {
fetch(
`${endPoint}/users/${userId}/devices/${deviceId}/data/daily?beforeDate=${new Date(
startDate
).toISOString()}&days=${nbDays}&measures=${
measures.length > 0 ? measures.toString() : "TEMPERATURE"
}&patched=${patched}`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
}

Insert cell
measures.toString()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
hourlyData = fetch(
`${endPoint}/users/${userId}/devices/${deviceIdHourly}/data/hourly?beforeDate=${new Date(
startDateHourly
).toISOString()}&days=${nbDaysHourly}&measures=${
measuresHourly.length > 0 ? measuresHourly.toString() : "TEMPERATURE"
}&patched=${patchedHourly}`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rawData = fetch(
`${endPoint}/users/${userId}/devices/${deviceIdRaw}/data/raw?size=${size}&beforeDate=${new Date(
startDateRaw
).toISOString()}&measures=${
measuresRaw.length > 0 ? measuresRaw.toString() : "TEMPERATURE"
}`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
geoData = fetch(
`${endPoint}/users/${userId}/data/daily?latitude=${userLatitude}&longitude=${userLongitude}&beforeDate=${new Date(
startDateGeo
).toISOString()}&days=${nbDaysGeo}&measures=${
measuresGeo.length > 0 ? measuresGeo.toString() : "TEMPERATURE"
}`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
statisticData = fetch(
`${endPoint}/users/${userId}/devices/${deviceIdStats}/statistics?startDate=${new Date(
startDateStats
).toISOString()}&endDate=${new Date(endDateStats).toISOString()}&measures=${
measuresStats.length > 0 ? measuresStats.toString() : "TEMPERATURE"
}&interval=${intervalStats}`,
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
).then((response) => {
return response.json();
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more