0
votes

I have the following Url graph APi that works as expected in POSTMAN :

https://graph.microsoft.com/v1.0/users?$filter=mail eq 'myuser@hotmail.com'

When I pass theis URl to graph API using groovy script, I get the following error :

java.net.URISyntaxException: Illegal character in query at index 52: https://graph.microsoft.com/v1.0/users/?$filter=mail eq 'myuser@gmail.com'

Here is the sample code how I build the URl :

 String _url =graph_base_user_url + '?\$filter=mail eq ' + "'" + userEmail + "'"

 def http = new HTTPBuilder(java.net.URLEncoder.encode(_url, "UTF-8"))

=====> UPDATED ======= I have apply the following change to my method, I do not have any more the error but what is strange is that return json content all my user instead of a single records. Here is below my method

Thnaks for your reply,

I have a wierd issue, when I try the filter in POSTMAN, it return the correct record based on the provided email

but when I use it in groovy script, it return my all users instead of the filter record,

here is my method below :

public String getUserIdByEmailQuery(String AuthToken,String userEmail){

     String _ret

         def http = new HTTPBuilder(graph_base_user_url +"?")
         http.request(GET) {

             requestContentType = ContentType.JSON
             query:[ $filter:"mail eq '$userEmail'" ]

             headers.'Authorization' = "Bearer " + AuthToken    

             response.success = { resp, json ->
                 //_userId=json["id"].toString()
                 _ret=json
             }

             // user ID not found : error 404
             response.'404' = { resp ->       
                 _ret = 'Not Found'
             }

         }
         _ret
     } 

My method parameter graph_base_user_url is equal to "https://graph.microsoft.com/v1.0/users"

Any idea why it returns all users instead of filter record ? Note that I have cross check the usermail in the parameter ans it is correct and exist

Thanks for help regards

1

1 Answers

0
votes

You should use the HTTPBuilder the idiomatic way:

def http = new HTTPBuilder( graph_base_user_url )
def result = http.get( query:[ $filter:"mail eq '$userEmail'" ] )

UPDATE:

your code is not passing query params properly. It should be:

        def http = new HTTPBuilder(graph_base_user_url)
         http.request(GET) {
             ...
             uri.query = [ $filter:"mail eq '$userEmail'", $select:id ] 
             ...
        }