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

API - Create Host "error": "Required database field is empty"

Scheduled Pinned Locked Moved
FOG Problems
2
4
481
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.
  • M
    maddyred
    last edited by Sebastian Roth Oct 30, 2021, 4:18 AM Oct 30, 2021, 8:53 AM

    Hi, I am trying to create a new host from api in pythonwith post to data to create a host it gives me this error: “error”: “Required database field is empty”

    My python code Api looks like this:

    import requests
    import json
    
    session = requests.Session()
    url = 'http://x.x.x.x.'
    userToken = 'ZDJkMDU4ODEyNDA2YTVlZDZhYjkxOGY3OGM2NDZiNjhiZmRkYjJlMTQ4Mzc1Y2FkMjQ2M2ViNGRkMDNjN2QxMjkwOThhM2Q4NTQ1ZmI3M2JhNmY5MGNiY2ZjYjAxMTVhNzdiZmMwZWE0ZjgzZjI0NzM5N2NkOTEzZjJlNzBjOTk='
    apiToken = 'ZTRkM2MxNWZlMDFmNWY3ZTJlNDBmM2MxN2Q0ZjFhOTI0ODc0NzExOWJlYmI0NmJiYTk5MzM1NDUxMmU1Yjg1ZThhOGM4MWM4ZDIxNDg1NGFlNmRiYmFiZWRmOGFkMWFjYTMwOGExMjA2ZGVkN2FiNDM1ZmU2YzcyY2Q3NjVlZDg='
    session.headers.update({'fog-user-token': userToken, 'fog-api-token':apiToken, 'Content-Type': 'application/json' })
    data = {
            "name": "12test host",
            "description":  "test hosts",
            "macs": "c4:90:19:9c:6b:ea",
            "imageID": "22",
            "imagename": "Windows_Server_2019"
          }
    response = session.post(url + '/fog/host/create',data=data)
    print(response.text)
    
    1 Reply Last reply Reply Quote 0
    • S
      Sebastian Roth Moderator
      last edited by Oct 30, 2021, 10:33 AM

      @maddyred The major issue in your script is that data is a simple python object and not JSON yet. Change the post line into this:

      response = session.post(url + '/fog/host/create',data=json.dumps(data))
      

      BUT host creation still doesn’t work with your script for several reasons:

      • You shouldn’t use spaces in hostnames!
      • The "macs" parameter prevents from creating the new host object because it’s not the correct way to specify the MAC address. I have not used the API in a long time and so I am not sure what’s the correct way to do it.

      @JJ-Fullmer Although I have played with it I have not found a way to add a host object including the MAC address association. Can you give us some hints on how to do this. What does the JSON string have to look like for creating a host including MAC address?

      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

      M 1 Reply Last reply Nov 9, 2021, 11:30 AM Reply Quote 0
      • M
        maddyred @Sebastian Roth
        last edited by Nov 9, 2021, 11:30 AM

        @sebastian-roth Hi, I tried with jsondumps(data) and it is now throwing HTTP 500 error. Need some help on registering host with api.

        1 Reply Last reply Reply Quote 0
        • S
          Sebastian Roth Moderator
          last edited by Nov 23, 2021, 4:01 PM

          @maddyred You might want to take a look at this topic: https://forums.fogproject.org/topic/15848/api-creating-host

          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 0
          • 1 / 1
          • First post
            Last post

          172

          Online

          12.0k

          Users

          17.3k

          Topics

          155.2k

          Posts
          Copyright © 2012-2024 FOG Project