Start a new topic
Answered

Problems with API v2 from command line

Now that I got my API key, still having problems, I'm getting a response...

{ "errors" : [ { "message" : "Invalid json" } ] }

Batch file is like...

curl.exe -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic [consisting of dev:+api-key base64 encoded]" -H "Cache-Control: no-cache" --data-ascii "@C:\\lametric\test.json" http://[inside IP of my LaMetric]:8080/api/v2/device/notifications

 test.json file is like...

{
    "priority": "warning",
    "model": {
        "cycles": 1,
        "frames": [
        {
            "icon": "i660",
            "text": "Test"
        }
        "sound": {
            "category": "notifications",
            "id": "cat",
            "repeat": 1
        }
    }
}

 



Best Answer

Found it.  I'd forgotten to close the square brackets.

 

{
    "priority": "critical",
    "model": {
        "cycles": 1,
        "frames": [
        {
            "icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAUklEQVQYlWNUVFBgYGBgYBC98uE/AxJ4rSPAyMDAwMCETRJZjAnGgOlAZote+fCfCV0nOmA0+yKAYTwygJuAzQoGBgYGRkUFBQZ0dyDzGQl5EwCTESNpFb6zEwAAAABJRU5ErkJggg==",
            "text": "HELLO!"
        }],
        "sound": {
            "category": "notifications",
            "id": "cat"
        }
    }
}

 This worked & might give a starting point to work from.


I've been working on this as well.  I've previously had trouble JSON formatting.

JSONLint suggests your JSON is invalid.


I've had success with :

{
	"priority": "info",
	"icon_type": "none",
	"model": {
		"cycles": 0,
		"frames": [{
			"icon": "data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAUklEQVQYlWNUVFBgYGBgYBC98uE\/AxJ4rSPAyMDAwMCETRJZjAnGgOlAZote+fCfCV0nOmA0+yKAYTwygJuAzQoGBgYGRkUFBQZ0dyDzGQl5EwCTESNpFb6zEwAAAABJRU5ErkJggg==",
			"text": "Hello"
		}]
	}
}

 But I've been unable to get the sound working.

Answer

Found it.  I'd forgotten to close the square brackets.

 

{
    "priority": "critical",
    "model": {
        "cycles": 1,
        "frames": [
        {
            "icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAUklEQVQYlWNUVFBgYGBgYBC98uE/AxJ4rSPAyMDAwMCETRJZjAnGgOlAZote+fCfCV0nOmA0+yKAYTwygJuAzQoGBgYGRkUFBQZ0dyDzGQl5EwCTESNpFb6zEwAAAABJRU5ErkJggg==",
            "text": "HELLO!"
        }],
        "sound": {
            "category": "notifications",
            "id": "cat"
        }
    }
}

 This worked & might give a starting point to work from.

JSON Formatter suggests your JSON is invalid.

Thanks!


That does work.  Wish the example in the API v2 reference would be as good.

Login or Signup to post a comment