1

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

BlockchainProgrammer
  • 1,333
  • 2
  • 11
  • 30

1 Answers1

2

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
flaxel
  • 2,706
  • 4
  • 9
  • 22
  • 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? – BlockchainProgrammer Aug 23 '20 at 19:15
  • 1
    There are only three [different types](https://api.slack.com/dialogs#elements) for an element of a dialog: text, textarea and select. – flaxel Aug 23 '20 at 19:34
  • 1
    But if you want to use modals, I think the given request cannot work. You can find a nice example in the [documentation](https://api.slack.com/surfaces/modals/using#opening_modals). – flaxel Aug 23 '20 at 20:17
  • 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? – BlockchainProgrammer Aug 24 '20 at 07:22
  • 1
    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](https://pl.kotl.in/dgOSOtxkS) 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](https://api.slack.com/methods/users.list#arg_limit). – flaxel Aug 24 '20 at 10:27
  • thanks. And how do I make the handshake response for the modal to close? Just a Post Request to the response URL? – BlockchainProgrammer Aug 24 '20 at 11:19
  • 1
    I do not know which url you get with the request but in the [documentation](https://api.slack.com/surfaces/modals/using#closing_views) you find a description to close views. – flaxel Aug 24 '20 at 11:27
  • 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. – BlockchainProgrammer Aug 24 '20 at 12:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220357/discussion-between-blockchainprogrammer-and-flaxel). – BlockchainProgrammer Aug 24 '20 at 12:35