I’m trying to use the REST API in HA (latest version) to call the following API and grab by vehicle data.
However I’m struggling to get the API lookup working using the necessary token.
I have a token in secrets.yaml as: api_dvla: Bearer uniqueapikey
I’ve also specified the necessary config in configuration.yaml (split to a separate file). i’ve tested it with either the Authorization and x-api-key headers, neither work.
My point was to test using the example command line that they offered to see if it works for you, and gives you a template for how to construct your sensor. Just because the HA docs suggest a certain header configuration doesn’t mean that it’s suitable for a given service. You’re also using url:, where the documentation says to use resource:. And you’ve used content_type instead of Content-Type.
And I would expect it to create a sensor entity called sensor.dvla_lookup with the response. There should be no need to create any “sub-sensors” to see the data - it would be in the state of that sensor.
That’s originally where I started setting this up actually and must have got it wrong because it didn’t work either.
However I’ve done it again and it’s now working properly, thank you for the assistance.
For anyone else who has the issue, here is my setup:
One last question, I’m trying to convert the date that returns, in format 2022-12-01, to dd/mm/yyyy.
Any chance of assistance in updating the value template to change the date format?
I’ve got it to work in Dev > Templates but if you copy from there into the value template it doesn’t work.
From Dev Tools I’ve used the following, which returns 01/12/2022: {{ strptime(state_attr('sensor.dvla_lookup', 'taxDueDate'), '%Y-%m-%d').strftime('%d/%m/%Y') }}
However in File Editor it states that , was not expected.
Ultimately I’d also like to add this to a calendar, not sure if that’s possible
I don’t see anything wrong with that expression, so I don’t know why File Editor would object to it. Calendars are created by integrations (like Google Calendar) and you would use a service offered by that integration to add an event to it, such as this.