Now I'm trying to set up a webhook in Asana to send me event updates for a particular task on my Asana Project. I am pretty novice so keep that in mind when reading and answering, thanks. This also my first post on here so be easy on me. Here's my code I am running.
WCF that received notify:
public string ReceiveHooks(Stream JSONdataStream)
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
if (headers.AllKeys.Contains("X-Hook-Secret"))
{
var key = headers["X-Hook-Secret"];
WebOperationContext.Current.OutgoingResponse.Headers.Add("X-Hook-Secret", key);
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
}
//Handle Json body
using (var reader = new StreamReader(JSONdataStream))
{
List<AsanaEvent> listEvent = null;
string values = reader.ReadToEnd();
logger.Info("Asana receive hook successful: " + values);
return "true";
}
return "False";
}
My Request to create Webhook:
var client = new RestClient("https://app.asana.com/api/1.0/webhooks");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("authorization", "Bearer 0/<key>");
request.AddParameter("application/x-www-form-urlencoded", "resource=234806314393357&target=https%3A%2F%2Fmywebservice.com%2FWCFService.svc%2FReceiveHooks", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
I can received HookId:
{
"data": {
"id": 235053304,
"target": "https://myservice.com/WCFService.svc/ReceiveHooks",
"active": true,
"created_at": "2016-12-22T16:02:29.899Z",
"last_failure_at": null,
"last_failure_content": "",
"last_success_at": null,
"resource": {
"id": 2349951,
"name": "My Task Name"
}
}
}
But when I try to get webhook by Id I got error message:
"message": "webhook: Unknown object: 235053304"
Do anyone have any clue on this error message? I assume that the code to do handshake and handle received hook are in same place.?
Many Thanks