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

    Benutzerdefinierte Kategorien über API

    Scheduled Pinned Locked Moved Entwicklung
    bug api
    3 Posts 1 Posters 572 Views 2 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.
    • MartinVM Offline
      MartinV
      last edited by MartinV

      Hallo!

      Ich möchte mit CMDBObject.createWithCategories() in einer i-doit 1.12.2 Pro ein Objekt (eines benutzerdefinierten Objekttyps) sowohl mit Standard- als auch mit benutzerdefinierten Kategorien anlegen.

      Der Ergebnis-Array enthält aber nur einen Eintrag für die Standardkategorie. Ist nicht vorgesehen, benutzerdefinierte Kategorien anzulegen?

      P.S.: Wir verwenden als Client-API-Lib eine eigene Implementation der i-doit-api-client-php in Python, die genau entlang der PHP-Implementierung geschrieben wurde.

      Codeschnipsel:

      cat = {
          'C__CATG__CUSTOM_FIELDS_ERP_INFORMATIONEN': [{
              K.IDOIT_ERP_CONTRACT_ID: master_data[K.WKS_VER_NR][2:],
              K.IDOIT_ERP_PDV_ENV: obj[K.WKS_OBJ_ENV],
              K.IDOIT_ERP_ARA_ENV: obj[K.WKS_OBJ_ARA_ENV],
              'description': obj[K.WKS_OBJ_REMARKS],
          }],
      }
      # ...
      cat['C__CATG__MODEL'] = [{
           'manufacturer': obj[K.WKS_OBJ_PRODUCER],
           'title': obj[K.WKS_OBJ_PROD_NAME],
           'productid': obj[K.WKS_OBJ_PROD_PART],
           'service_tag': None,
           'serial': obj[K.WKS_OBJ_PROD_SN],
           'firmware': None,
           'description': None,
      }]
      # ...
      result = idoitapi.CMDBObject(api).create_with_categories(
          object_type=obj_klasse_to_idoit_objtype(mgd_svc),
          title=obj[K.WKS_OBJ_HOSTNAME],
          categories=cat,
          attributes={
              'category': None,
              'purpose': None,
              'cmdb_status': 'C__CMDB_STATUS__IN_OPERATION',
              'description': None,
          }
      )
      

      Das ergibt

      result = {
          'id': 385,
          'message': 'Object was successfully created',
          'categories': {
              'C__CATG__MODEL': [19]
          },
          'success': True
      }
      
      MartinVM 1 Reply Last reply Reply Quote 0
      • MartinVM Offline
        MartinV @MartinV
        last edited by MartinV

        Das hat unser PRO-Reseller mittlerweile reproduzieren können und ein Ticket bei Synetics eröffnet. In der Zwischenzeit habe ich mir beholfen mit

        def idoit_create_with_categories(api, object_type, title, categories, attributes=None):
            object_id = idoitapi.CMDBObject(api).create(object_type, title, attributes)
        
            requests = list()
        
            for category, catattr_array in categories.items():
                for i, catattrs in enumerate(catattr_array):
                    params = {
                        'object': object_id,
                        'category': category,
                        'data': catattrs
                    }
                    if len(catattr_array) > 1:
                        params['entry'] = i
                    requests.append({
                        'method': 'cmdb.category.save',
                        'params': params
                    })
        
            response = api.batch_request(requests)
        
            result = {
                'id': object_id,
                'success': True,
                'categories': dict(),
            }
        
            for i, entry in enumerate(response):
                if 'success' not in entry or not entry['success']:
                    idoitapi.CMDBObject(api).delete(object_id)
                    message = 'Bad result'
                    if 'message' in entry:
                        message += ': ' + entry['message']
                    raise JSONRPC(message=message)
        
                params = requests[i]['params']
        
                category = params['category']
                if 'entry' in params:
                    # For multi-valued categories, value is a list of IDs
                    if category not in result['categories']:
                        result['categories'][category] = list()
                    result['categories'][category][params['entry']] = entry['entry']
                else:
                    result['categories'].update({category: entry['entry']})
        
            return result
        
        
        MartinVM 1 Reply Last reply Reply Quote 0
        • MartinVM Offline
          MartinV @MartinV
          last edited by

          Inzwischen habe ich von unserem Reseller Nachricht bekommen, dass dieser Bug in i-doit 1.13.2 behoben sein wird.

          1 Reply Last reply Reply Quote 0

          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