Ubidots Community

[SOLVED] Ubidots try it now! page

Doe this page work properly? ubidots try it now!
I am trying to verify my HTTP Post structure and JSON packet structure that I am using in an iOS app.
I get “Access is denied error” when I try to update a variable. I believe I have tried every combination of token and App ID and variable ID but always the same error.

FWIW, we are uploading data from an android device using the Ubidots android sdk and that works fine.

Hi, @jbeard.

Thanks for the report, the documentation is now working good.

Can you tell me a bit more about what are you sending in the request. For what I read, the error you are getting seem to be because there may be an error setting the token header in the iOS app.


Yes, thank you juanda95.

First I was trying to form the request direct from swift. Posted below is what I believe to be the vital parts of that code…

But I switched to Alamofire which wraps those commands and that is working fine.

What appears to be happening to the native swift output is it gets auto formatted with an extraneous “/” in the POST line right before the “HTTP/1.1”. Looks something like: POST /api/v1.6/devices/57b4c96b7625422adf5379bf/xPosition/values/?token=wn****MC / HTTP/1.1

let json = [ "value":97 ] 
let jsonData = try NSJSONSerialization.dataWithJSONObject(json, options: [])
let token = "wn*****************************MC"
let xLabel = "xPosition"
let dataSourceLabel = "iPhone"
let dataSourceId = "57b4c96b7625422adf5379bf"
let url = NSURL(string: "http://things.ubidots.com")!
let request = NSMutableURLRequest(URL: url)

request.HTTPMethod = "POST /api/v1.6/devices/\(dataSourceLabel)/\(xLabel)/values/?token=\(token)"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.HTTPBody = jsonData
let task = NSURLSession.sharedSession().dataTaskWithRequest(request){ data, response, error in
        if error != nil{
                print("Error -> \(error)")
            do {
                let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
                print("Response String: \(response)")   
            } catch {
                print("Error -> \(error)")

I’m not a Swift developer, so my answer may be wrong. But as I understand this line should not have this whole string:

request.HTTPMethod = "POST /api/v1.6/devices/\(dataSourceLabel)/\(xLabel)/values/?token=\(token)"

It should be like this:

request.HTTPMethod = "POST"

And the URL should have the path you added in the method:

let url = NSURL(string: "http://things.ubidots.com /api/v1.6/devices/\(dataSourceLabel)/\(xLabel)/values/?token=\(token)")!


1 Like

Perfect! I apparently couldn’t see the forest for the trees. That solved my issue.

Thanks juanda95!