我正在使用ms图表联系人api并寻找过滤器选项
是否可以过滤电子邮件或商务电话中至少包含一个元素的联系人?
我已经尝试了类似$ filter = emailAddresses / $ count gt 0'
的内容答案 0 :(得分:1)
$ count仅适用于联系人级别,根据this document,电子邮件或商务手机尚不支持$ filter。
作为解决方法,您可以使用c#/ javascript过滤联系人集合中的结果。例如在c#:
中 using (var request = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me/contacts"))
{
request.Headers.Add("Authorization", "Bearer " + token);
request.Headers.Add("Accept", "application/json;odata.metadata=minimal");
using (var response = client.SendAsync(request).Result)
{
if (response.StatusCode == HttpStatusCode.OK)
{
var model = JsonConvert.DeserializeObject<RootObject>(response.Content.ReadAsStringAsync().Result);
foreach (var item in model.value)
{
if (item.BusinessPhones.Count>0)
{
//you could add this contact to a contact list .
}
}
}
}
}
public class RootObject
{
public List<Value> value { get; set; }
}
public class Value
{
public string id { get; set; }
public List<object> BusinessPhones { get; set; }
public List<object> EmailAddresses { get; set; }
}