[HELP] I have an error with ending message: No signature of method using httpPut()

So, I can't figure this out... I'm trying to write a simple notification message drive to get messages to my matrix room. Was hoping someone might be able to find my mistake. I'm pretty sure httpPut() is being using correctly. I did try using hubitat.device.HubAction & httpPost() but got the same sending error about no signature.

I found the proper curl put request method:

curl 'https://SERVER/_matrix/client/r0/rooms/ROOMID/send/m.room.message/RANDOMIZEDMESSAGEID?access_token=MYTOKEN' -X PUT --data '{"msgtype":"m.text", "body":"MESSAGE","format":"org.matrix.custom.html","formatted_body":"MESSAGE"}'

I have the code below, but keep getting errors. I have resolved every error except this one:

Error sending message: No signature of method: user_driver_hakarune_Matrix_Notification_Device_1279.httpPut() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, java.util.LinkedHashMap, java.lang.String, user_driver_hakarune_Matrix_Notification_Device_1279$_sendNotification_closure2) values: [https://matrix.org/_matrix/client/r0/rooms/MYROOMID/send/m.room.message/88f23643-4259-4ab2-bb0d-495a167029b6?access_token=MYTOKEN, ...]

I can't seem to get rid of it and I have searched google and the forums, but can't find the cause. Does anyone see what is causing the issue? I feel like it must be something stupid that I didn't see or realize, but I don't know and am tired lol. Any help is appreciated. Thank you.

I am on Hubitat platform version: 2.3.8.119

CODE:

import groovy.json.JsonOutput
import java.net.URLEncoder

metadata {
  definition(name: "Matrix Notification Device", namespace: "hakarune", author: "hakarune", importUrl: "") {
    capability "Notification"
  }
  preferences {
    input name: "apiKey", type: "text", title: "Matrix API Key", required: true, defaultValue: ""
    input name: "roomId", type: "text", title: "Room ID", required: true, defaultValue: ""
    input name: "matrixServer", type: "text", title: "Matrix Server URL", required: true, defaultValue: "https://matrix.org"
  }
}

def deviceNotification(text) {
  try {
    def apiKey = settings.apiKey
    def roomId = settings.roomId
    def matrixServer = settings.matrixServer

    def sendMessage = [
      msgtype: 'm.text',
      body: text
    ]

    // Generate a random message ID
    def messageId = UUID.randomUUID().toString()

    def response = sendNotification(sendMessage, apiKey, roomId, messageId, matrixServer)
    if (response.status == 200) {
      log.debug "Message sent successfully: ${text}"
      updateStatus("Message sent successfully", "Connected", text)
    } else {
      log.error "Failed to send message. Status code: ${response.status}, Response: ${response.data}"
      updateStatus("Failed to send message", "Disconnected", text)
    }
  } catch (Exception e) {
    log.error "Error sending message: ${e.message}"
    updateStatus("Error sending message", "Disconnected", "")
  }
}

private sendNotification(message, apiKey, roomId, messageId, matrixServer) {
    def uri = "${matrixServer}/_matrix/client/r0/rooms/${roomId}/send/m.room.message/${messageId}?access_token=${apiKey}"
    def headers = [
        'Content-Type': 'application/json'
    ]
    def body = JsonOutput.toJson(message)

    // Use httpPut() instead of HubAction
    httpPut(uri, headers, body) { response ->
        if (response.status == 200) {
            log.debug "Message sent successfully: ${text}"
        } else {
            log.error "Failed to send message. Status code: ${response.status}, Response: ${response.data}"
        }
    }
}

private updateStatus(logEvent, connectionStatus, lastMessage) {
  sendEvent(name: "lastLogEvent", value: logEvent, displayed: true)
  sendEvent(name: "connectionStatus", value: connectionStatus, displayed: true)
  sendEvent(name: "lastMessage", value: lastMessage, displayed: true)
}

Use a hashmap as the single parameter for httpPut, like this:

httpPut([
uri: BASE_URI,
path: PATH_LOGIN,
headers: getApiHeaders(),
query: [
"userName": settings.username,
"password": md5(settings.password)
],
requestContentType: "application/x-www-form-urlencoded"
]) { resp -> code here }

1 Like

to

2 Likes

Thank you, Using that I was able to get everything woking! Whoot!

2 Likes