Given a groupId and authenticated user, how do I check the user's membership and role (owner vs member) in one network call? - microsoft-graph-api

As far as I know, Microsoft Graph lets me query for /groups/{groupid}/members or /groups/{groupid}//owners separately, but not both in one call. Is this possible?
In my context, I know the groupId and the authenticated calling userId. How do I check whether this user belongs to the group and if so, their owner/member role in one network call? Is this possible?

One option to assume would be to expand and include members and owners properties via $expand query option but unfortunately the following query is not supported:
https://graph.microsoft.com/v1.0/groups/{group-id}?$select=owners,members&$expand=owners,members
since max only 1 object is allowed to be expanded per Group resource
JSON batching comes to the rescue here, the following example demonstrates how to retrieve Group members and owners within a single request:
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/groups/{group-id}/members"
},
{
"id": "2",
"method": "GET",
"url": "/groups/{group-id}/owners"
}
]
}

Related

How can I filter calendar events with a specific email address or name using Microsoft graph api and OData?

I'm using the Microsoft graph api to fetch calendar events.
Now I would like to only fetch events where one of the attendees has a specific name or email address.
An example response describing such an event is
{
"subject": "General meeting",
"attendees": [
{
"emailAddress": {
"name": "Peter Pan",
"address": "peter.pan#neverland.org"
}
},
{
"emailAddress": {
"name": "Captain Hook",
"address": "captain.hook#neverland.org"
}
}
]
}
According to Microsofts documentation the likely way to achieve this is using OData and the any operator. However I can't find a way to access nested properties like name and address using query parameters.
I was hoping I could do something like this
https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2022-01-01T00:00:00.000Z&enddatetime=2022-31-01T00:00:00.000Z&$select=attendees,subject&$filter=attendees/any(var:var/emailAddress/address eq 'peter.pan#neverland.org')
but using subparam (emailAddress/address) like that leads to bad request.
If the emailAddress field was just an actual email and not another entity, filtering would work.
https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2022-01-01T00:00:00.000Z&enddatetime=2022-31-01T00:00:00.000Z&$select=attendees,subject&$filter=attendees/any(var:var/emailAddress eq 'peter.pan#neverland.org')
Is it possible to achieve what I want?
According this comment Graph API doesn't support drilling down multiple levels of relationships.

Xero API fetch list of organization (all organization)

I have done OAuth2.0 using PKCE flow in .NET Framework (C# Winforms).
Now I have tokens_response in my hand.
But I'm wondering is it possible to fetch all of the organisation (not only one)?
You can check the organisations (tenants) that you can access with a given token using the /connections endpoint, like this:
GET https://api.xero.com/connections
Authorization: "Bearer " + access_token
Content-Type: application/json
Response:
[
{
"id": "e1eede29-f875-4a5d-8470-17f6a29a88b1",
"authEventId": "d99ecdfe-391d-43d2-b834-17636ba90e8d",
"tenantId": "70784a63-d24b-46a9-a4db-0e70a274b056",
"tenantType": "ORGANISATION",
"tenantName": "Maple Florist",
"createdDateUtc": "2019-07-09T23:40:30.1833130",
"updatedDateUtc": "2020-05-15T01:35:13.8491980"
},
{
"id": "32587c85-a9b3-4306-ac30-b416e8f2c841",
"authEventId": "d0ddcf81-f942-4f4d-b3c7-f98045204db4",
"tenantId": "e0da6937-de07-4a14-adee-37abfac298ce",
"tenantType": "ORGANISATION",
"tenantName": "Adam Demo Company (NZ)",
"createdDateUtc": "2020-03-23T02:24:22.2328510",
"updatedDateUtc": "2020-05-13T09:43:40.7689720"
}
]
If you need more information than the organisations' id and name, you'll need to call the /organisation endpoint individually for each.
The connections endpoint is described more in section 5 on this page of the docs: https://developer.xero.com/documentation/oauth2/auth-flow

OData v4 filter resource by active user

I am working on an OData v4 compliant RESTful API, and have a need to filter a collection of tasks based on the assigned user. It would be useful to be able to handle this based on the active user, without having to explicitly refer to the user ID of the assigned user in the filter expression. Take the following request and response as an example:
GET /Tasks
{
"value": [
{
"Assignee": "user1"
},
{
"Assignee": "user2"
},
{
"Assignee": "user3"
}
]
}
I could do something like /Tasks?$filter=Assignee eq 'user1' but this requires that the consumer keep track of who the active user is. Is there some convention to do this in a more generic way? For example: /Tasks?$filter=Assignee eq $ActiveUser.

Microsoft graph batch requests

I have the following requirement :
create an office 365 unified group
add members to it
add each of the members to the accepted senders list of the group
fetch the following IDS for local storage (sql server)
The group ID
The group's main thread ID
The group's main planner plan ID
The group's main planner bucket ID
Can I batch this using the following : https://developer.microsoft.com/en-us/graph/docs/concepts/json_batching
The way I am doing it, I have a request object (in the JSON batch) for each api request.
Logically, I can't proceed with any of my requests without having created the group. So the first one will be the POST to the groups endpoint.
What I would like is a way for subsequent requests to use the newly created group ID to, for example, add members.
Is that doable in the same batch (same JSON batch object)?
If yes, how?
You can use dependsOn to sequence requests as specific order but it will be easier to run them as separated batches, one after another.
Create group
Add members
...
For adding users in a batch try json like this (replace id's with group and userIds):
`
{
"requests": [
{
"id": "1",
"method": "POST",
"url": "/v1.0/groups/{id}/members/$ref"
"body": {
"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
}
}
{
"id": "2",
"method": "POST",
"url": "/v1.0/groups/{id}/members/$ref"
"body": {
"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
}
}
]
}
`

Get the message ID in the survey monkey response

I am using survey monkey v3 API's to send survey emails. While sending a survey email from one collector, I am sending two different survey messages for the same recipient. However, while collecting the survey responses from survey monkey using the api "/surveys/{id}/responses/bulk", I couldn't find the messageID in it. So I how can I find which response belong to which message of the collector then? Is there a different API that I have to use?
What's the use case for tracking the specific message? You have the recipient_id, and first/last/email fields.
You can get recipient details at /collectors/{collector_id}/recipients/{recipient_id}. There's no way (as far as I can tell) to query for this other than searching your messages with /collectors/{collector_id}/messages/{message_id}/recipients
Generally speaking, when you add recipients to a message, they are shared with the collector. Which specific message was responded to is not really tracked, the tracking ID is the recipient_id with respect to the collector.
If you are interested in message stats (ex. which message gets a better response rate) you can use the message stats endpoint.
With regards to having a different message for say different products, unfortunately the message ID is not tied to a response, but two options are:
1) Use a different collector for each product (not ideal if there is a lot)
2) Use extra fields on the recipient (see example):
Example:
POST /v3/collectors/<collector_id>/messages/<message_id1>/recipients
{
"first_name": "Test",
"last_name": "Tester",
"email": "test#example.com",
"extra_fields": {
"product": "shoes"
}
}
POST /v3/collectors/<collector_id>/messages/<message_id2>/recipients
{
"first_name": "Test",
"last_name": "Tester",
"email": "test#example.com",
"extra_fields": {
"product": "shirts"
}
}
Then when you fetch the responses, you'll get that information in metadata, example:
{
"id": "<response_id>",
"recipient_id": "<recipient_id>",
"collector_id": "<collector_id>",
...
"metadata": {
"contact": {
"product": {
"type": "string",
"value": "shoes"
},
"email": {
"type": "string",
"value": "test#example.com"
}
}
}
}
One thing to watch out for is that the extra fields from the contact do not currently show up in the /responses/bulk endpoint, only individual responses/<id> endpoint. Also with extra fields you can't filter responses where product=shoes or whatnot. Those are some limitations with the current API - but hopefully it can at least be helpful for now.

Resources