Home Analyst Portal
Options

Some questions about the V3 api

Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
edited November 2022 in Analyst Portal

I recently built a Powershell script to update an MA or RA with the V3 api, in that case completing it, so external systems may update this activity - for example whenever an exchange online mailbox (which has been requested via a request offering) has been created in azure, we would be able to complete a Manual Activity in this request, so the user knows, that the mailbox got created. But I found some difficulties and therefor have some questions about it:

1) I have the following code snippet:

$templateUrl = "https://OURPORTAL/api/V3/Projection/GetProjection"


$ra = @{


    "typeProjectionId" = $projectionID;


     "id" = $raID
}
$restRA = Invoke-RestMethod -Uri $templateUrl -Method "GET" -Headers @{"Authorization"="Token $restToken"} -ContentType "application/json" -Body $ra
$newRA = $restRA
$newRA.Reviewer.Decision.Id = "0e856c6c-04e5-0a8e-6041-bc7715b4747e"
$newRA.Reviewer.Decision.Name = "Approved"
$voted = @{


    "formJson" = @{


        "original" = $restRA;
        "current" = $newRA


    }


}


$votedJSON = $voted | ConvertTo-Json -Depth 99


$createURL = "https://OURPORTAL/api/V3/Projection/Commit"


$updateRA = Invoke-RestMethod -Uri $createURL -Method "POST" -Headers @{"Authorization"="Token $restToken"} -ContentType "application/json" -Body $votedJSON

The thing is, whenever I change the Reviewer.Decision.id and Reviewer.Decision.Name of the $newRA, it also changes it inside the $restRA. SO whenever I make the Commit call, nothing happens, as "original" and "current" are the same. I solved this by just making the GetProjection API Call again and saving that into the $newRA variable. Then it works fine.

The same is with MAs, I also have to make the same call again in order for the original json to not be changed. I tried it with a fixed change, where I only have one activity. When I receive the change via GetProjection and copy the change json to a new variable, then complete the activity with a commit call for the whole change (where I only change the activity status id and name), it works, so it might be an issue with the Activity.

So am I doing something wrong here? Or is this intended?


2) Whenever I want to approve a review activity it would be amazing if I could add a reviewer comment and date to the approval. I tried it with the following code:

$restRA.Reviewer.Decision.Id = "0e856c6c-04e5-0a8e-6041-bc7715b4747e"
$restRA.Reviewer.Decision.Name = "Approved"
$restRA.Reviewer.Comments = "Approval by v3 API"
$restRA.Reviewer.DecisionDate = (Get-date).ToUniversalTime()

Whenever I want to change the Comments and DecisionDate inside this json, I receive the following error message. It seems like it cannot be changed when it is empty initially:


The property 'Comments' cannot be found on this object. Verify that the property exists and can be set.
The property 'DecisionDate' cannot be found on this object. Verify that the property exists and can be set.

Is there a way to set both of these properties?

Best Answer

  • Options
    Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    @Simon_Zeinhofer - You are pretty close I think. You can copy and separate the object by doing the following:

    $newRA = $restRA | ConvertTo-Json -Depth 99 | ConvertFrom-Json

    But also the Reviewer portion ($newRa.Reviewer) is an array not a single object. Try:

    $newRa.Reviewer[0].Comments = "Approval by v3 API"

Answers

  • Options
    Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    @Simon_Zeinhofer - You are pretty close I think. You can copy and separate the object by doing the following:

    $newRA = $restRA | ConvertTo-Json -Depth 99 | ConvertFrom-Json

    But also the Reviewer portion ($newRa.Reviewer) is an array not a single object. Try:

    $newRa.Reviewer[0].Comments = "Approval by v3 API"

  • Options
    Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭

    Thank you so much @Justin_Workman , we will try that asap

Sign In or Register to comment.