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

Update Global variable with HTTP PUT request


Neo Andersson

Question

Hello guys, can anyone help me, how to construct a correct http put request to update a global variable in HC3 from a JavaScript script?

 

I have tried this, but this doesn't work

 

Please login or register to see this code.

 

I have tried several different headers but none of them even ended up sending the request. I got always error 400. With this setting it seems that the request is sent, but actually the global variable doesn't update.

Any help would be appreciated. Thanks ahead

Edited by Neo Andersson
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hello @Neo Andersson,

 

I would recommend to catch what you sending via Wireshark in HC3 GUI or Swagger while changing the variable. Then I would try to catch what you sending via Javascript and then compare headers.

 

What I saw back with HC2, and I see you got HC3, was need for Content-Lenght in headers. API commands seems to move from HC2 to HC3 platform, so maybe it is still needed. 

 

It is part of VD I posted several years back on marketplace: 

Please login or register to see this link.

Also, I think it is also part of VD generated my Reboot VD Generator: 

Please login or register to see this link.

 

 

Download VD -> Open it in TXT editor -> Pass it to JSON validator (example: 

Please login or register to see this link.

) -> Check the button how it is formated. 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • 11 minutes ago, jakub.jezek said:

    Hello @Neo Andersson,

     

    I would recommend to catch what you sending via Wireshark in HC3 GUI or Swagger while changing the variable. Then I would try to catch what you sending via Javascript and then compare headers.

     

    What I saw back with HC2, and I see you got HC3, was need for Content-Lenght in headers. API commands seems to move from HC2 to HC3 platform, so maybe it is still needed. 

     

    It is part of VD I posted several years back on marketplace: 

    Please login or register to see this link.

    Also, I think it is also part of VD generated my Reboot VD Generator: 

    Please login or register to see this link.

     

     

    Download VD -> Open it in TXT editor -> Pass it to JSON validator (example: 

    Please login or register to see this link.

    ) -> Check the button how it is formated. 

    Thanks Jakub

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 16 minutes ago, Neo Andersson said:

    Thanks Jakub

    This is what a see from Swagger

     

    Please login or register to see this image.

    /monthly_2023_09/image.png.9ace0d4e187254acf65b10004607423f.png" />

     

     

      

    Please login or register to see this code.

     

    Please login or register to see this code.

            

    So i tried with this, but still doesn't work.

    I also tried with contentLenght in the header..nothing happens
       

    Please login or register to see this code.

     

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Okay, i have found the solution.

    For those who would need it.

    Actually we don't need the content length, nor the aut: credentials part.

     

    This is what works for me. The only thing i am curious about, that Authorization part. Where should we get that string, if we don't have swagger. Why can't we authenticate like usually with auth: credentials way. I don't know.

    So this is working:

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0

    The authentication string is btoa(username + ":" + password)

    Edited by jgab
    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • On 9/28/2023 at 8:35 PM, SmartHomeEddy said:


    Maybe not show this username/password in your post

    Yes, you are correct. Thanks. I have changed it anyway.

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