Community
    • Categories
    • Recent
    • Popular
    • Users
    • Search
    • Register
    • Login

    Creating objects using the API

    Scheduled Pinned Locked Moved Operating
    5 Posts 2 Posters 849 Views 1 Watching
    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.
    • J Offline
      joana_115
      last edited by

      Hello.
      I am trying to create objects using the API (JSON-RPC).
      I am using the method cmdb.object.create for that.
      However, I cannot send a lot of information about the objects.

      For example, the template to create a server is:
      {
      "version": "2.0",
      "method": "cmdb.object.create",
      "params": {
      "type": "C__OBJTYPE__SERVER",
      "title": "My little server",
      "apikey": "xxx",
      "language": "en"
      },
      "id": 1
      }

      Although, I would like to send information about its IP address for example. I can do that by creating the Server using the UI. Can I also do that using the API?

      Can you help me?

      LFischerL 1 Reply Last reply Reply Quote 0
      • LFischerL Offline
        LFischer @joana_115
        last edited by

        Hey @joana_115

        yes that is possible 🙂 You can pass category data in your "object create" request like this:

        {
           "version": "2.0",
           "method": "cmdb.object.create",
           "params": {
              "type": "C__OBJTYPE__SERVER",
              "title": "My little server",
              "apikey": "xxx",
              "language": "en",
              "categories": {
                 "<category constant>": [
                    {"<prop-key>": "<value>"}
                 ],
                 "C__CATG__CPU": [
                    {"title": "CPU 1"},
                    {"title": "CPU 2"}
                 ],
                 "C__CATG__MEMORY": [
                    {"title": "Memory A"}
                 ]
              }
           },
           "id": 1
        }
        
        1 Reply Last reply Reply Quote 0
        • J Offline
          joana_115
          last edited by

          Hey @lfischer,

          Thank you for your response!

          I tried to create the server and associate the IPv4 address, but I can't.
          This is my request:

          {
              "version": "2.0", 
              "method": "cmdb.object.create", 
              "params": {
                  "type": "C__OBJTYPE__SERVER",
                  "title": "my little server",
                  "description": "my little server description",
                  "apikey": "---", 
                  "language": "en",
                  "categories": {
                      "C__CATG__IP": [
                          {"net_type": 1},
                          {"ipv4_assignment": 1},
                          {"ipv4_address": "192.168.1.13"},
                          {"primary_hostaddress": "192.168.1.13"}
                      ]
                  }
              }, 
              "id": 1
          }
          

          The 1 for the "net_type" refers to the IPv4 (Internet Protocol v4) in the table isys_net_type, and the 1 for the "ipv4_assignment" refers to DHCP in the table isys_ip_assignment.

          I am sorry for not being able to use your suggestion.
          What am I doing wrong?

          LFischerL 1 Reply Last reply Reply Quote 0
          • LFischerL Offline
            LFischer @joana_115
            last edited by LFischer

            Hey @joana_115

            I'm afraid I used a bad example or should have explained it a bit more 😉 You'll need to pass all data of one entry in one package, like this:

            {
              "version": "2.0",
              "method": "cmdb.object.create",
              "params": {
                "type": "C__OBJTYPE__SERVER",
                "title": "my little server",
                "description": "my little server description",
                "apikey": "---",
                "language": "en",
                "categories": {
                  "C__CATG__IP": [
                    {
                      "net_type": 1,
                      "ipv4_assignment": 1,
                      "ipv4_address": "192.168.1.13",
                      "primary_hostaddress": "192.168.1.13"
                    }
                  ]
                }
              },
              "id": 1
            }
            

            The reason for this syntax is that you can create multiple entries at once (for multivalue categories). That would look like this:

            "C__CATG__IP": [
              {
                "net_type": 1,
                "ipv4_assignment": 1,
                "ipv4_address": "192.168.1.13",
                "primary_hostaddress": "192.168.1.13"
              },
              {
                "net_type": 1,
                "ipv4_assignment": 1,
                "ipv4_address": "192.168.1.123",
                "primary_hostaddress": "192.168.1.123"
              },
              { ... }
            ]
            

            I believe this might be your issue 🙂 The single data block should look the same as if you create a category entry on its own via cmdb.category.create, like this:

            {
              "version": "2.0",
              "method": "cmdb.category.save",
              "params": {
                "category": "C__CATG__WAN",
                "object": 10582,
                "data": {
                  "capacity_up": 6,
                  "capacity_up_unit": "MBit"
                },
                "apikey": "<api key>"
              },
              "id": 1
            }
            

            I hope this helps 🙂

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              joana_115 @LFischer
              last edited by

              Thank you @lfischer !

              1 Reply Last reply Reply Quote 1

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post