Trying to establish a new binding towards a bridge requiring Oauth access token. The developers of the bridge have opened their API, and customers are able to retrieve the token by logging in to the customer page, thus the plan is to use the access token as manual input as part of bridge creation.
So, have been trying the org.eclipse.smarthome.io.net.http.HttpUtil route, using Properties httpHeader for input headers, but struggle to access the bridge.
It must be something using “Authorization” and "Bearer " + MY_PERSONAL_TOKEN
BTW is this OAuth2? Because then it’s better to use the OAuth2 support from openHAB core.
The token is retrieved from a config class within the binding (String value), thus my attempt to set up the method: httpHeader.setProperty("Authoriation: Bearer", getToken as String value).
Have also tried different approaches, defining token manually within method, both with and without quotes, but it always ends up with the same error.
Made some changes, and by using StringBuilder("Bearer ") and .append(MY_TOKEN) I managed to get desired response from the bridge using httpHeader.put as suggested.
Have been looking into your Pixometer binding to get additional tips, including using JsonObject / JsonParser thus trying to extract certain elements from the response. My current issues are:
My server use GraphQL, and my first query (implementing token bearer from discussion above) gives me the HomeID to be included for further queries. So, using HttpUtil.executeURL gives me the following String response from the bridge:
{"data":{"viewer":{"homes":[{"id":"HOME_ID"}]}}}
When using JsonObject jsonResponse = new JsonParser.parse(String_response) and further responseJson.get("id").toString() I do not get anything extracted. Currently have to use String.substring() as a workaround to extract HOME_ID.
I am also implementing the HomeID query / method call within bridge initialize. Further use if/else within query/method to check if query response contains “id”, and set ThingStatus.ONLINE if true and ThingStatusOFFLINE if false. I know the “id” part is in place, but regardless, the OH demo gives me a java.lang.NullPointerException:
ERROR o.e.s.c.i.c.AbstractInvocationHandler:100 - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.tibber.internal.handler.TibberHandler@xxxxxxx': null