I have been fighting this for over 6 hours.
I have enabled oAuth in my app.
In my app code; I have a mapping:
mappings {
path("/update-settings") {
action: [ GET: "updateSettings" ]
}
}
I then have a handler:
def updateSettings() {
return 'THIS IS THE RESPONSE';
}
Lastly, in my page html:
try {
createAccessToken()
log.trace 'Created Access Token: ' + state.accessToken
log.trace 'starting get...'
try {
httpGet([ uri: "http://127.0.0.1:8080/apps/api/432/update-settings?access_token=${state.accessToken}" ]) { resp ->
log.trace resp
}
}
catch (Exception e) { log.warn "Error Updating App Settings: ${e.message}" }
}
catch (Exception e) { log.warn "Error Creating Access Token: ${e.message}" }
Here are the appropriate logs:
app:4322025-01-27 08:12:30.410 AMwarnError Updating App Settings: status code: 401, reason phrase: Unauthorized
app:4322025-01-27 08:12:30.362 AMtrace starting get...
app:4322025-01-27 08:12:30.359 AMtrace Created Access Token: ********-****-****-****-************
Why can I not make the http get call from my app without receiving a 401 unauthorized response?
I am expecting to receive THIS IS THE RESPONSE
.
Do you get the same result using the hub’s LAN ip?
That one is slightly different (using hubs LAN ip):
app:4322025-01-27 08:37:46.507 AMwarnError Updating App Settings: Connect to 192.168.1.235:80 [/192.168.1.235] failed: Connection refused (Connection refused)
app:4322025-01-27 08:37:46.481 AMtrace starting get...
app:4322025-01-27 08:37:46.477 AMtrace Created Access Token: ********-****-****-****-************
tray_e
January 27, 2025, 1:40pm
4
Should that have 3 slashes or 2?
Most definitely 2.. lol.
Edited above; but same result.
Thanks for checking!
1 Like
Don't think it likes the loopback address, try:
httpGet([ uri: "${location.hub.localIP}:8080/apps/api/432/update-settings?access_token=${state.accessToken}" ] ) { resp ->
Ignore this post... testing.
I editted it after my initial posting
1 Like
Lol.. that's why.
I began using cloud api.. then thought I wanted local api.. started working on that.. came back here and saw the update and thought.. I'm definitely losing my mind!
Okay, getting closer, I think:
try {
httpGet([ uri: "${location.hub.localIP}:8080/update-settings?access_token=${state.accessToken}" ]) { resp ->
log.trace resp
}
}
catch (Exception e) { log.warn "Error Updating App Settings: ${e.message}" }
Now this in logs:
Error Updating App Settings: Illegal character in scheme name at index 0: 192.168.1.235:8080/update-settings?access_token=********-****-****-****-************
1 Like
add "http://" at the front
Error Updating App Settings: status code: 404, reason phrase: Not Found
Oops.. I think I mauled the url. Checking.
So, getting to the app now, and accepting the access token. Normally when I get this I've fat fingered the endpoint.
httpGet([ uri: "http://${location.hub.localIP}:8080/apps/api/432/update-settings?access_token=${state.accessToken}" ]) { resp ->
Error Updating App Settings: status code: 401, reason phrase: Unauthorized
Back to this again...
Is that url structure correct?
Looks correct assuming the appID is correct.
why the 8080 on the LAN ip ?
Yeah, checked that 100 times:
http://192.168.1.235/installedapp/configure/432/mainPage
That's the url of the page of my app.
I have been trying all sorts of combinations...
1 Like
Needed to allow the hub to call itself.
Removing the :8080 generates this message:
Error Updating App Settings: Connect to 192.168.1.235:80 [/192.168.1.235] failed: Connection refused (Connection refused)
With the :8080
status code: 401, reason phrase: Unauthorized
Without the :8080
Connect to 192.168.1.235:80 [/192.168.1.235] failed: Connection refused (Connection refused)
If I change the appID in the get call to something that doesn't exist:
Received local request for App 289 that does not exist, path: /update-settings/ from unknown