Where do I get the parameters for measurements api?

I’m trying to use the web api to generate some reports.

https://kizniche.github.io/api/measurements/past/{unique_id}/{unit}/{channel}/{past_seconds}

for {unique_id} i’ve tried the UUID of the measurement, but, I don’t know what value to use for {unit}

I keep getting response {“custom”:“Unit ID not found”}

curl -k -v “https://[REDACTED]/api/measurements/past/720c1d35-0771-4033-9adc-1841c5cdf5b9/895b0d6e-d589-47db-a3be-d50404bade90/0/3600” -H “authorization: Basic [REDACTED]” -H “accept: application/vnd.mycodo.v1+json”

Best Regards

1 Like

All units in the system can be found under Configure → Measurements → All Units, and for the API, use Unit ID.

curl -k -v “https://[REDACTED]/api/measurements/past/720c1d35-0771-4033-9adc-1841c5cdf5b9/F/0/3600” -H "authorization: Basic [REDACTED] -H “accept: application/vnd.mycodo.v1+json”

9{“message”:“Internal Server Error”}

What is in the Web log?

Working fine over here. It’s likely you’re passing an invalid parameter in the URL. The Web log should indicate the issue.

user@dev:~ $ curl -k -v "https://192.168.0.26/api/measurements/past/883e2b0d-0610-4c20-b96a-484e933da685/C/0/360" -H "authorization: Basic MYAPIKEY" -H "accept: application/vnd.mycodo.v1+json"
*   Trying 192.168.0.26:443...
* Connected to 192.168.0.26 (192.168.0.26) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: O=mycodo; OU=mycodo; CN=mycodo
*  start date: Jul 15 02:18:32 2022 GMT
*  expire date: Jul 15 02:18:32 2032 GMT
*  issuer: O=mycodo; OU=mycodo; CN=mycodo
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
> GET /api/measurements/past/883e2b0d-0610-4c20-b96a-484e933da685/C/0/360 HTTP/1.1
> Host: 192.168.0.26
> User-Agent: curl/7.74.0
> authorization: Basic 5VE2Mnm501mf3zB1qdwBDChFUXxUhzd6rLkIcbaPvg6lfG5Nlyh0oebgcrNFBXa1oqyMVzpcWrW3o4A5KzuKo00Yr8SwkUbr49p4YTgNefE6ocx3LM2xk1HrTPLLEloxJozdbb1ImLTXD1zDFaOWh9zSJGjWluLRAyXZPstTc50=
> accept: application/vnd.mycodo.v1+json
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.18.0
< Date: Thu, 10 Nov 2022 23:26:15 GMT
< Content-Type: application/vnd.mycodo.v1+json
< Content-Length: 1305
< Connection: keep-alive
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Security-Policy: default-src * 'unsafe-inline' 'unsafe-eval'
< Strict-Transport-Security: max-age=31556926; includeSubDomains
< Referrer-Policy: strict-origin-when-cross-origin
< X-RateLimit-Limit: 200
< X-RateLimit-Remaining: 199
< X-RateLimit-Reset: 1668122836
< Retry-After: 60
< Vary: Accept-Encoding
< Set-Cookie: session=78d104f5-b9bf-4e45-8cb4-12abba8aad32; Expires=Sun, 11 Dec 2022 23:26:15 GMT; Secure; HttpOnly; Path=/; SameSite=Lax
<
{"measurements":[{"time":1668122422.459048,"value":23.335039062499995},{"time":1668122437.485661,"value":23.324313964843746},{"time":1668122452.494764,"value":23.324313964843746},{"time":1668122467.515885,"value":23.313588867187498},{"time":1668122482.485509,"value":23.324313964843746},{"time":1668122497.553354,"value":23.335039062499995},{"time":1668122512.52341,"value":23.345764160156243},{"time":1668122527.4897,"value":23.345764160156243},{"time":1668122542.439131,"value":23.335039062499995},{"time":1668122557.550108,"value":23.335039062499995},{"time":1668122572.499873,"value":23.324313964843746},{"time":1668122587.495814,"value":23.335039062499995},{"time":1668122602.465043,"value":23.345764160156243},{"time":1668122617.571325,"value":23.35648925781249},{"time":1668122632.492514,"value":23.345764160156243},{"time":1668122647.445638,"value":23.367214355468754},{"time":1668122662.507987,"value":23.377939453125002},{"time":1668122677.4636,"value":23.367214355468754},{"time":1668122692.571492,"value":23.345764160156243},{"time":1668122707.546087,"value":23.367214355468754},{"time":1668122722.509666,"value":23.35648925781249},{"time":1668122737.503587,"value":23.377939453125002},{"time":1668122752.505009,"value":23.38866455078125},{"time":1668122767.510216,"value":23.3993896484375}]}
* Connection #0 to host 192.168.0.26 left intact

Are you running the latest code?

Are you sure the URL is properly formed?

Is F really the unit (F is not a default unit for temperature)?

Version 8.14.2

The URL and headers are good as I was able to get something to return with this…

$ curl -k https://[MYIP]/api/inputs/3313ad36-33c9-4c0c-a1b8-04548c28ae34 -H "authorization: Basic [MYAPI]" -H "accept: application/vnd.mycodo.v1+json"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1030  100  1030    0     0   2712      0 --:--:-- --:--:-- --:--:--  2717{"device measurements":[],"input channels":[],"input settings":{"adc_gain":null,"adc_resolution":null,"adc_sample_speed":null,"baud_rate":null,"bt_adapter":null,"calibrate_sensor_measure":null,"cmd_command":null,"custom_options":null,"datetime":null,"deadline":null,"device":null,"ftdi_location":null,"gpio_location":null,"i2c_bus":null,"i2c_location":null,"id":null,"interface":null,"is_activated":null,"is_preset":null,"location":null,"log_level_debug":null,"name":null,"period":null,"pin_clock":null,"pin_cs":null,"pin_miso":null,"pin_mosi":null,"port":null,"position_y":null,"power_output_id":null,"pre_output_duration":null,"pre_output_during_measure":null,"pre_output_id":null,"preset_name":null,"ref_ohm":null,"resolution":null,"resolution_2":null,"rpm_pulses_per_rev":null,"sample_time":null,"sensitivity":null,"sht_voltage":null,"start_offset":null,"switch_bouncetime":null,"switch_edge":null,"switch_reset_period":null,"thermocouple_type":null,"times_check":null,"uart_location":null,"unique_id":null,"weighting":null}}

All temperature measurements are by default the SI unit Celsius. Only if you’ve set a conversion to F will it be Fahrenheit. All measurements are viewable in the Input configuration, which will list all channels, measurement IDs, and units.

So it looks like you’re not using the device ID in the URL, you’re using the measurement ID. It seems the API docs mistakenly state “Measurement ID” instead of “Device ID”.

looks like I’m getting closer…where do I get device id?

$ curl -k https://[MYIP]/api/measurements/last/cf5cd8b3-e68b-4c1d-bd58-16040416ae7e/F/0/3600 -H “authorization: Basic [MYAPI]” -H “accept: application/vnd.mycodo.v1+json”
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 27 100 27 0 0 5 0 0:00:05 0:00:04 0:00:01 8{“time”:null,“value”:null}

On the title button on the Input page.

BINGO!

Looks like we got it…thanks for all the help :slight_smile:
Even works for getting function results :wink:

MQTT data:
$ curl -k https://[MYIP]/api/measurements/last/2003f7d0-4e33-4ff0-94c2-dde42c8011d0/F/0/360 -H “authorization: Basic [MYAPI]” -H “accept: application/vnd.mycodo.v1+json”
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 57 100 57 0 0 83 0 --:–:-- --:–:-- --:–:-- 84{“time”:“2022-11-11T04:50:44.669069+00:00”,“value”:57.2}

Calculated value:
$ curl -k https://[MYIP]/api/measurements/last/529f02a5-0fa1-4a3c-b7b9-73fa04f16985/F/0/360 -H “authorization: Basic [MYAPI]” -H “accept: application/vnd.mycodo.v1+json”
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 62 100 62 0 0 120 0 --:–:-- --:–:-- --:–:-- 120{“time”:“2022-11-11T04:54:41.488291+00:00”,“value”:60.503068}

Calculated values for last 6 minutes:
$ curl -k https://[MYIP]/api/measurements/past/529f02a5-0fa1-4a3c-b7b9-73fa04f16985/F/0/360 -H “authorization: Basic [MYAPI]” -H “accept: application/vnd.mycodo.v1+json”
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 391 100 391 0 0 859 0 --:–:-- --:–:-- --:–:-- 863{“measurements”:[{“time”:“2022-11-11T04:49:41.578469+00:00”,“value”:60.503068},{“time”:“2022-11-11T04:50:41.513909+00:00”,“value”:60.503068},{“time”:“2022-11-11T04:51:41.776444+00:00”,“value”:60.503068},{“time”:“2022-11-11T04:52:41.479510+00:00”,“value”:60.503068},{“time”:“2022-11-11T04:53:41.727733+00:00”,“value”:60.503068},{“time”:“2022-11-11T04:54:41.488291+00:00”,“value”:60.503068}]}

1 Like