API Method Projection Query
i wanted to use the Method
GET api/V3/Projection/GetProjection?id={id}&typeProjectionId={typeProjectionId}
If i query an Incident with the id and the projectionid i get the right information. But if i want to query an HardwareAssetID with an HWAssetProjectionID i get only null. Is it because this Method only works with workitems? If so, we need a Method to query config items as well.<br><br>$HWAssetID = $HWAsset.Id<br>$ProjectionID = "7dd5144c-bd5d-af27-e3af-debcb5a53546"<br>$ProjectionURL = "http://servername/api/V3/Projection/GetProjection?id=$HWAssetID&typeProjectionId=$ProjectionID"<br>Invoke-RestMethod -Uri $ProjectionURL -Credential $CiresonPortalCred <br>
Best Answer
-
Justin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭@Jan_Schulz - The Hardware Asset projections don't have an 'Id' property which is what that API endpoint expects. You might want to use api/V3/Projection/GetProjectionByCriteria. That endpoint will expect a json post body that looks like this:$postBody = @"{"Id":"7dd5144c-bd5d-af27-e3af-debcb5a53546","Criteria":{"Base":{"Expression":{"SimpleExpression":{"ValueExpressionLeft":{"Property":"`$Context/Property[Type='c0c58e7f-7865-55cc-4600-753305b9be64']/HardwareAssetID$"},"Operator":"Equal","ValueExpressionRight":{"Value":"<the HardwareAssetId of your hardware asset here>"}}}}}}6
Answers
thank you very much :-)
so the method i used is only for workitems because of the id properties?
{"success":false,"message":"An error occurred.","exception":"System.NullReferenceException: Object reference not set to an instance of an object.\r\n at CiresonWebConsole.Controllers.api.V3.ProjectionController.d__8.MoveNext() in D:\\a\\1\\s\\Cireson.WebConsole\\Cireson.ServiceManager.WebConsole\\Controllers\\api\\V3\\ProjectionController.cs:line 86\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.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()"} In Zeile:1 Zeichen:1 + Invoke-RestMethod -Uri $ProjectionURL -Method Post -Body $jsonbody - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
In the meantime i found another Question in the community which helps me, sorry next time i had to search first :-).
thank you for your answer.
https://community.cireson.com/discussion/2905/problem-with-api-v3-projection-getprojectionbycriteria
I got it. My PS Script now works:
$mybody = @'
{ "Id":"6fd42dd3-81b4-ec8d-14d6-08af1e83f63a", "Criteria":{ "Base":{ "Expression":{ "SimpleExpression":{ "ValueExpressionLeft":{ "Property":"$Context/Property[Type='c0c58e7f-7865-55cc-4600-753305b9be64']/DisplayName$"}, "Operator":"Like","ValueExpressionRight":{ "Value":"%test%"} } } } } } '@$ProjectionURL = "http://citywap0391/api/V3/Projection/GetProjectionByCriteria"
Invoke-RestMethod -Uri $ProjectionURL -Method Post -Body $myBody -UseDefaultCredentials -Verbose -ContentType 'application/json'