How to add a comments to jira issue using rest api - jira-rest-api

Refered AnotherJiraClient code found in nuget package
Refered this
https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Add+Comment
to add a comment.
var request = new RestRequest()
{
Resource = ResourceUrls.Comment(),
RequestFormat = DataFormat.Json,
Method = Method.POST
};
request.AddBody(addComment);//{"body":"Something"}
return Execute<BasicIssue>(request, HttpStatusCode.Created);
But always returned with status not found?
How to add comments using Jira REST API?

I figured out what was I mssing in the code. I need to provide the comment as an json object.
library(httr)
library(RJSONIO)
x <- toJSON(list(body = "Adding a new Comment"))
POST("https://xxxxxx.atlassian.net/rest/api/2/issue/{issueIdOrKey}/comment",body = x, authenticate(userid,password, "basic"), add_headers("Content-Type" = "application/json"), verbose())

You should use Jira's REST API to append a comment . See this link https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-add-comments-using-rest-api/qaq-p/571351

Related

Can't use QnAMakerClient to download Qna database content

I'm trying to use nuget Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker to use QnAMakerClient and Knowledgebase.DownloadWithHttpMessagesAsync, but when I try to instantiate Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker() the parameters are the abstract classes, so I don't know how I can use QnAMakerClient to download the contents of Body.QnaDocuments.
Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker.QnAMakerClient z = new Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker.QnAMakerClient(new ServiceClientCredentials(),HttpClient httpClient, bool disposeHttpClient);
var kb = z.Knowledgebase.DownloadWithHttpMessagesAsync("key", "test").Result;
Thanks for your help.
#elise You can find one example on how to download the knowledgebase here.
Essentially:
var client = new QnAMakerClient(new ApiKeyServiceClientCredentials(key)) { Endpoint = endpoint };
// Download the KB
Console.Write("Downloading KB...");
var kbData = await client.Knowledgebase.DownloadAsync(kbId, EnvironmentType.Prod);
Console.WriteLine("KB Downloaded. It has {0} QnAs.", kbData.QnaDocuments.Count);

problem posting embeds in discord.net 2.0

So I have been trying to figure this out but I can't find any sources on discord.net 2.0.0-beta which I am currently using.
My question is how to post an embed in the chat, I know how to build one and what the different things do but when I do the method I used in 1.0 it comes up with an error regarding not being able to convert Discord.EmbedBuilder to Discord.Embed
Any help would be appreciated.
My Code:
var eb = new EmbedBuilder();
EmbedFooterBuilder efb = new EmbedFooterBuilder();
EmbedFieldBuilder ef = new EmbedFieldBuilder();
SocketGuild server = ((SocketGuildChannel)msg.Channel).Guild;
//Incorrect use
if (parameters.Length > 0)
{
await msg.Channel.SendMessageAsync($"**Correct Usage**: `{Syntax}`");
return;
}
eb.Title = server.Name;
eb.Description = "this is a really fancy description";
await msg.Channel.SendMessageAsync("", false, embed: eb);
Just call the Build() method on the EmbedBuilder instance.
There was an implicit conversion from EmbedBuilder -> Embed that was removed in the 2.0 development cycle.
You also can
var embed = new EmbedBuilder();
embed.WithTitle("Normal title");
embed.WithDescription("So cute description");
embed.WithFooter("Wawwww i love stanley");
Context.Channel.SendMessageAsync("", false, embed);

Sending JSON data to rest api

I have started to learn about REST API. So far I have been able to call my REST API post data using the form and also to get values from my REST API. Now I am trying to learn to send my data to my REST API using JSON object. I have been searching on the net and reading on StackOverflow on how to implement it but so far there is no luck. I am looking for some basic code examples where I can get an idea of how it's done. If some could help me with some codes on how to send data to my REST API using JSON and also how to retrieve that JSON data in my REST API it will be very helpful to me in learning REST API(Just the basic codes I hope it shouldn't take much of your time to post some codes). Btw I am using Jersey to implement my REST API. Thanks in Advance :) It really will be helpful to me in understanding sending JSON data to my web service Thanks again :)
The language is JAVA(JAX-RS implemented in Jersey)
While sending data in json request, your request should be in the form of a map (key value pair ). Key should be your attribute name and values as the value for the attribute.
For example if you are trying to find a employee using employeeid the your request should be of the form {data:{"employeeid":"1"}}
Be more specif about which platform you are using to call the RESTservice.
Hope this will help you.
var clientCreateOrder = new RestClient("#######################");
var requestCreateOrder = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
//Use below code for creating and sending dynamic json objects to RESTAPI
object[] purchase_units_arr = new object[1];
purchase_units_arr[0] = new
{
amount = new
{
currency_code = "USD",
value = "100.00"
}
};
var body = new
{
intent = "CAPTURE",
purchase_units = purchase_units_arr,
};
//Serialize Json object
request.AddParameter("undefined", new JavaScriptSerializer().Serialize(body).ToString(), ParameterType.RequestBody);
IRestResponse responseCreateOrder = client.Execute(request);

YouTube API v3.0 VideoReponse and ListRequest class

Using the first example, found here https://developers.google.com/youtube/v3/code_samples/dotnet
for the .Net YouTube 3.0 API, I'm doing something very similar but using a VideoResource object not a SearchResource. Code from the example:
YoutubeService youtube = new YoutubeService(new BaseClientService.Initializer() {
ApiKey = credentials.ApiKey
});
SearchResource.ListRequest listRequest = youtube.Search.List("snippet");
listRequest.Q = CommandLine.RequestUserInput<string>("Search term: ");
listRequest.Order = SearchResource.Order.Relevance;
SearchListResponse searchResponse = listRequest.Fetch();
Notice after setting the fields on the ListRequest object a Fetch() method is called to initialize a SearchListResponse object. However, this Fetch() method does not appear to be part of the API! What gives? Does anyone know how to execute the listrequest so that it returns a ListReponse object?
Instead using listRequest.Fetch(); try to use listRequest.Execute();

Crawl Wikipedia using ASP.NET HttpWebRequest

I am new to Web Crawling, and I am using HttpWebRequest to crawl data from sites.
As of now I was successfully able to crawl and get data from my wordpress site. This data was a simple user profile data. (like name, email, AIM id etc...)
Now as an exercise I want to crawl wikipedia, where I will search using the value entered into textbox at my end and then crawl wikipedia with the search value and get the appropriate title(s) from the search.
Now I have the following doubts/difficulties.
Firstly, is this even possible ? I have heard that wiki has robot.txt setup to block this. Though I have heard this only from a friend and hence not sure.
I am using the same procedure I used earlier, but I am not getting the required results.
Thanks !
Update :
After some explanation and help from #svick, I tried the below code, but still not able to get any value (see last line of code, there I am expecting an html markup of the search result page)
string searchUrl = "http://en.wikipedia.org/w/index.php?search=Wikipedia&title=Special%3ASearch";
var postData = new StringBuilder();
postData.Append("search=" + model.Query);
postData.Append("&");
postData.Append("title" + "Special:Search");
byte[] data2 = Crawler.GetEncodedData(postData.ToString());
var webRequest = (HttpWebRequest)WebRequest.Create(searchUrl);
webRequest.Method = "POST";
webRequest.UserAgent = "Crawling HW (http://yassershaikh.com/contact-me/)";
webRequest.AllowAutoRedirect = false;
ServicePointManager.Expect100Continue = false;
Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(data2, 0, data2.Length);
requestStream.Close();
var responseCsv = (HttpWebResponse)webRequest.GetResponse();
Stream response = responseCsv.GetResponseStream();
// Todo Parsing
var streamReader = new StreamReader(response);
string val = streamReader.ReadToEnd();
// val is empty !! <-- this is my problem !
and here is my GetEncodedData method defination.
public static byte[] GetEncodedData(string postData)
{
var encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
return data;
}
Pls help me on this.
You probably don't need to use HttpWebRequest. Using WebClient (or HttpClient if you're on .Net 4.5) will be much easier for you.
robots.txt doesn't actually block anything. If something doesn't support it (and .Net doesn't support it), it can access anything.
Wikipedia does block requests that don't have their User-Agent header set. And you should use an informative User-Agent string with your contact information.
A better way to access Wikipedia is to use its API, rather than scraping. This way, you will get an answer that's specifically meant to be read by a custom applications, formatted as XML or JSON. There are also dumps containing all information from Wikipedia available for download.
EDIT: The problem with your newly posted code is that your query returns a 302 Moved Temporarily response to the searched article, if it exists. Either remove the line that forbids AllowAutoRedirect, or add &fulltext=Search to your query, which will mean you won't get redirected.