Is there a way to return the count of all contacts in Microsoft Graph?
At the moment I am using the https://graph.microsoft.com/v1.0/me/contacts endpoint to return a paginated list of contacts but I would like to know before I begin how long it's going to take to sort through them all.
Having a count return before-hand would be very useful here. I can't find this anywhere in the docs though.
Typically, the $count segment at the end should provide the collection count (if the service supports it). In this instance however, I see a value of -1 being returned upon GET https://graph.microsoft.com/v1.0/me/contacts/$count.
When I make this call via Graph Explorer
https://graph.microsoft.com/v1.0/me/Contacts/$count
I get the following result,
cache-control: private
client-request-id: 9ff7a409-b3d5-4123-b0ad-aeb267ca0ad1
content-type: text/plain; charset=utf-8
request-id: 9ff7a409-b3d5-4123-b0ad-aeb267ca0ad1
4
So, it seems to work for me.
In 2022 the current graph Api want you to request count as shown below
https://graph.microsoft.com/v1.0/me/Contacts?$count=true
Which returns
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('7c5ad5-af40-41a4-88a3-a0a37971d16f')/contacts",
"#odata.count": 0,
"value": []
}
Related
I want to filter my tasks which are currently active(not completed). I am using microsoft graph api. I get all my tasks and I found that if I mark task complete it is adding date to completedDateTime property. If task is not completed then it's completedDateTime is null. so I try to get task which has completedDateTime eq null but it is not working. so is there any why to check my active task which are not completed?
I have user v1.0 and beta both none of them are working. After lot of struggle get https://github.com/microsoftgraph/microsoft-graph-docs/issues/239 link which says that null check is possible with beta I tried it and it is working. but null check is not working with my query.
Query where null check working:
GET https://graph.microsoft.com/beta/users?$count=true&$select=id,displayName,surname&$filter=surname eq null
Content-type: application/json
ConsistencyLevel : eventual
Authorization: Bearer {{access_token}}
My query where null check not working:
GET https://graph.microsoft.com/beta/me/planner/tasks?$count=true&$select=planId,title,completedDateTime&$filter=completedDateTime eq null
Content-type: application/json
ConsistencyLevel : eventual
Authorization: Bearer {{access_token}}
I have also tried with percentComplete parameter. If it is 100 means task is completed but it also not working.
GET https://graph.microsoft.com/beta/me/planner/tasks?$count=true&$select=planId,title,percentComplete,completedDateTime&$filter= percentComplete ne 100
Content-type: application/json
ConsistencyLevel : eventual
Authorization: Bearer {{access_token}}
According this filtering is not supported and unfortunately it is not described in the documentation which properties support filtering.
I have tested filtering and it is not possible to filter tasks by any property. It always returns all records.
Similar issue:
GitHub
Microsoft Q&A
I'm using python to make calls to the Graph API regarding planner and tasks. whenever I use PATCH to try and update the task I get a 204 response back and the task remains unchanged. According to Microsoft's documentation here, this request should always return either a 200, or a 400 level error.
I have tried changing the data that I send to the server, to change the title rather than the dates, however I get the same 204 response no matter what data I send or what field I attempt to change. I have no problem making other graph calls like updating files in One Drive or getting data about a user
def SetDates(task):
'''Update planner to match the start date and due date of the passed in task'''
tid = task["id"]
start = task["startDateTime"]
end = task["dueDateTime"]
newDates = {"dueDateTime": end,"startDateTime": start}
etag = task["#odata.etag"]
session.headers.update({'If-Match':etag})
response = session.patch(f"https://graph.microsoft.com/v1.0/planner/tasks/{tid}", data = newDates)
session.headers.pop('If-Match')
print(task["title"] + " Has been scheduled")
Based on the documentation I expect this to return a status code of 200, and for the response to contain the data of the task that was updated, and for the change to actually be applied to the task.
By default, PATCH requests return an empty response with 204 return code. To get the data updated data back, you should send "Prefer" HTTP header with value "return=representation".
PATCH https://graph.microsoft.com/v1.0/planner/tasks/{task-id}
Content-type: application/json
Content-length: 247
If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="
Prefer: return=representation
I have finally figured this out.
#Tarken Sevilmis mentioned that in order to get a 200 response from a PATCH request you need to add
Prefer: return=representation
to your request. In my case the reason that my changes weren't being applied was because I hadn't set the content type in the header. The Graph API didn't give an error, but this seems to have been the cause of the issue. Once I set the content type to application/json it gave a proper error indication that the values I gave in the body weren't being read correctly, and I realized that I forgot to parse them to JSON.
Once you set the content headers appropriately and make sure to convert your data to proper JSON everything should work as intended
When attempting to the list the drives for a SharePoint site, I recently began receiving a Microsoft.SharePoint.Client.UnknownError response.
The request and response is as follows:
Request:
https://graph.microsoft.com/v1.0/sites/<site_id>/drives?select=*,system
Response:
request-id: 050894cc-a435-498a-ae0a-ead3d46924f9
client-request-id: 050894cc-a435-498a-ae0a-ead3d46924f9
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"East US","Slice":"SliceB","Ring":"NA","ScaleUnit":"000","Host":"AGSFE_IN_21","ADSiteName":"EST"}}
{
"error":{
"code":"-1, Microsoft.SharePoint.Client.UnknownError",
"message":"Unknown Error",
"innerError":{
"request-id":"050894cc-a435-498a-ae0a-ead3d46924f9",
"date":"2017-12-06T12:38:44"
}
}
}
The same call was working earlier this week without any changes on my end.
I found a few posts from about a month ago that indicate this is possibly a regression on the MS side of things.
Microsoft Graph Exception code -1 starting this week
Microsoft Graph API for SharePoint in Python: Microsoft.SharePoint.Client.UnknownError
MS Graph API Unknown Error when trying to get folder's children
Is this a indeed a regression on the MS side? Is it a change in API behavior that I need to adjust for?
This was indeed a regression that hit a limited number of scenarios. We've since fixed it so you shouldn't see the unexpected behavior any more.
I'm having problems using the server-side paging, utilizing the #odata.nextlink to fetch the next page of data from Microsoft Graph, based on the information in this page. I'm using raw GETs, with the authorization token set in the header (ie, I'm not using a language API, I'm trying this from Powershell using curl). I've scrubbed sensitive data from the following snippets, replacing them with x's, but hopefully the problematic info comes across.
For the first GET, I query with
https://graph.microsoft.com/beta/drives/b!Gxxxxx-xxxxxxge/root:/ReallyBigFolder:/children?top=200
and I get a response with 200 items, as expected. The #odata.nextlink field in this response is
https://graph.microsoft.com/beta/drives/b!Gxxxxx-xxxxxxge/root/children?top=200&$skiptoken=Paged%3dTRUE%26p_SortBehavior%3d0%26p_FileLeafRef%3d279%252ezip%26p_ID%3d208%26p_FileDirRef%3dMaintenance%2520Department%252fReallyBigFolder%26RootFolder%3dMaintenance%2520Department%252fReallyBigFolder
For the examples in the Microsoft Graph documentation linked above, the $skiptoken=... part has random-looking numbers, but mine has $skiptoken=Paged=TRUE&etc. Perhaps the API has changed the response since the documentation was written, or mine is completely incorrect.
My understanding from the documentation is that I should be able to use this URL as an opaque value, and GET it from the Graph API (with auth token of course) without modification. However, when I do this, the response is
{"#odata.context":"https://graph.microsoft.com/beta/$metadata#drives('b%21Gxxxxx-xxxxxxge')/root/children","value":[]}
Where I'm expecting to get another 200 files listed, there are no files returned at all, and it appears the path is gone, pointing to the root rather than the subfolder like it should have been.
I've also tried this in Graph Explorer with both the /beta and /v1.0 endpoints, and it fails in the same way there as well.
Where am I going wrong?
Edit with details for debugging: Note: Graph Explorer doesn't seem to display the Date field from headers, so I'm using Postman Chrome Plugin for these values.
First GET request is to
beta/drives/b!xxx-xxxge/root:/Really%20Big%20Folder/ReallyBigFolder:/children
With response headers
Cache-Control →private
Content-Encoding →gzip
Content-Type →application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Date →Fri, 26 May 2017 19:07:54 GMT
Duration →2033.3889
OData-Version →4.0
Transfer-Encoding →chunked
Vary →Accept-Encoding
client-request-id →6faf5d1d-a291-410a-b269-f4667187d7cb
request-id →6faf5d1d-a291-410a-b269-f4667187d7cb
x-ms-ags-diagnostic →{"ServerInfo":{"DataCenter":"North Central US","Slice":"SliceB","ScaleUnit":"002","Host":"AGSFE_IN_11","ADSiteName":"CHI"}}
and nextLink (obfuscated slightly for security)
https://graph.microsoft.com/beta/drives/b!xxx-xxxge/root/children?$skiptoken=Paged%3dTRUE%26p_SortBehavior%3d0%26p_FileLeafRef%3d279%252ezip%26p_ID%3d208%26p_FileDirRef%3dGSH%2520Test%252fMaintenance%2520Department%252fReally%2520Big%2520Folder%252fReallyBigFolder%26RootFolder%3d%252fGSH%2520Test%252fMaintenance%2520Department%252fReally%2520Big%2520Folder%252fReallyBigFolder
Following the nextLink produces headers (unchanged headers omitted):
Date →Fri, 26 May 2017 19:15:17 GMT
Duration →512.9537
client-request-id →6ba61712-a423-4bc8-9376-cc62bf854329
request-id →6ba61712-a423-4bc8-9376-cc62bf854329
x-ms-ags-diagnostic →{"ServerInfo":{"DataCenter":"North Central US","Slice":"SliceA","ScaleUnit":"001","Host":"AGSFE_IN_7","ADSiteName":"CHI"}}
and resulting body:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#drives('b%21xxxx-xxxxge')/root/children",
"value": []
}
You are correct that the nextLink should be an opaque URL that returns you the next set of results. The format of that string may change over time, so you should not try to parse or otherwise interpret the string, but the usage should be the same.
The response that you are getting back is consistent with an empty result -- meaning that there are no additional files to list.
How many results do you have in ReallyBigFolder? What happens if you set top to a different value (say, 5? 1000?)
Note that the #odata.context describes the result, but is not necessarily the same as the request URL. Is the #odata.context that you get back from nextLink different than that you got back from the initial request? It should be the same...
I am trying to find out how to deep insert in odata v4. Odata v4 specification says that deep insert is possible. But I have tried it in several ways but unable to find out the solution. Whenever I am trying to post an entity with its navigation data, it is being received null on server side.
Anybody has any idea on this. Thanks
I don't know what service side do you use. However, Web API OData supports to post an entity with its navigation property.
For example, you have a Post method in your controller:
[HttpPost]
public IHttpActionResult Post(Customer customer)
{
int key = _customers.Count();
customer.Id = key + 1;
_customers.Add(customer);
return Created(customer);
}
You can issue a POST request on http://..../odata/Customers with the following sample request payload:
User-Agent: Fiddler
Host: localhost:33082
Content-Type: application/json
Content-Length: 134
{
"Id":9,
"Name":"Customer #9",
"Orders":[
{
"OrderId":2,"Price":3.3
}
]
}
Thanks.