Hi all, I want to get value from below API which tells me est time for bus to arrive. I’ve learnt how to get value with get method, but now I am stuck with Post, and having trouble find a right solution.
Using that URL I get an actual JSON response in my web browser, but in HA I get the following message in the log.
2022-12-02 19:42:42.225 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: no Authorization header found
Maybe you can sign up for their API and get an authorisation token or something like that. However, a quick test revealed that the server looks for a User-Agent header, so this appears to work:
sensor:
- platform: rest
resource: https://tdx.transportdata.tw/api/basic/v2/Bus/EstimatedTimeOfArrival/City/NewTaipei/946%E5%89%AF?%24top=30&%24format=JSON
name: bus
value_template: "{{ value_json[0].EstimateTime }}"
headers:
User-Agent: Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1
The following configuration also gives me a response:
sensor:
- platform: rest
resource: 'https://gist.transportdata.tw/gist_web/BusInfo/BusLiveSearch?city=NewTaipei&op=%E5%85%A8%E9%83%A8%E6%A5%AD%E8%80%85&type=route&name=F237&direction=1&isUID=false'
method: POST
name: bus
value_template: "{{ value_json['detail'][0]['EstimateTime'] }}"
headers:
User-Agent: Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1
authorization: 'TOKEN'