0

When I am trying to execute SOQL using OAuthRestTemplate Rest API with following URL:

https://na98.salesforce.com/services/data/v46.0/queryAll/?q=SELECT+Name+from+Account+where+SAP_ID_UCID__c+=+'1000479'

I am getting below error:

[{"message":"\nSELECT+Name+from+Account+where+SAP_ID_UCID__c+=+'1000479'\n ^\nERROR at Row:1:Column:6\nunexpected token: '+'","errorCode":"MALFORMED_QUERY"}]

And also tried encoding the URL and query param. but no luck

but when I execute the same URL in any rest client like post man, it is giving response.

I am doing any wrong in java ? Please help

  • 2
    What's in your actual code? It looks like you might be supplying the query pre-encoded and then having it be encoded a second time. – David Reed May 24 '19 at 12:45
1

I had exactly the same error and the same scenario: worked in workbench did not work in Java. As suggested above, I removed the manual URL Encoding step. Java seems to be automatically encoding. Here's the final code that worked.

response = client.send(HttpRequest.newBuilder()
                        .uri(UriComponentsBuilder
                                .fromHttpUrl(token.getInstanceUrl())
                                .path(path)
                                .queryParam("q", query)
                                .build()
                                .toUri())
                        .header(HttpHeaders.CONTENT_TYPE, "application/json")
                        .header(HttpHeaders.AUTHORIZATION, "OAuth " + token.getToken())
                        .GET()
                        .build(),
                HttpResponse.BodyHandlers.ofString());

I got it to work by removing the step that was manually encoding the query before building the HTTPRequest.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.