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

json POST syntax


Question

Posted

Hi,

 

Im trying to control a Danalock through a Danabridge and so far i can get the token and use it to retrieve my locks and its status but when trying to perform lock/unlock i get a 404 error.

I have translated a python implementation but this last part is not working.

 

The encoded json from python looks like this:

payload = json.dumps({"device": serial, "operation": "afi.lock.operate", "arguments": [command]})

The command here is either "lock" or "unlock" but since its inside brackets im not sure how to translate it.

"arguments": ["lock"] and "arguments": "[lock]" doesnt work.

 

Does anyone have an idea how the syntax should be?

 

My POST in lua looks like this:

http:request('https://bridge.danalockservices.com/bridge/v1/execute',{
    options = {
      method = 'POST',
      headers = {
        ['Accept'] = 'application/json',
        ['Content-Type'] = 'application/json',
        ['Authorization'] = 'Bearer ' ..token          
      },
        data = json.encode({
        ["device"] = lockserial,
        ["operation"] = "afi.lock.operate",
        ["arguments"] = '["lock"]'
          })
  },

 

BR

 

Recommended Posts

  • 0
  • Inquirer
  • Posted

    Ok, i finally got it working.

    Apparently it had to do with the polling (python code):

    poll_url = "https://bridge.danalockservices.com/bridge/v1/poll"

     payload = json.dumps({"id": job_id})

     r = requests.post(poll_url, headers={'Authorization': 'Bearer ' + token, 'Accept': 'application/json', 'content-type': 'application/json'}, data=payload)

     

    I had from the beginning 12 iterations of polling and all looked fine (Waiting for "Succeeded") but when i lowered it to 6 and didnt care about the "Succeeded" response, just went ahead and try to lock/unlock it, then it works.

    Im probably doing something wrong and yes, since its asynchronous, i get printouts in the wrong order but at least its working now :)

     

    Many thanks for you help!

     

    BR

    • 0
    Posted (edited)

     

    basically you need to do this

     

    Get token request

      token response callback

        store token

        make

    Please login or register to see this link.

     request IN THE RESPONSE block of code

     

    Please login or register to see this code.

     

        

    Edited by ivx
    • 0
  • Inquirer
  • Posted

    Thanks ivx,

     

    Ill try this when i get home to see that i get things in correct order.

     

    BR

    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...