Hello I want to make a Request to our cloud. For this I first want to get the Token and then open View Nodes. But no matter what I try. I always get the Exception: groovyx.net.http.HttpResponseException: Access Denied. And I dont know why this happens because I do it the same way like in other tutorials. Can someone help?
Code:
/**
- ClimatixIc (Connect)
- Copyright 2017 Dany Van der Meij
- Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
- in compliance with the License. You may obtain a copy of the License at:
-
http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
- on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
- for the specific language governing permissions and limitations under the License.
*/
include ‘localization’
include ‘asynchttp_v1’
definition(
name: “ClimatixIc (Connect)”,
namespace: “Dany3337”,
author: “Dany Van der Meij”,
description: "This is the Service Manager for ClimatixIc ",
category: “”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)
preferences {
}
mappings {
path("/oauth/initialize") {action: [GET: “oauthInitUrl”]}
path("/oauth/callback") {action: [GET: “callback”]}
}
def installed() {
log.debug “Installed with settings: ${settings}”
initialize()
}
def updated() {
log.debug “Updated with settings: ${settings}”
unsubscribe()
initialize()
}
def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
getClimatixToken()
getViewNodes()
}
def getClimatixToken(){
log.debug “getToken()”
def TokenCallParams = [
uri: "https://api.climatixic.com/Staging",
path: "/Token",
header: ["Ocp-Apim-Subscription-Key": "2733467e26b541d7969f76f2e6dac966"],
body: [grant_type: 'password', username: "dany.van_der_meij@siemens.com", password: "xnxx"]
]
try{
httpPost(TokenCallParams){ resp ->
if(resp.status == 200){
log.debug resp.data
}else{
log.debug "http status: ${resp.status}"
}
}
log.debug "Erfolgreich GetToken"
}catch(e){
log.debug "Fehler in getToken"
log.debug e
}
// Try Catch
}
def getViewNodes(){
log.debug “getViewNodes()”
def TokenCallParams = [
uri: "https://api.climatixic.com/Staging",
path: "/ViewNodes",
header: ["Ocp-Apim-Subscription-Key": "2733467e26b541d7969f76f2e6dac966", "Authorization": "Bearer 0Xtf87cVmb9KdNi1PjPHXw7UNTFyRfEme4nUna7UN8ITEBA5F0Q5GZLW-kM9jEDva2n9FrjLGewX9Qk_tZ8WFsJ80g4ivQ5NsBQ6gJ9YOkXDFrMrZVg7hAHfTFMiaOFK5GCbpF50NSQmiTnTKVzN08pAjFkjhzdNGOmxK3lDtTVxMX1E0VL8aB7EgKiizS2tcv6L4N2jJOYyijJaybQ9XLGLxvargeNyD3s7liJ4V5rIW7HXwX8CmBlRlDYBdt3s5nkcyEvIo5nMSWAmSeMfRIaVFyZlL4vya3sp3MNTTtE3Hubrr1t3Von0K1MjXdDmgeTxY4MgsPBWMC6wSEAHIf8CqkGtTAbrtfCnifTW3iKuxF8BK5oNHjtFCqfD3RiWoNALLbuTimdXqSyYgPpq13xFS_eND-qtJaGUeo25DVs4LTrA"]
]
try{
httpGet(TokenCallParams){ resp ->
if(resp.status == 200){
log.debug resp.data
}else{
log.debug "http status: ${resp.status}"
}
}
log.debug "Erfolgreich GetViewNodes"
}catch(e){
log.debug "Fehler in GetViewNodes"
log.debug e
}
// Try Catch
}
// TODO: implement event handlers