The CreatorCon Call for Content is officially open! Get started here.

Adding CI using API interface

Sergey Lisitsin
Kilo Contributor

Hello everyone,

I am trying to write a script to import multiple CI's into CMDB using REST API interface. I am testing the deployment in Postman, create a POST request and receive the following data:

 

"result": {
        "items": [
            {
                "className": "cmdb_ci_router",
                "sysId": "Unknown",
                "identifierEntrySysId": "Unknown",
                "errors": [
                    {
                        "error": "INVALID_INPUT_DATA",
                        "message": "In payload invalid data source [null] exist. You need to provide a valid choice value from field [discovery_source] in table [cmdb_ci]"
                    }
                ],
                "identificationAttempts": [],

Obviously the error message suggests that field [discovery_source] is missing the correct info. I have tried to leave the field blank, putting in "None" or other name of existing discovery source, but still get the same error. Does it need to be an ID of a discovery source and if so, where do I find it?

Thanks

1 ACCEPTED SOLUTION

can u try something like below ? 

{
  "attributes": {
    "name" : "New_PC"
  },
  "source": "ServiceNow",

}

View solution in original post

13 REPLIES 13

how is ur request package , can u share ? does it match with below link i shared which is oob request format ? 

Ravi,

the data I send is as follows:

{         "attributes": {
            "name": "New_PC"
            }

    }

can u try something like below ? 

{
  "attributes": {
    "name" : "New_PC"
  },
  "source": "ServiceNow",

}

Thanks Ravi, that is seemingly getting accepted, however I can't see the new CI being created and the number of CI devices in the PC class doesn't increase. This is the result I get back:

{
    "result": {
        "outbound_relations": [],
        "attributes": {
            "os_address_width": "",
            "attested_date": "",
            "operational_status": "1",
            "os_service_pack": "",
            "cpu_core_thread": "",
            "cpu_manufacturer": "",
            "sys_updated_on": "2022-04-07 13:49:02",
            "discovery_source": "ServiceNow",
            "first_discovered": "2022-04-07 13:49:02",
            "due_in": "",
            "invoice_number": "",
            "gl_account": "",
            "sys_created_by": "integration.user",
            "warranty_expiration": "",
            "ram": "",
            "cpu_name": "",
            "cpu_speed": "",
            "owned_by": "",
            "checked_out": "",
            "sys_domain_path": "/",
            "disk_space": "",
            "object_id": "",
            "business_unit": "",
            "maintenance_schedule": "",
            "cost_center": "",
            "attested_by": "",
            "dns_domain": "",
            "assigned": "",
            "purchase_date": "",
            "life_cycle_stage": "",
            "short_description": "",
            "cd_speed": "",
            "floppy": "",
            "managed_by": "",
            "os_domain": "",
            "last_discovered": "2022-04-07 13:49:02",
            "can_print": "false",
            "sys_class_name": "cmdb_ci_computer",
            "manufacturer": "",
            "cpu_count": "",
            "vendor": "",
            "life_cycle_stage_status": "",
            "model_number": "",
            "assigned_to": "",
            "start_date": "",
            "os_version": "",
            "serial_number": "",
            "cd_rom": "false",
            "support_group": "",
            "unverified": "false",
            "correlation_id": "",
            "attributes": "",
            "asset": "",
            "form_factor": "",
            "cpu_core_count": "",
            "skip_sync": "false",
            "most_frequent_user": "",
            "attestation_score": "",
            "sys_updated_by": "integration.user",
            "sys_created_on": "2022-04-07 13:49:02",
            "sys_domain": {
                "display_value": "global",
                "link": "https://dev94109.service-now.com/api/now/v1/table/sys_user_group/global",
                "value": "global"
            },
            "cpu_type": "",
            "install_date": "",
            "asset_tag": "",
            "hardware_substatus": "",
            "fqdn": "",
            "change_control": "",
            "internet_facing": "true",
            "delivery_date": "",
            "hardware_status": "installed",
            "install_status": "1",
            "supported_by": "",
            "name": "New_PC4",
            "subcategory": "Computer",
            "default_gateway": "",
            "chassis_type": "",
            "virtual": "false",
            "assignment_group": "",
            "managed_by_group": "",
            "sys_id": "a75ad51c2f7a4110996fd39df699b690",
            "po_number": "",
            "checked_in": "",
            "sys_class_path": "/!!/!2/!(",
            "mac_address": "",
            "company": "",
            "justification": "",
            "department": "",
            "cost": "",
            "comments": "",
            "os": "",
            "attestation_status": "Not Yet Reviewed",
            "sys_mod_count": "0",
            "monitor": "false",
            "model_id": "",
            "ip_address": "",
            "duplicate_of": "",
            "sys_tags": "",
            "cost_cc": "USD",
            "order_date": "",
            "schedule": "",
            "environment": "",
            "due": "",
            "attested": "false",
            "location": "",
            "category": "Hardware",
            "fault_count": "0",
            "lease_id": ""
        },
        "inbound_relations": []
    }
}

okay seems like its saying it created one ! 

when u go to cmdb_ci_computer list view and search with the sys id provided 

a75ad51c2f7a4110996fd39df699b690

do you not see any record ?