Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Mike Waldron
    REST queryResults Resource/Endpoint Not WorkingAnswered
    Topic posted July 25, 2016 by Mike WaldronGold Medal: 3,500+ Points, tagged REST 
    514 Views, 15 Comments
    Title:
    REST queryResults Resource/Endpoint Not Working
    Content:

    I'm trying to run a ROQL tabular query with the REST queryResults resource/endpoint. According to the documentation, I should be able to do this, but...ain't workin', even when I copy-and-paste the example directly out of the documentation.

    One peculiarity I've noticed is if I hit

    https://mysite.example.com/services/rest/connect/v1.3/queryResults/
    ?query=select id,subject from incidents where id<=10;
    

    (query from the documentation) there's an extraneous space in between the last slash and the question mark...which may be an artifact of the line break. If I leave it, I get a 200 OK...but no results. If I take it out, I get a 400 Bad Request. Neither result is useful.

    I'm trying to do this on Feb '16. Is there a bug in this REST resource, is something missing from the documentation, or is some other thing going on? Anyone dealt with/resolved this before?

    mjw

     

     

     

    Best Comment

    Bastiaan van der Kooij

    The URL encoding should use %20, not + for spaces, just use the exact query I posted, that should work in ARC. ARC itself uses the encoding with plus sings which fails for these rest queries

    Comment

     

    • Dietrik

      Leave out any space where not needed. You can also leave out the last /.

      https://mysite.example.com/services/rest/connect/v1.3/queryResults?query=select id,subject from incidents where id<=10
       

      i don't see any issue with your link, it should always return something, even if the query doesn't return records.

      Do other request functions as expected ?

    • Mike Waldron

      Thanks, Dietrik. I haven't had trouble with any other resources in the REST API other than queryResults. After removing the extraneous space and slash...I'm still getting a 400 Bad Request, running your exact query above. Very strange.

    • Scott Harwell

      Try using 'latest' instead of 1.3 in your URL.  I tested and received the same results as you with 1.3, but latest works.

      https://mysite.custhelp.com/rest/connect/latest/queryResults?query=select id,subject from incidents where id<=10;
      
    • Suresh Thirukoti

      Scott - Its working in 1.3 as well ..i tried the below query

      https://xxxx.custhelp.com/services/rest/connect/v1.3/queryResults/?query=select id,subject from incidents where id<=100000 limit 5

    • Scott Harwell

      Suresh, likely 1.3 is a newer version than supported on the site that he is working on.  Could be a number of things.  But, latest should get him to the newest version that his site supports to use the query.

      Mike...be sure that you haven't omitted the "v" in front of 1.3 either.  You have it in your query, but a typo may be another reason for the 404 error.

    • Mike Waldron

      Yep, I've got the "v" in front of "1.3" I've looked over the URL about a hundred times by now. Also, this is sort of picky, but you know software - it's not a 404 Not Found I'm getting; it's a 400 Bad Request.

      Using "latest" instead of "v1.3" also did not work out. I got the same result. For those of you for whom it's working - what version of OSC are you using? I'm on Feb '16, and I'm starting to wonder if an earlier or later version is maybe providing different results.

    • Scott Harwell

      I'm using 16.5.  But, per the docs " In the February 2016 release, only v1.3 and latest are allowed, both of which currently point to CCOM version 1.3."  So, you should be set.

      How are you sending the request to the server?  A REST test tool?  Are you sure you are using an HTTP GET operation (not POST or PATCH)?

    • Mike Waldron

      I'm using Google's Advanced REST Client (ARC). Every other REST resource has worked fine, so I'm thiiiis close to stumped.

      You may note in this screenshot, ARC suggests "encoding this value before sending it to the server." I did that the first time. The REST API apparently does not URL-decode, and ROQL can't handle e.g. "%20"...so it also breaks if you encode the URL.

       

    • Scott Harwell

      Hmm, I wonder if the fact that the request is coming from Google's servers as opposed to your local client (PC) could be the issue.  Could you use cURL or a tool like Postman to try the request from your end?

      curl -X GET -H "Authorization: Basic XXXXXXXXXXXXXX" -H "Cache-Control: no-cache" "https://site.custhelp.com/services/rest/connect/v1.3/queryResults?query=select%20id,subject%20from%20incidents%20where%20id%3C=10;"
      

    • Bastiaan van der Kooij

      if you just properly encode your query there should be no problem;

      https://mysite.example.com/services/rest/connect/v1.3/queryResults?query=select%20id,subject%20from%20incidents%20where%20id<=10;

      As a test just drop your query first in the browser and hit the request, copy the encoded url and that should just work fine in ARC.

       

    • Mike Waldron

      I get the exact same result when I URL-encode the URL. I haven't tried Postman or cURL yet, but I will.

       

    • Bastiaan van der Kooij

      The URL encoding should use %20, not + for spaces, just use the exact query I posted, that should work in ARC. ARC itself uses the encoding with plus sings which fails for these rest queries

    • Mike Waldron

      That finally fixed the problem. Thank you, Bastiaan! I ASSUMED that ARC's built in "Encode URL" function was working correctly...but not so.

      Wow, that was hard. Thanks to everyone who worked to help me find a solution.

    • Scott Harwell

      Good catch, Bastiaan!  Missed that in the problematic encoded samples had pluses.

    • Suresh Thirukoti

      You rock Bastiaan !!