1

I've setup an asp.net MVC web application to capture post request. I've set breakpoints to see what info is coming through. When an interactive button is clicked, my breakpoint is hit but the object has no details. It simply says {Object} when i hover over value. When I use Postman and send a raw JSON body, it displays the JSON. May I ask how am i suppose to process the slack object that is sent?

public void Post(object value)
{
    // breakpoint here
}
Master
  • 2,038
  • 2
  • 27
  • 77

1 Answers1

3

For interactive messages Slack send a standard POST request with a single form-data encoded parameter called payload in the body. This parameter contains the data of the actual request as JSON string.

You can simulate this with Postman by using the following parameters:

  • Request type: POST
  • Header: Content-Type: application/x-www-form-urlencoded
  • Body: form-data, with key=payload and value = JSON string.

So the body is not fully JSON as you assumed, but contains a form parameter with a JSON encoded string. If you change your app accordingly, it will work.

In c# you can access the content of the payload parameter with Request["payload"] (see this answer or details).

Then you still need to decode the JSON string into an object of course. An easy approach is to use JavaScriptSerializer.Deserialize. (see this answer for details and alternative approaches).

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • Hi Erik, what type of application did you create to accept those post request? asp.net mvc as well? I tried and i'm presented with this https://imgur.com/a/ri6Wg – Master Sep 30 '17 at 17:26
  • If that approach does not work, please check out the linked answer on alternative approaches on how to retrieve a POST request with c# – Erik Kalkoken Sep 30 '17 at 18:37
  • Hey, anychance have you accomplished this in .net core? Using framework 4.6 it works fine with Request["payload"], but not a solution for .net core. – Master Oct 18 '17 at 11:28
  • No, but have you checked the answers from the link I posted? – Erik Kalkoken Oct 18 '17 at 12:21
  • By using the required params in the Postman i was able to get the json values but according to Events API documentation they will send Content-Type:application/json. Won't it hurt then? – Harry .Naeem Sep 28 '18 at 11:56
  • yes, Events API works a bit differently. This answer is for Interactive Messages. – Erik Kalkoken Sep 28 '18 at 12:13
  • Any idea how to do it for Events API because i'm stuck at it for two days now and i'm not able to verify my request url. – Harry .Naeem Sep 28 '18 at 12:55
  • sure. please open a question for it and I am happy to help. – Erik Kalkoken Sep 28 '18 at 12:57