i want to update the issue status as done or true from the rest api, i tried some links and documentations but it failed and not worked, my json data and url is following, please have a look and let me know where i am wrong.
i followed this link to update the issue status as done.
jQuery.ajax({
url :'https://myurl.com/rest/api/latest/issue/10635',
type: 'PUT',
beforeSend : function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + 'QXNjiYIklOZvcxlxhZ3NodXNldA==');
},
data: JSON.stringify({"status":{"id":"10635","name":"done"}}}),
dataType: 'json',
contentType:'application/json; charset=utf8',
success: function(data){
console.log(data);
}
})
My json is following
{"status":{"id":"10635","name":"done"}}}
i checked the response on fiddler but i got the following error in fiddler response.
{"errorMessages":["one of 'fields' or 'update' required"],"errors":{}}
after that i changed my json data as following and that also not worked,
{"update":{"status":{"id":"10635","name":"done"}}}
and then i seen the error in fiddle as following.
{"errorMessages":["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream#19d2e36; line: 1, column: 12] (through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]}
it killed my 2.5 hours approx, kindly help where i am wrong ?
I was using the wrong approach, for setting the status as done of the Jira issue you have to send two requests to the server (1) Get request which will return the transaction id for the issue. (2) Post request to the server with the help of transaction id you can make the issue as done, i try to demonstrate following.
(1) Send Get Request to the JIRA server with following url (same url will use for POST request).
https://mycompany.com/rest/api/2/issue/{issueidORkey}/transitions?expand=expand.fields
it will return the following type of details into json mode.
{
"expand": "transitions",
"transitions": [
{
"id": "25",
"name": "Start Progress",
"to": {
"self": "https://mycompany.com/rest/api/2/status/3",
"description": "This issue is being actively worked on at the moment by the assignee.",
"iconUrl": "https://mycomapny.com/images/icons/statuses/inprogress.png",
"name": "In Progress",
"id": "3",
"statusCategory": {
"self": "https://mycompany.com/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
}
}
}
as above you can see there is the transition --> id=25, this id will be use for the POST request, for me i created the JSON as following and now
(2) send the POST request through same url as i used above.
{
"update": {
"comment": [{
"add": {
"body": "Comment body"
}
}]
},
"fields": {},
"transition": {
"id": "25"
}
}
for me fields property was not required so i am able to update the issue status as done.
:)
Related
I am creating a Azure function http trigger post method where i am receiving json data in body and then i am mapping it and store it in blob storage.It is working well in local but in Azure environment it gets failed.In application insight i have created a custom log events where i see the error is due to counting of json dynamic data.
error:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
Cannot perform runtime binding on a null reference
Here is my sample code
public async Task Run([ HttpTrigger( AuthorizationLevel.Anonymous, "get", "post", Route = null) ] HttpRequest req )
{
try
{
StringBuilder csveventcontent = new StringBuilder();
string requestBody =
await new StreamReader(req.Body).ReadToEndAsync();
dynamic json = JsonConvert.DeserializeObject(requestBody);
int eventsDataloopCount = json["body"]["data"].Count;
Sample http reqst data
{
"functionName": "abc",
"method": "POST",
"headers": {},
"body": {
"data": [
{
"item1": 1,
"created_at": "2021-02-10T21:07:08Z",
"item2":"b",
"item3": -1,
"item4": null,
"item5": null,
"arrayitem": {
"item1": "1",
"item2": "2",
"item3": "3"
},
"data": {},
"arrayevent": {
"abc": 1
}
},
I can see there are two issues in your JSON.
It should be "item2": "b" not "item2": b.
There are two keys for "item1" for value "1" and "3". so you have to remove one of them.
So my suggestion is to first fix the JSON and then proceed further.
Got the issue, you should use json["body"]["data"].Count not json["body"]["data"].count. Newtonsoft.Json.Linq.JArray has no count method.
I am trying to automate some processes in our organization and part of that includes being able to transfer a repository in one of our azure devops organizations to another (think of it as a dev organization and a test organization so we are pushing from dev to test)
Through the API https://learn.microsoft.com/en-us/rest/api/azure/devops/git/import%20requests/create?view=azure-devops-rest-6.0 I am trying to create an import request.
Here's where I'm stumped and the documentation doesn't say much about.
If I use a request body like in the example:
{
"parameters": {
"gitSource": {
"url": "https://github.com/Microsoft/vsts-agent.git"
}
}
}
The import request works fine as long as I'm importing to an empty repository. However I need to be able to sync an existing repository.
[There's a property in the documentation called overwrite that seems to be for this purpose][1]: https://i.stack.imgur.com/ezCB3.png
The only problem is when I add this to the request body and set to true
{
"parameters": {
"gitSource": {
"url": "https://github.com/Microsoft/vsts-agent.git",
"overwrite": true
}
}
}
I get bad request message saying invalid combination of parameters
If I set this to false it works if I'm trying to import to an empty repository. If the repository isn't empty I get an error saying I can only import into an empty repo.
So it seems this property is meant for exactly what I'm doing, however it seems there are more parameters needed when that property is set to true in order to make the request succeed, but the documentation is lacking in this area.
Any help would be much appreciated
I suspect that overwrite = true is giving you error because there may be some permission issues or Auth problem in your latter repo.
Alternatively, you can fork your parent repository and sync only the provided refs:
CURL:
POST https://dev.azure.com/{organization}/_apis/git/repositories?sourceRef=users/heads/master&api-version=6.0
Request Body:
{
"name": "forkRepositoryWithOnlySourceRef",
"project": {
"id": "3b046b6a-d070-4cd5-ad59-2eace5d05b90"
},
"parentRepository": {
"id": "76b510af-7910-4a96-9902-b978d6226bee"
}
}
Sample response (HTTP 201):
{
"id": "29230c30-9125-459b-a3f6-ffab329053bd",
"name": "forkRepositoryWithOnlySourceRef",
"url": "https://dev.azure.com/fabrikam/MyFirstProject/_apis/git/repositories/29230c30-9125-459b-a3f6-ffab329053bd",
"project": {
"id": "3b046b6a-d070-4cd5-ad59-2eace5d05b90",
"name": "MyFirstProject",
"url": "https://dev.azure.com/fabrikam/_apis/projects/3b046b6a-d070-4cd5-ad59-2eace5d05b90",
"state": "wellFormed",
"revision": 12,
"visibility": "private",
"defaultTeamImageUrl": null
},
"size": 0,
"remoteUrl": "https://dev.azure.com/fabrikam/MyFirstProject/_git/forkRepositoryWithOnlySourceRef",
"sshUrl": "git#ssh.dev.azure.com:v3/fabrikam/MyFirstProject/forkRepositoryWithOnlySourceRef",
"isFork": true,
"_links": {
"forkSyncOperation": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/29230c30-9125-459b-a3f6-ffab329053bd/forkSyncRequests/7"
}
}
}
I want to be able approve a moderation request through Graph API. I have referred to Approve Moderation Request. I was not able to get it to work. Although, there is a PowerShell script available at EWS Managed API and Powershell How-To Series Part 11 Moderation that I managed to get working.
This is not a supported feature in Graph API and therefore requires some tinkering. I would like some guidance on how to do this.
This is the JSON I am sending to the end point https://graph.microsoft.com/v1.0/me/sendMail
{
"message": {
"subject": "Approve:MessageName"
},
"toRecipients": [
{
"emailAddress": {
"name": "Microsoft Exchange",
"address": "systemmailbox#domain.com"
}
}
],
"singleValueExtendedProperties": [
{
"id": "Binary 0x31",
"value": "7gd324tgcxJJNkEuxk2DP2Xk+M/fxw=="
},
{
"id": "String 0x001A",
"value": "IPM.Note.Microsoft.Approval.Reply.Approve"
}
]
}
This is the response I receive
{
"error": {
"code": "ErrorInvalidRecipients",
"message": "At least one recipient isn't valid., A message can't be sent because it contains no recipients.",
"innerError": {
"date": "2020-08-19T23:40:07",
"request-id": "7g5h732v-6uhb-3212-b6f1-43f6eeb139wq"
}
}
}
Any help would be appreciated.
You have a syntax issue in your Json request eg look closely at the Message after subject you have a closing } which means the only thing your posting is the subject of the message it should be
{
"message": {
"subject": "Approve:MessageName",
"toRecipients": [
{
"emailAddress": {
"name": "Microsoft Exchange",
"address": "address.com"
}
}
],
"singleValueExtendedProperties": [
{
"id": "Binary 0x31",
"value": "7gd324tgcxJJNkEuxk2DP2Xk+M/fxw=="
},
{
"id": "String 0x001A",
"value": "IPM.Note.Microsoft.Approval.Reply.Approve"
}
]
}
}
Additional
To make this work correctly you need to get the Approval Request from an app rovers mailbox for the Graph a query like this
https://graph.microsoft.com/v1.0/me/mailFolders('Inbox')/messages?$filter=singleValueExtendedProperties/any(ep:ep/id eq 'String 0x001a' and ep/value eq 'IPM.Note.Microsoft.Approval.Request')&$expand=singleValueExtendedProperties($filter%3D(Id eq 'Binary 0x0031') or (Id eq 'String 0x0E1D'))
This will give you the report tag 0x0031 value that you need to use in your Send and you also need to include the Approve Verb Extended property
{
id = "String {00062008-0000-0000-C000-000000000046} Id 0x8524"
value = "Approve"
}
I converted the script from my blog which I'll get around to posting this week that just approves the last email in a Mailbox you can look at it https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/Moderation.ps1 (look at Invoke-ApproveModerationRequest)
Working with Azure Machine Learning - Text Analytics REST api, located here. Requires sending a payload to the server via POST. I am trying to get similar results as I do with IBM watson
Here is what I tried in console app, here's core code:
static IRestResponse GetResp(string url, string key, string jsonText) {
IRestClient client = new RestClient(url);
IRestRequest request = new RestRequest() { RequestFormat = DataFormat.Json };
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Ocp-Apim-Subscription-Key", key);
IRestResponse response = client.ExecuteAsPost(request, "POST");
}
// Here the code that serializes the object to look precisely like body advertised calls it:
string json = JsonConvert.SerializeObject(documents);
IRestResponse resp = GetResponse("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases", TaxonomyGlueKey, json);
message body from serializing "documents" is:
{
"documents": [
{
"language": "en",
"id": "4",
"text": "Lateral internal sphincterotomy and fissurectomy"
},
{
"language": "en",
"id": "5",
"text": "Fissurectomy and Botox injection"
}
]}
I get Bad Request errors. I've verified my request is sent and passing authentication (it had failed prior). I have tried many variations on this as well.
I am able to try my request body out and it works properly when copying text from debug variable directly to the body provided by Azure:
https://westus.dev.cognitive.microsoft.com/docs/services/TextAnalytics.V2.0/operations/56f30ceeeda5650db055a3c6/console
If I test using the above I get the response expected, status 200:
Transfer-Encoding: chunked
x-aml-ta-request-id: c4ea9fff-8068-42a3-99c4-68717acddcf5
X-Content-Type-Options: nosniff
apim-request-id: e5eb593b-96a3-4806-9143-1d83424569be
Date: Thu, 21 Jul 2016 14:14:44 GMT
Content-Type: application/json; charset=utf-8
{
"documents": [
{
"keyPhrases": [
"fissurectomy"
],
"id": "4"
},
{
"keyPhrases": [
"Botox injection"
],
"id": "5"
}
],
"errors": []
}
I was working with JQuery and REST API for the Sentiment Analysis. I had received the same error as you have received.
I managed to get it working by providing the JSON-serialized version of the input as the request body.
Here is the working code-
$(function() {
var params ={
"documents": [
{
"language": "en",
"id": "1",
"text": "this is AWESOME!"
}
]
};
$.ajax({
url: "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?" + $.param( params );,
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","<your subscription key here>");
xhrObj.setRequestHeader("Accept","application/json");
},
type: "POST",
// Request body
data: JSON.stringify(params)
})
.done(function(data) {
alert("Sentiment score is " + data.documents[0].score);
})
.fail(function() {
alert("error");
});
});
#Makk, it looks like you are using C# code.
In the text analytics documentation, there is a quick-start section that has running C# sample that should work for you.
I am trying to get jStree (jQuery tree control) working in my ASP.NET (C#) page. I'm using a WCF service to return a test string of JSON.
Opening the WCF service URL in the browser works fine - If I go to the URL (http://localhost/website/GetTree) I get the JSON (looks just like opening XML in browser, with syntax highlighting and collapsible tab thingys)
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">{"attr": { "id": 2, "rel": "default" }, "data": "A node", "children": [ { "data": "Child 1", "attr": { "id": 43, "rel": "document" } }, {"data": "Child 2", "attr": { "id": 25, "rel": "document"} } ] }</string>
jstree itself works fine - if I put the same JSON in "manually" in my document.ready like so:
"json_data": {
"data":
[{
"attr": { "id": 2, "rel": "default" },
"data": "A node",
"children":
[{
"data": "Child 1", "attr": { "id": 43, "rel": "document" }
},{
"data": "Child 2", "attr": { "id": 25, "rel": "document"}
}]},{
"attr": { "id": "li.node.id", "rel": "document" },
"data": {
"title": "Long format demo",
"attr": { "href": "#" }
}}]},
I get the tree appearing with those nodes in it.
But, combining the two:
"json_data": {
"ajax": {
"url": "GetTree",
"data": function (n) {
return {
};
}
}
},
...fails. The jstree shows up as just the word "loading..." and an animated loading gif. And it does hit a breakpoint inside the WCF service method (just like browsing to it does).
A: An idea where I've gone wrong?
B: An idea how I find out what's wrong? jstree documentation was no help, and I can't see any error messages.
Thanks.
Update: solved
Thanks to Mikael Eliasson for pointing out that my service must be returning XML and not JSON.
WCF service code-behind:
// this responseformat bit below fixed it
[WebGet(UriTemplate = "GetTesto", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
public Testo GetTesto()
{
return new Testo();
}
Might be a stupid question but you have enabled the json_data plugin, right? As akonsu said inspecting the response in a tool like Firebug.
It seems to me that you WCF service is not returning JSON but rather a XML response. I think that is your problem. The best thing is probably to change the service to return JSON. If you can't do that you could add the success function and transform the string to JSON with the function $.parseJSON()
I hope that helps. But again you really should start using Firebug or something similar because there are lot of times when you need to inspect the response or debug javascript.