In our Windows application, I am accessing all the comments made to a task and displaying them to the users. They would also like a way to add a comment from our application. I can’t find the exact syntax but I think it’s something like this: “/tasks/{0:Target}/stories”, “POST”. I have no idea what “Target” is.
Yes, thank you, I saw that.
What I need help with, if you know, is how to issue that request from my C#/Windows application. It would be the complement to GetResponse.
We don’t have any examples in C#, but the docs do have a cURL request example for making a comment:
curl -H "Authorization: Bearer <personal_access_token>" \
https://app.asana.com/api/1.0/tasks/1001/stories \
--data-urlencode "text=This is a very nice comment."
@MMOCK I’m using the AsanaNet project as the basis for my communications so I don’t have a simple code fragment I could give you; but I think something like the HTTPClient PostAsync example shown here should do the trick. Let us know how that goes.
So then I realized I just need to fill in the part when data is not blank so I can post my new asana comment. I googled “GetResponse(string uri, string data = “”, string method = “GET”)” to see if I could get back to where I found that, and it led me to c# - How to properly make a http web GET request - Stack Overflow. That gave me the missing block which is simply:
// send data if supplied
if (data != "")
{
byte[] dataBytes = Encoding.UTF8.GetBytes(data);
request.ContentLength = dataBytes.Length;
using (Stream requestBody = request.GetRequestStream())
{
requestBody.Write(dataBytes, 0, dataBytes.Length);
}
}
And I call into it:
private void cmdAddStory_Click(object sender, EventArgs e)
{
string response;
response = GetResponse("https://app.asana.com/api/1.0/tasks/xxxxxx/stories", "text=This is my new comment", "POST");
}
In my response the StatusCode is Created so then I checked asana from the user end and there it is, my new comment!
So thank you, again!
Yes, it’s possible. Specifically, there are two types of stories: system-generated stories that record updates to task information, and user-generated stories, that is, task comments.
You can’t add system-generated stories but you can add comments to tasks. See here for more info: