Troubleshooting "(400) Bad Request" return from Slack API - 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.

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.

Following Renato's logic, a way of dealing with this in Python is as follows:
"".join(i for i in text if ord(i)<126 and ord(i)>31)
This will remove all non-ASCII characters and line breaks.

Related

Asana - Rest API - Multipart/form image upload times out

I am working on a little tool to upload issues found during development to Asana. I am able to get and use post to create tasks etc, but I am unable to do a proper multipart forum upload.
When I run my image upload post request through an independent perl based cgi script I am getting 200's back and an image saved on my server.
When I target Asana, I get 504 gateway timeouts. I am thinking there must be something strict that the perl script is letting through but I have malformed in my request but I am hard pressed to find it.
Is there a web expert or asana expert out there who might be able to help shed some light on what might be missing.
Note the wireshark capture has an extra field. The Asana docs indicate a task field I have tried with and without that field since it is unclear if the task id encoded in the url satisfies that requirement.
I found the problem!
My boundary= had quotes around the value which was getting through on my cgi / apache setup but not for asana.

Asana returns spurious 500 errors with cryptic messages

I am seeing spurious HTTP 500 errors with cryptic messages. For example, doing a GET using oauth on /projects/28408740055707 I see a response body: {"errors":[{"message":"Server Error","phrase":"24 purple woodchucks wriggle fast"}]}
I've also seen it on GET /tasks/{taskId}/stories and other endpoints as well. Any thoughts on this? Thanks!
When an API call or an action within the Asana application generates a server error we generate a random phrase that corresponds so that we can easily look up logs about the issue later.
If you continue to experience 500 errors when making calls to the API we encourage you to write into api-support#asana.com and reference the error phrase along with the call that you were making so that we can try to fix the issue.
I checked for "24 purple woodchucks wriggle fast" and that specific issue seems to have been solved.

Content encoding error when using linkedin.com/uas/oauth2/authorization

I'm developer working on integration between our product and LinkedIn. It's been decided we use https://www.linkedin.com/uas/oauth2/authorization to authenticate user. I found out the following issue, that I'll explain in detail below.
Positive scenario, everything works as expected:
when using valid client_id, everything is fine. To make everything clear, please see this URL (API key replaced with fake one):
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=VALID_API_KEY&state=b4ac5e2ab5404d6fad2f25521d83e825&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2Fapply-app%2Fpages%2Fsocial-networks%2Flinkedin%2Fauthenticated%3FsiteIdentifier%3DPIUFK026203F3VBLZ6G79V7OU%26token%3Db4ac5e2ab5404d6fad2f25521d83e825
When I remove client_id, everything is also fine and message is displayed (Missing client_id. A valid client_id is required to proceed.)
But when I use invalid client_id in browser I receive Content Encoding Error and http status code 500. URL: https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=invalid_client_id&state=b4ac5e2ab5404d6fad2f25521d83e825&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2Fapply-app%2Fpages%2Fsocial-networks%2Flinkedin%2Fauthenticated%3FsiteIdentifier%3DPIUFK026203F3VBLZ6G79V7OU%26token%3Db4ac5e2ab5404d6fad2f25521d83e825
And the most interesting part goes here: when I fetch same URL using either wget or even java HttpConnection.connect() there result is different: HTTP status code 200 and html response. But when I started to analyze given output, I noticed that is ends up unexpectedly after <ul class="permissions, so it must me error in your code, that requires fixing.
I reported that, because it's quite inconvenient to support such behavior. Could you please inform me if you have any plans to fix this? If you need any further details regarding steps to reproduce this issue, please do not hesitate to contact me.
Best regards,
Piotr

Different error responses when using the JIRA REST API in two instances

We have two jira installations at our company. One that we use for our projects and a second one for testing purposes.
I'm working in a project that needs to use the JIRA REST API. For this purpose I'm connecting to our testing instance.
The problem is that while trying out the REST API, I keep getting 400 errors without a single explanation of what went wrong. I just get an HTML with
Your browser sent a request that this server could not understand
I was a bit desperate and decided to try it into our real JIRA. To my surpirse the same request gave me a different response:
{"errorMessages":[],"errors":{"project":"project is required"}}
In this case, I do get a meaningful error!
I replicated this easily. I would never get a meaningful error from the test instance, but the real one will always give me one.
I cannot keep trying out stuff in our productive JIRA, but I cannot easily continue working without getting meaningful errors. So, what could be wrong in the testing instance? I could not find any configuration about the 'verbosity' of the API responses.
I believe that this error is returned not by JIRA but rather by proxy web server that is part of you production configuration.
I suggest you to compare HTTP headers that are sent with working requests from your browser with headers you pass via curl. Googling for the "Your browser sent a request that this server could not understand" helps too

signalR no element found error message

On pages that I have signalR included I get the following error in firebug:
http://localhost:53604/signalr/signalr/negotiate?_=1352797361490
no element found
everything still works fine but just wanted to see if this will become an issue. thanks
Since you're using Firebug that means you're using Firefox. What transport are you using (if using Fiddler remember to turn Streaming on)? It should be:
1. Long Polling
2. Server Sent Events
3. WebSockets
If the transport is Long Polling then we probably have an issue in the underlying code(Firefox should prioritize WebSockets/SSE before LP).
However, if not then we have a content based issue. So that being said, what type of data are you retrieving from the server? Usually a no element found error comes from invalid markup.
Try stripping out all pieces of your application and see if you still get this error. AKA just a $.connection.hub.start().

Resources