How do I retrieve issues of specific status with JQL - jira

Entering a url, or running with curl, like:
https://<myurl>/rest/api/2/search?jql=project=<myproject>&status=closed&fields=id,key,status,project&maxResults=5
returns me 5 items in my project but with all statuses. For some reason I can't query for a specific status.
The output (part of it) is:
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 5,
"total": 727,
"issues": [
{
"expand": "editmeta,renderedFields,transitions,changelog,operations",
"id": "79577",
"self": "https://<myurl>/rest/api/2/issue/79577",
"key": "<myproject>-774",
"fields": {
"project": {
"self": "https://<myurl>/rest/api/2/project/<myproject>",
"id": "14421",
"key": "<myproject>",
"name": "<myproject>",
"avatarUrls": {
(...)
}
},
"status": {
"self": "<myurl>/rest/api/2/status/1",
"description": "The issue is open and ready for the assignee to start work on it.",
"iconUrl": "https://<myurl>/images/icons/statuses/open.png",
"name": "Open",
"id": "1"
}
}
},(...)
]
}
How to query for a given status? Many thanks.

Use URL encoding on the attributes.
Perhaps use an online tool like this to URL encode your JQL from this:
project = PROJECTKEY AND status = Closed
to get this:
/rest/api/2/search?jql=project%20%3D%20PROJECTKEY%20AND%20status%20%3D%20Closed&fields=id,key,status,project&maxResults=5
The resulting JSON will be all closed issues.

Run the query you want in the Issue Navigator. Use the link to the left of the Share button that resembles a chain link to find the URL for the query, e.g.
http://jira.example.com/issues/?jql=project%20%3D%20MDOAR%20and%20status%20%3D%20Closed
Use that URL with curl

Related

Graph Pagination in Logic Apps

I'm trying to fetch all users from a specific group via an HTTP connector, a registered app, and Microsoft Graph.
The registered app has Directory.Read.All permissions.
My idea is that I'm calling the nextLink as long as it's there while appending all of the fetched users' userPrincipalName to an array eventually filling the array with all users of the group.
My Logic App looks like this:
Unfortunately, I'm just 1 reputation short of posting images, please forgive. The 3 links should provide an overview of the structure of my app.
First, nextLink is initialized to the first Graph API endpoint. This variable is set to the current nextLink through each iteration of the until loop.
Second, For the purpose of this exercise, I only get the top 5. I know there are only 9 users:
Lastly, I call the union method on the "users" array that I initialized earlier and the "value" array from the HTTP get method, to get one single array consisting of all users:
The issue is that the HTTP action always returns the same top 5 users. I've checked that the nextLink provided in the first HTTP GET call to Graph, is correct by copying it from the Runs history and pasting it into Microsoft Graph Explorer and there the next 4 users are correctly returned.
I also made sure that, for each iteration in the until loop, I call the Graph API with the nextLink from the previous iteration as expected.
The nextLink returned inside of the Logic App is exactly the same when I test it in Graph Explorer, but the same nextLink returns 2 different results when called from Graph Explorer and inside my Logic App.
Why is the result always the same top 5 users and not the next 4 users as expected?
If not sure about the reason why you will get this issue, but based on your requirement, I did a sample below:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "GetGroupUrl",
"type": "string",
"value": "https://graph.microsoft.com/v1.0/groups/<your group id>/members?$select=userPrincipalName&$top=5"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "users",
"type": "array"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Until": {
"actions": {
"Compose": {
"inputs": "#union(variables('users'),body('HTTP')['value'])",
"runAfter": {
"HTTP": [
"Succeeded"
]
},
"type": "Compose"
},
"HTTP": {
"inputs": {
"authentication": {
"audience": "https://graph.microsoft.com",
"clientId": "<app id>",
"secret": "<app secret>",
"tenant": "<your secret>",
"type": "ActiveDirectoryOAuth"
},
"method": "GET",
"uri": "#variables('GetGroupUrl')"
},
"runAfter": {},
"type": "Http"
},
"Set_variable": {
"inputs": {
"name": "GetGroupUrl",
"value": "#{if(equals(body('HTTP')?['#odata.nextLink'], null),null,body('HTTP')['#odata.nextLink'])}"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"expression": "#equals(variables('GetGroupUrl'), '')",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Initialize_variable_2": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "GET",
"schema": {
"properties": {
"text": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
You can just replace the params with your own and paste it into your logic app code view and test it .
It works for me, as you can see , each request results are different :
Hope it helps .
This issue solved by OP self, this issue is due to queries in request URL , copy OP's comment as an answer :
After fiddling a bit more around with what each of you providing I
found a solution. It seems that when the query arguments are passed to
the HTTP GET outside of the endpoint itself (meaning in the "queries"
field inside of the block) it seems to keep overriding the nextLink.
When writing the endpoint URL out entirely with the odata parameters,
it works as intended.

how to pull code review reports from TFSGIT

I am trying to pull code review reports from the TFSGIT/VSTS, but I don't see anything out of the box.
The 3rd part code review tools like "ReviewAssistant" works great but they are not integrated with the Pull Request. It decouples code review to pull request.
I would like to get reports from the PullRequest code comments.
You can pull data from TFS with Rest API.
To get the PR code comments you can use the Pull Request Threads - List.
The request is:
https://{instance}/{collection}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/threads?api-version=4.1
In the JSON response, you will get the comments and the comment location in the code (line number):
"comments": [
{
"id": 1,
"parentCommentId": 0,
"author": {
"displayName": "Shayki Abramczyk",
"url": "https://spsprodweu3.vssps.visualstudio.com/Ac256a93d-7cea-4070-xxxxxxxxx/_apis/Identities/7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
"_links": {
"avatar": {
"href": "https://dev.azure.com/xxxxxx/_apis/GraphProfile/MemberAvatars/msa.N2E5YTlxxxxxxxxxxxxxxx"
}
},
"id": "7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
"uniqueName": "xxxxxxxx",
"imageUrl": "https://dev.azure.com/xxxxxxxx/_api/_common/identityImage?id=7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
"descriptor": "msa.N2E5YTliNDQtYTJmMS03ZGZkLWE3Zjxxxxxxxxxxx"
},
"content": "test comment",
"publishedDate": "2019-02-25T11:11:03.45Z",
"lastUpdatedDate": "2019-02-25T11:11:03.45Z",
"lastContentUpdatedDate": "2019-02-25T11:11:03.45Z",
"commentType": "text",
"usersLiked": [
]
}
],
"status": "active",
"threadContext": {
"filePath": "/SampleForVSTS/Program.cs",
"leftFileStart": {
"line": 14,
"offset": 1
},
"leftFileEnd": {
"line": 14,
"offset": 10
}
},
As you can see there is a comment test comment at line 14 in the file SampleForVSTS/Program.cs.
You can write simple code in any language to get the data with Rest API.

How can I use TFS WebApi to remove a workitemlink

I am using Microsoft.TeamFoundation.WorkItemTracking.WebApi and trying to add and remove a workitemlink from an item.
I am calling
workItemTrackingHttpClient.UpdateWorkItemAsync(jsonPatchDocument, Id);
and my JsonPatchDocument looks like this.
[
{
"op": 1,
"Path": "/relations/-",
"From": null,
"Value": {
"Rel": "System.LinkTypes.Dependency-Forward",
"Url": "https://[server]/tfs/DefaultCollection/_apis/wit/workItems/[id]"
}
}
]
When I use "op": 0 to update (add) it works correctly but I cannot work out the correct form for remove.
I get an error similar to
VssServiceException
Remove does not support insert.
Microsoft.VisualStudio.Services.WebApi
-2146232832
Anyone have any ideas please.
To remove a link, the JsonPatchDocument is not like the insert, it is necessary to provide "value".
It is like:
[
{
"op": "test",
"path": "/rev",
"value": 3
},
{
"op": "remove",
"path": "/relations/0"
}
]
To remove a link, you need to point which link to be removed by using "relations/Id". The Id is started from 0.
For more induction, please refer to the official document.

In Watson Discovery, limiting "return"ed fields to aggregation values

For the Discovery REST api, the argument/parameter "return" controls which fields are returned.
So if I pass these arguments to the API
{
"query": named_sector,
"count": "10",
"filter": filter_dates,
"aggregation" : "term(docSentiment.type,count:3)"
}
my_query = discovery.query(my_disc_environment_id, my_disc_collection_id, qopts)
print(json.dumps(my_query, indent=2))
I get the following:
{
"matching_results": 14779,
"aggregations": [
{
"type": "term",
"field": "docSentiment.type",
"count": 3,
"results": [
{
"key": "positive",
"matching_results": 4212
},
{
"key": "negative",
"matching_results": 3259
},
{
"key": "neutral",
"matching_results": 152
}
]
}
],
"results": [
{
"id": "6389715fe7e7f711e0bc09d4f1236639",
"score": 1.3689895,
"yyyymm": "201704",
"url": "https://seekingalpha.com/article/4060446-valuation-dashboard-consumer-discretionary-update",
"enrichedTitle": null,
"host": "seekingalpha.com",
"text": "Valuation Dashboard: Consumer Discretionary - Update\n\nSummary\n\nValuation metrics in Consumer Discretionary.\n\nEvolution since last month.\n\nA list of stocks loo ....
and thousands of more lines. How do I restrict the output to the aggregations section? Is this an issue of me better handling the JSON structure that is returned?
thanks
If you change the count argument to 0, the returned JSON will only contain the aggregations.
Also, if you're using the Discovery web tooling, you can enter 0 for the "Number of results to return (Count)" field.
More details and an example can be found here: https://www.ibm.com/watson/developercloud/doc/discovery/using.html#building-aggregations

how to create a confluence page using rest api with a label

I checked the documentation and I saw how to update an existing page to add the labels.
What I need is to create a new confluence page with a specific label that is added during this creation.
With get I saw that for a existing page, labels are stored into the metadatas:
"metadata": {
"labels": {
"results": [
{
"prefix": "global",
"name": "labelName1",
"id": "2195459"
},
{
"prefix": "global",
"name": "labelName2",
"id": "2195460"
}
],
"start": 0,
"limit": 200,
"size": 2,
"_links": {
"self": "http://localhost:8090/rest/api/content/2129921/label"
}
},...
Can anyone tell me if it is possible to create a page with a label and if yes, how?
Thanks
According to the documentation (https://docs.atlassian.com/confluence/REST/latest/#content/{id}/label-addLabels), you can add the following to your json for creating the page:
"metadata": {
"labels": [
{
"prefix": "global",
"name": "label1"
},
{
"prefix": "global",
"name": "label2"
}
]
},
I have not, however, been successful at getting this implementation to work yet. It seems to be ignored when I invoke the post to the endpoint (/rest/api/content).
I did some tests and found out that if you add below json node just after body node a curl will create the page with label2 successfully.
,"metadata": {"labels": [{"prefix": "global","name": "label2"}]}

Resources