简体   繁体   中英

Microsoft Graph API: query not working

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:

在此处输入图片说明

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!

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.

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM