Home General Discussion

API Method Projection Query

Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭
Hi,

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&nbsp;<br>

Best Answer

Answers

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭
    @Justin_Workman
    thank you very much :-)
    so the method i used is only for workitems because of the id properties?
  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Correct
  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    FYI The forum is clipping the last line of my earlier post.  You'll want to terminate that string with the @ and a double quote(")
  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭
    edited January 2019
    I tested the query in Powershell and finally it didnt work, but it seems to be an Powershell problem, because in ARC (Chrome Extension) it works great. Do you know why i get this error?


    {"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




    MyCode is:


    $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%"} } } } } } '@ $jsonbody = $myBody | ConvertTo-Json #???? $ProjectionURL = "http://servername/api/V3/Projection/GetProjectionByCriteria" Invoke-RestMethod -Uri $ProjectionURL -Method Post -Body $jsonbody -UseDefaultCredentials -Verbose
  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    It looks like you're using $jsonbody in the invocation of invoke-restmethod, but you're populating $myBody.  Is that the issue?

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

     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'


Sign In or Register to comment.