0

I am working on a prototype for using Smartsheets webhooks to notify an ASP.Net/WebApi endpoint when changes occur. While I understand the concepts, I have not been able to find a specific example of the structure that Smartsheets will be passing to the callback endpoint.

I suspect that it is a Json string and that I should be able to define a string parameter in the controller method to accept it like this:

public HttpStatusCodeResult Put([FromBody]string payload)
{ ... } 

but I am not clear on what the parameter should be named (or even if it matters what it is named).

Can someone provide:

  • An example of a Smartsheets webhook callback controller method
  • Clarification on what the payload parameter type and name should be

2 Answers2

1

I finally figured this one out. I used the Json response structure to create a similar class in C#, then used that structure as the incoming parameter type:

  public class Payload
    {
        public int PayloadId { get; set; }
        public Guid Nonce { get; set; }
        public string Timestamp { get; set; }
        public string WebhookId { get; set; }
        public string Scope { get; set; }

        public string ScopeObjectId { get; set; }
        public virtual List<PayloadEvent> Events { get; set; }
    }

    public class PayloadEvent
    {
        public int PayloadEventId { get; set; }
        public string ObjectType { get; set; }
        public string EventType { get; set; }

        [JsonProperty(PropertyName = "Id")]
        public string EventId { get; set; }

        public string UserId { get; set; }

        public string Timestamp { get; set; }
    }

Controller code:

[HttpPost]
public void Post([FromBody] Payload value)
{
    ...
}

It is also possible to just use dynamic as the parameter type, but that doesn't take advantage of any compiler checks downstream so I opted for more structure by defining the classes.

0

I can help with the structure of the Webhook callback. Once you create and verify the webhook, the events will be posted to your callback endpoint in following format:

{
  "nonce": "4b2ed20d-6f00-4b0c-8fac-082182aa9aac",
  "timestamp": "2015-10-27T17:04:23.795+0000",
  "webhookId": 4503604829677444,
  "scope": "sheet",
  "scopeObjectId": 4509506114742148,
  "events": [
    {
      "objectType": "sheet",
      "eventType": "updated",
      "id": 4509506114742148,
      "userId": 9007194052434043,
      "timestamp": "2015-10-27T17:03:15.000+0000"
    },
    {
      "objectType": "row",
      "eventType": "created",
      "id": 7129509179746180,
      "userId": 9007194052434043,
      "timestamp": "2015-10-27T17:03:15.000+0000"
    }
  ]
}

The events array will be in the body of the POST.

stmcallister
  • 1,682
  • 1
  • 12
  • 21