Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

HTTP request HC3


Rikbast

Question

Hi,

 

I am trying this HTTP request in HC3 which always returns this statement:

 

{"error":{"message":"Cast to number failed for value \"NaN\" at path \"__QueryCasting__\" for model \"Ozone1\"","name":"CastError","stringValue":"\"NaN\"","kind":"number","value":"NaN","path":"__QueryCasting__"}}

 

I also get an 500 error code with this call

 

This request works flawlessly in HC2, so I am bit lost here. I adapted the HC2 code (hub.debug  command only).

Might this be a bug in HC3? I just don't know what's wrong here.

 

This script has some more code, but that's just handling and data for input of the HTTP request (like token variable). I only copied the HTTP request here.

 

url: 

Please login or register to see this link.

 

local http = net.HTTPClient({timeout=20000})
function httpGetJson(url, body, func)
  http:request(url, { 
  
      options = { 
        method = 'GET',
        
        headers = {
         
          ['x-access-token'] = token
        },
        
      },
      success = function(response)
          print(response.data)
          hub.debug("Scene6 API response",response.data)
          hub.debug("Scene6",response.status)
        
        local isOk, dataTable = pcall(json.decode,response.data)
        if (isOk == false) then
          func(false, "getResponseData ERROR: Invalid JSON: " .. dataTable ..
            "\nWeb Server Data: ".. tostring(response.data))
        else
          if type(dataTable)=="table" then
            func(true, dataTable)
          else
            func(false, "Data returned by json.decode is not a table")
          end
        end
      end,
      error = function(err)
        func(false, "HTTPClient error: ".. err)
      end
    })   
end

 

Any help is appreciated.

thx,

Rik

 

Edited by Rikbast
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi Rik, I just did a test after your email with the same question, this code works, but I get an API rate limit error now:

 

Please login or register to see this code.

 

Response:

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Apparently this only works in QA's and not scenes, I tested this on advice of @Sankotronic

    Why that is, I don't know. That's why I think it might be a bug? Will send Fibaro support an e-mail about it.

     

    Local API calls (with internal IP address) work fine with the above code in scenes on HC3.

     

     

    Thanks for your input!

    Edited by Rikbast
    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...