SlackBot OpenModal Error: "Missing Charset"
Asked Answered
T

1

10

I want to make an api Call via Zapier to open a Modal in Slack.

But I always get the error:

ok: false
error:  invalid_json
warning:    missing_charset
response_metadata:
warnings:
1:  missing_charset

This is my Request Body:

{
"token":"XXXXXXXXX",
"trigger_id":"XXXXXXXXXX",
"dialog": {
  "callback_id": "projekt-verantwortliche",
  "title": "Projektverantwortliche auswählen",
  "submit_label": "Request",
  "state": "Limo",
  "elements": [
    {
      "type": "users_select",
      "action_id": "projekt-projektleiter",
      "placeholder": {
         "type":"plain_text",
         "text":"Projektleiter auswählen"
        },
    },
     {
      "type": "users_select",
      "action_id":"projekt-berater",
      "placeholder": {
         "type":"plain_text",
         "text":"Berater auswählen"
        }
    }
  ]
}
}

What am I doing wrong?

Here a Screenshot of the whole call: enter image description here

Trumpet answered 23/8, 2020 at 17:29 Comment(0)
M
21

The solution can be found in this documentation:

The JSON you've included in your POST body cannot be parsed. This might be because it's actually not JSON, or perhaps you did not correctly set your HTTP Content-type header. Make sure your JSON attribute keys are strings wrapped with double-quote (") characters.

You only need to remove one comma, then it should work:

{
   "token":"XXXXXXXXX",
   "trigger_id":"XXXXXXXXXX",
   "dialog":{
      "callback_id":"projekt-verantwortliche",
      "title":"Projektverantwortliche auswählen",
      "submit_label":"Request",
      "state":"Limo",
      "elements":[
         {
            "type":"users_select",
            "action_id":"projekt-projektleiter",
            "placeholder":{
               "type":"plain_text",
               "text":"Projektleiter auswählen"
            }
         },
         {
            "type":"users_select",
            "action_id":"projekt-berater",
            "placeholder":{
               "type":"plain_text",
               "text":"Berater auswählen"
            }
         }
      ]
   }
}

You can remove the warning missing_charset if you set the charset for the content-type header. For example:

Content-type: application/json; charset=utf-8
Mcspadden answered 23/8, 2020 at 19:0 Comment(9)
Thank you! Now I get another error: [ERROR] Element 0 has an invalid type. Is it not possible to use the type "users_select" in a modal?Trumpet
There are only three different types for an element of a dialog: text, textarea and select.Mcspadden
But if you want to use modals, I think the given request cannot work. You can find a nice example in the documentation.Mcspadden
thank you, now everything is working! Now I got one more question. When I create the message with the modal, I want to add some additional Data to use as a default value in the dialog. For example an ID for a Project. This should be changeable for each new message / dialog. How can I store that Information to use it later on with the dialog ect?Trumpet
I do not think that this can be used with the request. You have to put the logic into your own code. Then you can for example write the following code in Kotlin to use the ID in the request: val id = data.id ?: default_id. There are only some default values from Slack, e.g. users.list:limit = 0.Mcspadden
thanks. And how do I make the handshake response for the modal to close? Just a Post Request to the response URL?Trumpet
I do not know which url you get with the request but in the documentation you find a description to close views.Mcspadden
Thanks @flaxel, actually I don't understand it. i think first of all that I have to send a handshake request back to the response URL in the payload with a message. But this doesn't seem to work.Trumpet
Let us continue this discussion in chat.Trumpet

© 2022 - 2024 — McMap. All rights reserved.