Search code examples
c#jsonhttprequestmattermost

I can´t open dialog an mattermost?


When i send a request to mattermost API. I get response error code 400(Bad Request). I am using the language of c #, and this serializing an anonymous class to generate the format.

{ 
    "trigger_id":
         "a2k0eGhveDN3M2dtN2I0Y3c3b3BobXBoZW86bXlubmk3eGg4M2Y3eDhoMThucjE0c3dvb3I6MTU1NTk1MTg3NjAxNjpNRVFDSUU4VDFqYmNSVGswdDZRQVVFU3haZk5URTg3MUhMT1ozK003aWdsQ01nckhBaUFac290SncwMmFSSkRWNEQyTFN0eXpGY0QySFREeVI2SVg3clY3ejVlMjFnPT0=",
               "url": "https://myapi.com/api/values/service",
               "dialog": {
                 "callback_id": "123",
                 "title": "Form Test",
                 "icon_url": "http://www.mattermost.org/wp-content/uploads/2016/04/icon.png",
                 "elements": [
                   {
                     "display_name": "Display Name",
                     "name": "Name",
                     "type": "text",
                    "subtype": "",
                     "default": "default text",
                    "placeholder": "Placeholder",
                    "help_text": "This is a test regular input",
                    "optional": false,
                     "min_length": 0,
                     "max_length": 0,
                    "data_source": "",
                    "options": null
                  },
                   {
                    "display_name": "Email",
                     "name": "youremail@email.com",
                     "type": "text",
                     "subtype": "",
                    "default": "default text",
                     "placeholder": "placeholder@bladekick.com",
                     "help_text": "This is a test regular input",
                 "optional": false,
                  "min_length": 0,
                     "max_length": 0,
                     "data_source": "",
                   "options": null
                  },
                   {
                    "display_name": "Number",
                     "name": "Number",
                     "type": "text",
                     "subtype": "number",
                     "default": "",
                     "placeholder": "",
                     "help_text": "",
                     "optional": false,
                     "min_length": 0,
                     "max_length": 0,
                     "data_source": "",
                     "options": null
                   }
                 ],
                 "submit_label": "Enviar",
                 "notify_on_cancel": false,
                 "state": "Default state"
        }
    }

This is my json that i send Help me please with this error. Attachment Picture Code 400


Solution

  • Well, I solved it. My error was the way I made the HTTP request.

    What I was doing delayed the request and the “trigger_id” expired. Remember that the “trigger_id” has a useful life of 3 seconds.

    My recommendation is to try to use different ways to send the request because the JSON that I send (it's the same as yours) is correct. Another observation from me was that it apparently did not send it properly as an “application / json”