Dynatrace API
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RequestToken invalid when contains + symbol

Celine
Newcomer

Hi,

I use the grail service api to run DQL query from java client.
When i do a POST on 

platform/storage/query/v1/query:execute

I received a requestToken that I reuse in a query GET platform/storage/query/v1/query:poll (while state is Running).
It works excepted when the requestToken received contains a "+".
I got the error "The supplied request-token parameter (xxxxxxxxxxx xxxxxx==) is invalid".
I try to encode it but I got an error too: The supplied request-token parameter (xxxxxxxxxxx%2Bxxxxxx==) is invalid.
How to fix it?

3 REPLIES 3

MaximilianoML
Champion

Hello @Celine ,

This usually happens because the request-token is being treated as a URL query parameter, and in query strings a + is often interpreted as a space if it isn’t handled correctly.

So when Dynatrace returns a token containing +, you should make sure the token is passed as a properly encoded query parameter in the query:poll call, and that it is encoded only once.

What to check on the Java side:

  • Do not build the URL by simple string concatenation
  • Do not send the raw token directly in the URL
  • Do not pre-encode it and then let the HTTP client encode it again

The safest approach is to use a URI/query parameter builder and pass the original token value to it, so the client handles encoding correctly.

In practice, the problem is often this:

  • raw + becomes a space
  • Or %2B gets encoded again and the API receives the wrong value

So the fix is:

  1. keep the original requestToken 
  2. add it as a query parameter with your HTTP client
  3. let the client encode it once

Maybe something like:

URI uri = new URIBuilder(baseUrl + "/platform/storage/query/v1/query:poll")
    .addParameter("request-token", requestToken)
    .build();

I got the same problem when I was making a n8n automation, not with Java ofc, I suffered a little to got the solution 😅 

Let me know if helped, please

Max Lopes

Thank you so much Maximiliano, it's working! 🙂

My pleasure, @Celine !

Max Lopes

Featured Posts