0
votes

I've been trying to use the following query with the Microsoft graph API:

"groups?$filter=startswith(displayName, '" + term + "')"

So this term's value is taken from an input html:

enter image description here

and through python I'm inserting it to perform the search with the query:

@APP.route('/search')
def search():
    params = request.args.to_dict()
    term = params.get('term')
    queryGroup = "groups?$filter=startswith(displayName, '" + term + "')"
    result = MSGRAPH.get(queryGroup, headers=request_headers()).data

    return flask.render_template('home-page.html', result=result)

When I try looking for an existent group in the Azure AD, as a result I get this:

b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">\r\n<HTML><HEAD><TITLE>Bad Request</TITLE>\r\n<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>\r\n<BODY><h2>Bad Request</h2>\r\n<hr><p>HTTP Error 400. The request is badly formed.</p>\r\n</BODY></HTML>\r\n'

According to Microsoft's Documentation, I see that my query is well structured.

I would like you guys to help me know, what may be failing here?

I'm using v1.0 of the API, and also tried it out with the same version in the graph explorer.(Where it worked out, which is odd for me)

I've been thinking about using the $search parameter, but it does not work for this type of collection (Groups)

The full URI that I'm sending is :

https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName,<here I put the searched value>)

Thanks!

2
Your examples aren't very clear. You are showing the query parameter but not the full URI so it's not clear how the call is actually executing. Can you include an HTTP trace showing what is actually traveling down the wire?Marc LaFleur
@MarcLaFleur Oh, I just updated my question, there you can see the URI that I'm sending.Jplaudir8
According to Bad Request exception, it means that the request is not correct. I assume that term = params.get('term') the value of term is null or empty. You could set term with hard code value and test it again.Tom Sun - MSFT

2 Answers

0
votes

400 means bad request. It could be because of url encoding. Url encode the query string.

Something like

String query = "Extensions($filter=Id eq 'c.i.m.p.server.entities.outlook.Event'";
String url = "https://graph.microsoft.com/v1.0/users/{userId}/calendars/{calendarId}/events?
               $expand=" + URLEncoder.encode(query, StandardCharsets.UTF_8.name());
0
votes

You can change your query string in your Python project first, to confirm if other query condition works well.

And if your project and graph explorer use different user credentials, you maybe need to check the permission again.

All in all, try different query first.