Has anyone had any luck getting the UpdateWatchlistByWorkItemId API to work?
According to the documentation this is used to add/delete users to a watchlist.
I was trying to put together a custom task for "Add to my watchlist" but I cant get the API to return anything but false.
If so would you mind posting the format you used for it.
Best Answer
-
Conner_Wood Customer Ninja IT Monkey ✭✭✭✭I have started playing with the Cireson API myself and it appears UpdateWatchlistByWorkItemId does not work at all. I also in IIS > Sites > CiresonPortal > Authentication > Enabled Anonymous Authentication since we use Windows Authentication through the Portal.
First of all, Cireson should make this a POST Method as this is could be submitting large amounts of JSON text to the Portal (GET=Read,POST=Write).
Secondly it seems bizarre that something from the few things that were delivered from the Watchlist request don't work, was this all just created during a last minute all-nighter?
Thirdly, there needs a sample powershell script for each API command to prove Cireson tested their own releases and actually enforce quality control.
PowerShell Example: GetChildWorkItems#enter your portal URL here $site = "http://localhost" #API url to GetChildWorkItems $url = ($site + "/api/V3/WorkItem/GetChildWorkItems") #Retrieves the child workitem Guids for any requested parent Base Ids #Input my Ticket(s) "BaseManagedEntityId" in array format $body = @("17853613-9A26-8DB5-FA8A-0563D5EB0ECE", "B59D24C8-AE15-450B-8D1B-C476864B53CC") #Parent GUIDs, GUID must be valid $jsonBody = ConvertTo-Json $body #Correctly convert to Json even with one array element $response = try { Invoke-RestMethod -UseDefaultCredentials -Uri $url -Method POST -ContentType 'application/json' -Body $jsonBody } catch { $_.Exception.Response } if(!$response) { echo "Response is null." } else { echo $response }<br>
See, it's not hard to do when the Cireson API method works, however UpdateWatchlistByWorkItemId which uses the same json body array format does not work, here is my code that would work if Cireson fixes their API GET method, although as stated before I'd like this method to be POST since possibility of submitting large amounts of text is very real. I am going to use 142F68DD-F1E1-3883-61EA-1436EC3436CD as the workitemId, you'll need to figure out your own ticket "BaseManagedEntityId" to test it out with.#enter your portal URL here $site = "http://localhost"<br> #URL of UpdateWatchlistByWorkItemId with workitemId query parameter filled in $url = ($site + "/api/V3/WorkItem/UpdateWatchlistByWorkItemId?workitemId=142F68DD-F1E1-3883-61EA-1436EC3436CD") #Adds/deletes users to a watchlist $body = @("55ef7e06-8ee3-576f-76a7-ec858b20f751","9e7d7d10-4217-f69c-2551-bc12cd94c1a0") #returns null and doesn't update. #Other attempted formats, all fail to update and return null. #$body = @{Id=@("55ef7e06-8ee3-576f-76a7-ec858b20f751","9e7d7d10-4217-f69c-2551-bc12cd94c1a0")} #returns null. #$body = @{"userId"=@("55ef7e06-8ee3-576f-76a7-ec858b20f751","9e7d7d10-4217-f69c-2551-bc12cd94c1a0")} #returns null. $jsonBody = ConvertTo-Json $body -Depth 3 Echo ("`nShowing `$jsonBody is in correct request format as shown on Cireson Support:`n" + $jsonBody + "`n") #Other attempted formats, all fail to update and return null. #$jsonBody = '["55ef7e06-8ee3-576f-76a7-ec858b20f751","9e7d7d10-4217-f69c-2551-bc12cd94c1a0"]' #returns null. #$jsonBody = '[{"Id": "55ef7e06-8ee3-576f-76a7-ec858b20f751"},{"Id": "9e7d7d10-4217-f69c-2551-bc12cd94c1a0"}]' #returns null. #$jsonBody = '[{"userId": "55ef7e06-8ee3-576f-76a7-ec858b20f751"},{"userId": "9e7d7d10-4217-f69c-2551-bc12cd94c1a0"}]' #returns null. $response = try { Invoke-RestMethod -UseDefaultCredentials -Uri $url -Method GET -ContentType 'application/json' -Body $jsonBody } catch { $_.Exception.Response } #Attempted with xml format, also fails to update and returns null. #$xmlBody = '<ArrayOfguid xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><guid>9e7d7d10-4217-f69c-2551-bc12cd94c1a0</guid></ArrayOfguid>' #$response = try { Invoke-RestMethod -Uri $url -Method GET -ContentType 'text/xml' -Body $xmlBody } catch { echo $_.Exception.Response } if(!$response) { echo "Response is null." } else { echo $response }<br>
The concept isn't hard to understand, you pass an array of userIds that will be the new watchlist, the watchlist based on the workitemId query parameter removes all previous entries of itself in the table and then adds these. However Cireson failed to make this API call work.
Cireson, please don't conveniently try to say my code is incorrect, I proved "-UseDefaultCredentials" worked with GetChildWorkItems so guess what, it would work if your side of the code did. And yes, I did already try with using the token approach, same result because it would work if the Cireson side of the code did....
Oh, and Cireson, would you kindly make a ticket for yourselves as a reminder that this needs fixing. Make no mistake, I'd love to be proven wrong about this, but..... you'll have to prove it with a working example.
@R_Delawder I want to thank you because something like this would've driven me mad, I really did assume Cireson made sure their API calls worked, especially for the Watchlist which was the #1 requested feature, ah well, that's the price of being an optimist!
5
Answers
Have you used the API before at all? I'd recommend starting calls to the Cireson Portal API with PowerShell
Then after confirming any of the GET methods work with your script from the Cireson API Reference, I would then attempt to pass already confirmed values to the functions to ensure each one would work:
- GetWatchlistByWorkItemId
- GetWatchListByUserId
- UpdateWatchlistByWorkItemId
Good Luck!Yes, I have several custom task that use the API, I just haven't been able to get the update watchlist one to work. The getwatchlistbyworkitemid worked fine for me but not the update one.
I haven't tried running it via PowerShell but guess I could to test it there when I have some time.
First of all, Cireson should make this a POST Method as this is could be submitting large amounts of JSON text to the Portal (GET=Read,POST=Write).
Secondly it seems bizarre that something from the few things that were delivered from the Watchlist request don't work, was this all just created during a last minute all-nighter?
Thirdly, there needs a sample powershell script for each API command to prove Cireson tested their own releases and actually enforce quality control.
PowerShell Example: GetChildWorkItems
See, it's not hard to do when the Cireson API method works, however UpdateWatchlistByWorkItemId which uses the same json body array format does not work, here is my code that would work if Cireson fixes their API GET method, although as stated before I'd like this method to be POST since possibility of submitting large amounts of text is very real. I am going to use 142F68DD-F1E1-3883-61EA-1436EC3436CD as the workitemId, you'll need to figure out your own ticket "BaseManagedEntityId" to test it out with.
The concept isn't hard to understand, you pass an array of userIds that will be the new watchlist, the watchlist based on the workitemId query parameter removes all previous entries of itself in the table and then adds these. However Cireson failed to make this API call work.
Cireson, please don't conveniently try to say my code is incorrect, I proved "-UseDefaultCredentials" worked with GetChildWorkItems so guess what, it would work if your side of the code did. And yes, I did already try with using the token approach, same result because it would work if the Cireson side of the code did....
Oh, and Cireson, would you kindly make a ticket for yourselves as a reminder that this needs fixing. Make no mistake, I'd love to be proven wrong about this, but..... you'll have to prove it with a working example.
@R_Delawder I want to thank you because something like this would've driven me mad, I really did assume Cireson made sure their API calls worked, especially for the Watchlist which was the #1 requested feature, ah well, that's the price of being an optimist!
[POST] AddToWatchlist
[DELETE] DeleteFromWatchlist
Thank you Cireson workers for updating and improving the Watch List Functionality. Great job Cireson, you have earned that compliment.