Search code examples
slack-api

Troubleshooting "(400) Bad Request" return from Slack API


We've been using slack API for some time, calling it from powershell inside Jenkins, and all was working fine. The messages have formatting and use some links. Recently, some messages stopped to get through, returning (400) Bad Request. If I get the content that failed from logs, and send it manually, the message gets through.

I'm trying to find a way to better troubleshoot what can be wrong with the content or the request, since "Bad Request" is a bit too vague.


Solution

  • In this specific case, I had to remove bit by bit until I found out there was an issue with accentuation and encoding, coming from a text from a git output.

    For future reference, removing the encoding from the message might be a way to troubleshoot this kind of issue, as a way to identify if encoding is what's causing the error.

    The way I did it in powershell was:

    $msg = [Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding("ISO-8859-8").GetBytes($msg))
    

    This generates problems with accentuation, but we're only trying to find if encoding is the issue generating the Bad Request response.