• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Coding a shortcut Webview/Problem with the API

    Scheduled Pinned Locked Moved
    General
    api api help fogapi-psmodule
    3
    11
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sega
      last edited by JJ Fullmer

      Hi,

      I’m currently coding a simple-to-use-Webview for my colleagues, it will just contain some buttons to deploy images on hosts/groups. And at this point I have a problem. I want to call the deploy action but I get only this response:

      { "error": "Invalid tasking type passed" }
      

      Followed the documentation on here (https://docs.fogproject.org/en/latest/Knowledge-Base/integrations/api/?h=api#put) so I set the taskType as “1”. I’m testing it in Postman. Other get examples are working, so the token are right.

      Does anyone know what’s the problem? Thank you in advance.

      Tom ElliottT 2 Replies Last reply Reply Quote 0
      • Tom ElliottT
        Tom Elliott @sega
        last edited by

        @sega What’s the api endpoint you’re reaching to?

        Right now we just see you having some request, but what is the request you’re making exactly?

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        S 1 Reply Last reply Reply Quote 0
        • S
          sega @Tom Elliott
          last edited by sega

          @Tom-Elliott

          The endpoint I’m trying to reach is: http://192.168.0.0/fog/host/128/task
          And as I read in the documentation I have to add taskType: 1 as the body. So basically I just need to know which ID the task “Deploy” has.

          1 Reply Last reply Reply Quote 0
          • Tom ElliottT
            Tom Elliott @sega
            last edited by

            @sega I would also recommend following this information:
            https://news.fogproject.org/simplified-api-documentation/

            While it’s a bit older, it seems the other link you’re using is incomplete at this point.

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            1 Reply Last reply Reply Quote 1
            • S
              sega
              last edited by

              @Tom-Elliott I saw this site also and used the example at the end of the page:

              curl -H 'fog-api-token: abcde' -H 'fog-user-token: fghij' -H 'Content-Type: application/json' -X POST -d '{"taskTypeID":13,"deploySnapins":6}' http://fogserver/fog/host/1/task
              

              I used this one, removed the "deploySnapins and changed the taskTypeID into 1, which should stand for the task of deployment. Still the same error. There isn’t any documentation about the various taskTypeIDs, I think thats my main problem.

              JJ FullmerJ 2 Replies Last reply Reply Quote 0
              • JJ FullmerJ
                JJ Fullmer Testers @sega
                last edited by

                @sega I believe you need more in your json post

                I have a function in the fogApi powershell module to deploy an image.
                The code is in the syntax for powershell not curl, but it should give you an idea.
                https://github.com/darksidemilk/FogApi/blob/master/FogApi/Public/Send-FogImage.ps1

                i.e. a simple deploy image now task of a host’s assigned image would have json like this

                {
                    "taskTypeID": "1",
                    "shutdown":"0",
                    "other2":"0",
                    "other4":"1",
                    "isActive":"1" 
                }
                

                IIRC other2 is debug task and other4 is wake on lan

                Have you tried the FogApi powershell module? It's pretty cool IMHO
                https://github.com/darksidemilk/FogApi
                https://fogapi.readthedocs.io/en/latest/
                https://www.powershellgallery.com/packages/FogApi
                https://forums.fogproject.org/topic/12026/powershell-api-module

                1 Reply Last reply Reply Quote 1
                • JJ FullmerJ
                  JJ Fullmer Testers @sega
                  last edited by

                  @sega said in Coding a shortcut Webview/Problem with the API:

                  There isn’t any documentation about the various taskTypeIDs, I think thats my main problem.

                  It’s on the todo list, it’s a long todo list though.

                  In the interim:

                  You can get the tasktype ids from the urls in the gui
                  i.e. you go to a hosts task page
                  http://fogserver/fog/management/index.php?node=host&sub=edit&id=1#host-tasks

                  And each link to a task type on that page ends with &type=# where that number is that tasks id.

                  To then figure out the required fields for that task you have to look into the various classes. For tasks its a bit trickier to find that it is for objects. I sadly don’t remember how I figured out where those fields were, I think @Tom-Elliott helped me a few years back and I forgot to write down the origin of it all.

                  Have you tried the FogApi powershell module? It's pretty cool IMHO
                  https://github.com/darksidemilk/FogApi
                  https://fogapi.readthedocs.io/en/latest/
                  https://www.powershellgallery.com/packages/FogApi
                  https://forums.fogproject.org/topic/12026/powershell-api-module

                  1 Reply Last reply Reply Quote 0
                  • S
                    sega
                    last edited by

                    Ok, the call in Postman worked now, I just had to change a setting.
                    Now I want to import that call in html/js. But I just get an error as response:

                    GET http://192.168.xxx.xxx/fog/task/active net::ERR_ABORTED 403 (Forbidden)
                    

                    I’m pretty sure I have to change something in the fetch function? But I’m not sure. The HTML file is right now running on a local PHP server.

                    fetch("http://192.168.xxx.xxx/fog/task/active", {
                            method: "GET",
                            mode: "no-cors",
                            headers: {
                              "fog-api-token": "token",
                              "fog-user-token": "token"
                            }
                          })
                    
                    JJ FullmerJ 1 Reply Last reply Reply Quote 0
                    • JJ FullmerJ
                      JJ Fullmer Testers @sega
                      last edited by

                      @sega said in Coding a shortcut Webview/Problem with the API:

                      Ok, the call in Postman worked now, I just had to change a setting.
                      Now I want to import that call in html/js. But I just get an error as response:

                      GET http://192.168.xxx.xxx/fog/task/active net::ERR_ABORTED 403 (Forbidden)
                      

                      I’m pretty sure I have to change something in the fetch function? But I’m not sure. The HTML file is right now running on a local PHP server.

                      fetch("http://192.168.xxx.xxx/fog/task/active", {
                              method: "GET",
                              mode: "no-cors",
                              headers: {
                                "fog-api-token": "token",
                                "fog-user-token": "token"
                              }
                            })
                      

                      Does this fetch function work for other things in your custom page?

                      I’m not a php expert, but I found this post that suggests using a curl extension or using file_get_contents with json_encode and json_decode

                      https://stackoverflow.com/questions/9802788/call-a-rest-api-in-php

                      @Tom-Elliott might know more about using php with the api.

                      Have you tried the FogApi powershell module? It's pretty cool IMHO
                      https://github.com/darksidemilk/FogApi
                      https://fogapi.readthedocs.io/en/latest/
                      https://www.powershellgallery.com/packages/FogApi
                      https://forums.fogproject.org/topic/12026/powershell-api-module

                      1 Reply Last reply Reply Quote 0
                      • S
                        sega
                        last edited by

                        This should work (worked at the start), but that’s a good point. I will test it with another API just to get sure.
                        The HTML file just runs on a PHP server but has no PHP in it, just HTML and JavaScript. But won’t be a big problem, to rewrite it in PHP, if that’s necessary.

                        1 Reply Last reply Reply Quote 0
                        • S
                          sega
                          last edited by

                          I changed the code to PHP and now it works, so I think it was something security related from the browser.

                          1 Reply Last reply Reply Quote 1
                          • 1 / 1
                          • First post
                            Last post

                          197

                          Online

                          12.0k

                          Users

                          17.3k

                          Topics

                          155.2k

                          Posts
                          Copyright © 2012-2024 FOG Project