Need API Help!


(Craig) #1

I’m a rookie when it comes to writing API commands. My goal is to improve an app that uses a forscam’s motion detector. In that effort I have to figure out just how the APIs work. I’m hoping to get help here on this super simple program and get it up and running.

definition(
    name: "Test API.",
    namespace: "Home",
    author: "Craig via SmartThings",
    description: "can't get APIs to work...",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/photo-burst-when.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/photo-burst-when@2x.png"
)

preferences {
	section("Take a burst of pictures") {
		input "camera", "capability.imageCapture"
		input "burst", "number", title: "How many? (default 5)", defaultValue:5, required: true
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	subscribeToEvents()
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
}

mappings {

	path("/camera") {
		action: [
			GET: "getCamera"
		]
	}
}
   


def getCamera() {
    log.info "it worked"
}

I went through the basic steps on this page: ST API Documentation. I ended up with this URL: https://graph.api.smartthings.com/api/smartapps/installations/APP_ID/camera/ON?OATH_KEY

First Problem: I’m getting this error:

{“error”:true,“type”:“AccessDenied”,“message”:“You are not authorized to perform the requested operation.”}


(Eric R) #2

I think you need …ON?**access_token=**OATH_KEY


(Craig) #3

@baldeagle072 - Thank you. Now I’m getting this error:

{“error”:true,“type”:“AccessDenied”,“message”:“This request is not authorized by the specified access token”}

I’ve gone through the steps to get a new OATH key several times all with the same error.


(Craig) #4

Nice!! I figured it out. Apparently the ID in the “edit” URL is not the APP ID but the id in the logs is!


(Craig) #5

Ok new problem. FOSCAM URL can’t be over 121 characters (I know random!). STs URL is very long because of all it’s Key’s. I’ve stripped everything down I could and I’m still at 123 characters. Anyone have any ideas?

54.243.63.67/api/smartapps/installations/xxxxxxxx-xxxx-xxxx-xxx-f17ae1786263/c/?access_token=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx


(Eric R) #6

You could use an URL shortener. Not sure how secure that would be