IT Monkey:   Click Here to Help Me Build the Agenda for Upcoming Cireson Webinars!

Is it possible to create a ConfigItem with the API

Jan_SchulzJan_Schulz Customer IT Monkey ✭

Hi,

we see the Rest API GET api/V3/Projection/CreateProjectionByTemplate?id={id}&createdById={createdById} and hoped we could create a ConfigItem with it. But we get an error.


[ClassName] does not contain a property with name 'Status'.\r\n  at

Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectBaseWithProperties.TryGetProperty(ManagementPackType type, String name, EnterpriseManagementSimpleObject& simpleObject)\r\n  at

Cireson.ServiceManager.Services.Implementations.WorkItemService.d__17.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n  at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at CiresonWebConsole.Controllers.api.V3.ProjectionController.d__6.MoveNext() in

D:\\a\\1\\s\\Cireson.WebConsole\\Cireson.ServiceManager.WebConsole\\Controllers\\api\\V3\\ProjectionController.cs:line 57\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at

System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()\r\n--- End of

stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at

System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n  at

System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at

System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()\r\n--- End

of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n  at

System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()"}


Does the API only support Workitem type classes to be created with it?

If so, will there be a API in future to do such things?

We need such a feature, beacuase we want to use the CMDB Portal to work with CIs not only to edit the items. In some cases the SCSM DB is the primary source for some of our config data.

regards,

Jan

Answers

  • steve_tuelsteve_tuel Cireson Consultant Adept IT Monkey ✭✭

    You can do it using the Commit API. Below is basic example in Javascript. You would have to build a UI around passing data into the various fields in the newCI variable.

    var newCI = {

    "BaseId": null,

    "FullClassName": "CI Name", // Get-SCSMClass InternalNameGoesHere | ft DisplayName, Name, Id --DisplayName 

    "ClassName": "CI Internal Name", // --Name

    "ClassTypeId": "37326d71-03e6-ea87-d43e-dacfe6d244cc", // --Id

    "NameRelationship": null,

    "CIKey": "{0}",

    "DisplayName": "My New CI",

    "TimeAdded": "0001-01-01T00:00:00.000Z",


    };

    var strData = { "formJson":{"original": null, "current": newCI}}

    console.log (strData);

    $.ajax({

    url: "/api/V3/Projection/Commit",

    type: "POST",

    contentType: "application/json; charset=utf-8",

    dataType: "json",

    data: JSON.stringify(strData) ,

    success: function (data2) {

    //console.log(data2)

    }

    });

  • Daniel_DeimlingDaniel_Deimling Customer IT Monkey ✭

    Hi,

    just tried that solution. Didn't work for me.

    Code:

    let currentDateTime = new Date(Date.now());

    let newCI = {

    "BaseId": null,

    "FullClassName": "1|FFM.Class.Buchungsdaten/f52053a985f13e91|1.0.0.0|FFM.Class.Buchungsdatenposition||",

    "ClassName": "FFM.Class.Buchungsdatenposition",

    "ClassTypeId": "eb71a255-bbf3-0807-9994-c366169a1bd0",

    "NameRelationship": null,

    "CIKey": "{0}",

    "DisplayName": "My New CI",

    "TimeAdded": currentDateTime.toISOString()

    };


    let strData = { "formJson": { "original": null, "current": newCI } }

    console.log(strData);

    $.ajax({

    url: "/api/V3/Projection/Commit",

    type: "POST",

    contentType: "application/json; charset=utf-8",

    dataType: "json",

    data: JSON.stringify(strData),

    })

    .done(function( data, textStatus, jqXHR ) {

    })

    .fail(function( jqXHR, textStatus, errorThrown ) {

    });

    Error:

    jqXHR.responseText:

    "{"message":"Unrecognized Guid format.","success":false,"data":"","exception":"Unrecognized Guid format.","BaseId":""}"


    Looks like "BaseId" expects a GUID of an EnterpriseManagementObject Id, doesn't work with an ManagementPackClass Id (e. g. like from ConfigItem). With an EnterpriseManagementObject Id the result looks ok but an object is not created.

  • steve_tuelsteve_tuel Cireson Consultant Adept IT Monkey ✭✭

    Any chance you can send me the MP that defines this custom class?

  • steve_tuelsteve_tuel Cireson Consultant Adept IT Monkey ✭✭

    That error is misleading. The Full Class Name and ClassTypeId were changed. I also updated it to include your key, ID. The Commit API is also picky about Time Added, it needs to remain as it is shown below. Give the following a try (it worked in my lab).


    let newCI = {


    "BaseId": null,


    "FullClassName": "FFM.Class.Buchungsdatenposition",


    "ClassName": "FFM.Class.Buchungsdatenposition",


    "ClassTypeId": "253b4bbf-3ff4-43ed-9004-bf0f5b5e4c3e",


    "NameRelationship": null,


    "ID": "{0}",


    "DisplayName": "My New CI 2",


    "TimeAdded": "0001-01-01T00:00:00.000Z",


    };




    let strData = { "formJson": { "original": null, "current": newCI } }


    console.log(strData);


    $.ajax({


    url: "/api/V3/Projection/Commit",


    type: "POST",


    contentType: "application/json; charset=utf-8",


    dataType: "json",


    data: JSON.stringify(strData),


    })


    .done(function( data, textStatus, jqXHR ) {


    })


    .fail(function( jqXHR, textStatus, errorThrown ) {


    });

Sign In or Register to comment.