連絡人的作業 | Graph API 參考
**適用於︰**Graph API | Azure Active Directory
本主題討論如何使用 Azure Active Directory (AD) Graph API 對組織連絡人執行作業。 組織連絡人通常代表公司或組織外部的使用者。 他們與 O365 Outlook 個人連絡人不同。 使用 Azure AD Graph API,您可以讀取組織連絡人以及其與其他目錄物件 (例如其管理員、直屬員工和群組成員資格) 的關聯性。 寫入組織連絡人的功能僅限於這些目前不是從內部部署目錄同步的連絡人 (dirSyncEnabled 屬性是 null 或 false)。 對於這類連絡人,您可以更新或刪除連絡人本身或是其管理員屬性。 您無法使用 Graph API 來建立組織連絡人。 如需組織連絡人的詳細資訊 (包括其在租用戶中的建立方式),請參閱 [Contact]。
Graph API 是 REST API,可讓您以程式設計方式存取 Azure Active Directory 中的目錄物件,例如使用者、群組、組織連絡人和應用程式。
重要
您也可以透過 Microsoft Graph 取得 Azure AD Graph API 功能,這個統一 API 同時也包含如 Outlook、OneDrive、OneNote、Planner 和 Office Graph 等其他 Microsoft 服務 API,讓您可以使用單一的存取權杖透過單一端點存取所有 API。
執行連絡人的 REST 作業
為了使用 Graph API 執行組織連絡人的作業,請使用支援的方法 (GET、POST、PATCH、PUT 或 DELETE) 將 HTTP 要求傳送到端點,而端點的目標設為連絡人資源集合、特定連絡人、連絡人的導覽屬性,或是可對連絡人呼叫的函數或動作。
Graph API 要求使用下列基本 URL:
https://graph.windows.net/{tenant_id}/{resource_path}?{api_version}[odata_query_parameters]
重要
傳送到 Graph API 之要求的格式必須正確、目標設為有效的端點和Graph API 版本,而且其 Authorization
標頭中攜帶取自 Azure AD 的有效存取權杖。 如需使用 Graph API 建立要求以及接收回應的詳細資訊,請參閱[Operations Overview]。
您可以根據目標設為租用戶中的所有連絡人集合、個別連絡人還是特定連絡人的導覽屬性,透過不同的方式指定 {resource_path}
。
/contacts
將目標設為連絡人資源集合。 您可以使用此資源路徑讀取租用戶中的所有連絡人或篩選過的連絡人清單。/contacts/{object_id}
將目標設為租用戶中的個別連絡人。 您可以使用物件識別碼 (GUID) 指定目標連絡人。 您可以使用此資源路徑取得連絡人的已宣告屬性。 對於未從內部部署目錄同步處理的連絡人,您可以使用此資源路徑修改連絡人的已宣告屬性或刪除連絡人。/contacts/{object_id}/{nav_property}
將目標設為連絡人的指定導覽屬性。 您可以使用它來傳回所指定連絡人的目標導覽屬性所參考的一或多個物件。 注意:這種形式的定址僅供讀取。/contacts/{object_id}/$links/{nav_property}
將目標設為連絡人的指定導覽屬性。 您可以使用這種定址形式來讀取和修改導覽屬性。 讀取時,此屬性所參考的物件會傳回為回應主體中的一或多個連結。 只能修改未從內部部署目錄同步處理之連絡人的 manager 導覽屬性。 管理員會指定為要求主體中的連結。
例如,下列要求會傳回所指定連絡人之管理員的連結︰
GET https://graph.windows.net/myorganization/contacts/a2fb3752-08b4-413d-af6f-1d99c4c131d9/$links/manager?api-version=1.6
連絡人的基本作業
將目標設為連絡人資源集合或特定連絡人,即可執行連絡人的讀取作業。 將目標設為特定連絡人,即可更新和刪除未從內部部署目錄同步處理的連絡人。 Graph API 不支援建立連絡人, 也不支援更新或刪除從內部部署目錄同步處理的連絡人 (dirSyncEnabled 屬性是 true)。 下列各主題示範如何執行連絡人的基本作業。
取得連絡人
取得連絡人集合。 您可以將 OData 查詢參數加入對回應進行篩選、排序和分頁的要求中。 如需詳細資訊,請參閱[Supported Queries, Filters, and Paging Options]。
成功時,傳回 [Contact] 物件集合;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
{
"api": "Contacts",
"operation": "get contacts",
"showComponents": {
"codeGenerator": "true"
}
}
取得連絡人
取得指定的連絡人。 您可以使用物件識別碼 (GUID) 識別目標連絡人。
成功時,傳回所指定連絡人的 [Contact] 物件;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
{
"api": "Contacts",
"operation": "get contact by id",
"showComponents": {
"codeGenerator": "true"
}
}
更新連絡人
更新連絡人的屬性。 在要求主體中指定任何可寫入的 [Contact] 屬性。 只會變更您所指定的屬性。 您只能更新未從內部部署目錄同步處理的連絡人 (dirSyncEnabled 屬性是 null 或 false)。
成功時,不會傳回回應主體;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
{
"api": "Contacts",
"operation": "update contact"
}
刪除連絡人
刪除連絡人。 您只能刪除未從內部部署目錄同步處理的連絡人 (dirSyncEnabled 屬性是 null 或 false)。
成功時,不會傳回回應主體;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
{
"api": "Contacts",
"operation": "delete contact"
}
連絡人導覽屬性的作業
連絡人與目錄中其他物件 (例如連絡人的管理員、直屬群組成員資格和直屬員工) 之間的關聯性是透過導覽屬性進行公開。 將目標設為要求中的這些導覽屬性,即可讀取這些關聯性;而且,在某些情況下,還可以修改這些關聯性。
取得連絡人的管理員
透過 manager 導覽屬性取得連絡人的管理員。
成功時,傳回指派為連絡人管理員之 [User] 或 [Contact] 的連結;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
注意:您可以移除 URL 中的 "$links" 區段來傳回 [User] 或 [Contact] 物件,而非連結。
{
"api": "Contacts",
"operation": "get contact manager link",
"showComponents": {
"codeGenerator": "true",
}
}
指派連絡人的管理員
透過 manager 屬性指派連絡人的管理員。 可能指派使用者或連絡人。 要求主體包含要指派之 [User] 或 [Contact] 的連結。 您只能更新未從內部部署目錄同步處理之連絡人的管理員 (dirSyncEnabled 屬性是 null 或 false)。
成功時,不會傳回回應主體;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
{
"api": "Contacts",
"operation": "update contact manager"
}
取得連絡人的直屬員工
透過 directReports 導覽屬性取得連絡人的直屬員工。
成功時,傳回將此連絡人指派為管理員之 [User] 和 [Contact] 的連結集合;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
注意:您可以移除 URL 中的 "$links" 區段來傳回使用者和連絡人的 [DirectoryObject],而非連結。
{
"api": "Contacts",
"operation": "get contact direct reports links",
"showComponents": {
"codeGenerator": "true"
}
}
取得連絡人的群組成員資格
透過 memberOf 導覽屬性取得連絡人的群組成員資格。
這個屬性只會傳回連絡人為其直屬成員的群組。 若要取得連絡人具有直接或可轉移成員資格的所有群組,請呼叫 [getMemberGroups] 函數。
成功時,傳回此連絡人為其成員之 [Group] 的連結集合;否則,回應主體會包含錯誤詳細資料。 如需錯誤的詳細資訊,請參閱Error Codes and Error Handling。
注意:您可以移除 URL 中的 "$links" 區段來傳回群組的 [DirectoryObject],而非連結。
{
"api": "Contacts",
"operation": "get contact memberOf links",
"showComponents": {
"codeGenerator": "true"
}
}
連絡人的函數和動作
您可以對連絡人呼叫下列任何函數。
檢查特定群組中的成員資格 (可轉移)
您可以呼叫 [isMemberOf] 函數來檢查特定群組中的成員資格。 此檢查可移轉。
檢查群組清單中的成員資格 (可轉移)
您可以呼叫 [checkMemberGroups] 函數來檢查群組清單中的成員資格。 此檢查可移轉。
取得所有群組成員資格 (可轉移)
您可以呼叫 [getMemberGroups] 函數來傳回連絡人為其成員的所有群組。 與讀取 memberOf 導覽屬性 (只會傳回連絡人為其直屬成員的群組) 不同,此檢查可轉移。
其他資源
- 在 Graph API 概念中深入了解 Graph API 支援的功能、能力和預覽功能。
Get contacts
GET https://graph.windows.net/myorganization/contacts?api-version
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
Query | |||
api-version | string | 1.6 | The version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
Response
Status Code:200
Content-Type: application/json
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/Microsoft.DirectoryServices.Contact",
"value": [
{
"odata.type": "Microsoft.DirectoryServices.Contact",
"objectType": "Contact",
"objectId": "31944231-fd52-4a7f-b32e-7902a01fddf9",
"deletionTimestamp": null,
"city": null,
"companyName": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "Marcus Breyer",
"facsimileTelephoneNumber": null,
"givenName": "Marcus",
"jobTitle": null,
"lastDirSyncTime": null,
"mail": "Marcus@contoso.com",
"mailNickname": "MarcusBreyer",
"mobile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"provisioningErrors": [],
"proxyAddresses": [
"SMTP:Marcus@contoso.com"
],
"sipProxyAddress": null,
"state": null,
"streetAddress": null,
"surname": "Breyer",
"telephoneNumber": null
},
{
"odata.type": "Microsoft.DirectoryServices.Contact",
"objectType": "Contact",
"objectId": "35110b16-360c-4c4a-93b2-03f065fabd93",
"deletionTimestamp": null,
"city": null,
"companyName": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "Yossi Ran",
"facsimileTelephoneNumber": null,
"givenName": "Yossi",
"jobTitle": null,
"lastDirSyncTime": null,
"mail": "Yossi@contoso.com",
"mailNickname": "YossiRan",
"mobile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"provisioningErrors": [],
"proxyAddresses": [
"SMTP:Yossi@contoso.com"
],
"sipProxyAddress": null,
"state": null,
"streetAddress": null,
"surname": "Ran",
"telephoneNumber": null
},
{
"odata.type": "Microsoft.DirectoryServices.Contact",
"objectType": "Contact",
"objectId": "7163f3b8-70c9-43d2-b9e1-4467ddaf087a",
"deletionTimestamp": null,
"city": null,
"companyName": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "Jeremy Nelson",
"facsimileTelephoneNumber": null,
"givenName": "Jeremy",
"jobTitle": null,
"lastDirSyncTime": null,
"mail": "Jeremy@contoso.com",
"mailNickname": "JeremyNelson",
"mobile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"provisioningErrors": [],
"proxyAddresses": [
"SMTP:Jeremy@contoso.com"
],
"sipProxyAddress": null,
"state": null,
"streetAddress": null,
"surname": "Nelson",
"telephoneNumber": null
},
{
"odata.type": "Microsoft.DirectoryServices.Contact",
"objectType": "Contact",
"objectId": "83234b5c-3a10-4108-8f36-39b1addadfdb",
"deletionTimestamp": null,
"city": null,
"companyName": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "David Strome",
"facsimileTelephoneNumber": null,
"givenName": "David",
"jobTitle": null,
"lastDirSyncTime": null,
"mail": "David@contoso.com",
"mailNickname": "DavidStrome",
"mobile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"provisioningErrors": [],
"proxyAddresses": [
"SMTP:David@contoso.com"
],
"sipProxyAddress": null,
"state": null,
"streetAddress": null,
"surname": "Strome",
"telephoneNumber": null
},
{
"odata.type": "Microsoft.DirectoryServices.Contact",
"objectType": "Contact",
"objectId": "8c1315ce-bf6f-4e26-b24f-c830606ef41c",
"deletionTimestamp": null,
"city": null,
"companyName": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "Holly Holt",
"facsimileTelephoneNumber": null,
"givenName": "Holly",
"jobTitle": null,
"lastDirSyncTime": null,
"mail": "Holly@contoso.com",
"mailNickname": "HollyHolt",
"mobile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"provisioningErrors": [],
"proxyAddresses": [
"SMTP:Holly@contoso.com"
],
"sipProxyAddress": null,
"state": null,
"streetAddress": null,
"surname": "Holt",
"telephoneNumber": null
}
]
}
Response List
Status Code | Description |
---|---|
200 | OK. Indicates success. The results are returned in the response body. |
Code Samples
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
/* OAuth2 is required to access this API. For more information visit:
https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks */
// Specify values for the following required parameters
queryString["api-version"] = "1.6";
// Specify values for path parameters (shown as {...})
var uri = "https://graph.windows.net/myorganization/contacts?" + queryString;
var response = await client.GetAsync(uri);
if (response.Content != null)
{
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
}
}
@ECHO OFF
REM OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
REM Specify values for path parameters (shown as {...}), values for query parameters
curl -v -X GET "https://graph.windows.net/myorganization/contacts?api-version=1.6&"^
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample {
public static void main(String[] args) {
HttpClient httpclient = HttpClients.createDefault();
try
{
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
URIBuilder builder = new URIBuilder("https://graph.windows.net/myorganization/contacts");
// Specify values for the following required parameters
builder.setParameter("api-version", "1.6");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
var params = {
// Specify values for the following required parameters
'api-version': "1.6",
};
$.ajax({
// Specify values for path parameters (shown as {...})
url: 'https://graph.windows.net/myorganization/contacts?' + $.param(params),
type: 'GET',
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
NSString* path = @"https://graph.windows.net/myorganization/contacts";
NSArray* array = @[
@"entities=true",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if(nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if(nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
[pool drain];
return 0;
}
<?php
// This sample uses the pecl_http package. (for more information: http://pecl.php.net/package/pecl_http)
require_once 'HTTP/Request2.php';
$headers = array(
);
$query_params = array(
// Specify values for the following required parameters
'api-version' => '1.6',
);
$request = new Http_Request2('https://graph.windows.net/myorganization/contacts');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setHeader($headers);
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
$url = $request->getUrl();
$url->setQueryVariables($query_params);
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
`
``
``` Python
########### Python 2.7 #############
import httplib, urllib, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = httplib.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.parse.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = http.client.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
require 'net/http'
uri = URI('https://graph.windows.net/myorganization/contacts')
uri.query = URI.encode_www_form({
# Specify values for the following required parameters
'api-version' => '1.6',
})
request = Net::HTTP::Get.new(uri.request_uri)
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body
Get a contact
GET https://graph.windows.net/myorganization/contacts/{object_id}?api-version
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
URL | |||
object_id | string | 31944231-fd52-4a7f-b32e-7902a01fddf9 | The object ID (GUID) of the target contact. |
Query | |||
api-version | string | 1.6 | Specifies the version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
GET https://graph.windows.net/myorganization/contacts/31944231-fd52-4a7f-b32e-7902a01fddf9?api-version=1.6
Response
Status Code:200
Content-Type: application/json
{
"odata.metadata": "https://graph.windows.net/graphdir1.onmicrosoft.com/$metadata#directoryObjects/Microsoft.DirectoryServices.Contact/@Element",
"odata.type": "Microsoft.DirectoryServices.Contact",
"objectType": "Contact",
"objectId": "31944231-fd52-4a7f-b32e-7902a01fddf9",
"deletionTimestamp": null,
"city": null,
"companyName": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "Marcus Breyer",
"facsimileTelephoneNumber": null,
"givenName": "Marcus",
"jobTitle": null,
"lastDirSyncTime": null,
"mail": "Marcus@contoso.com",
"mailNickname": "MarcusBreyer",
"mobile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"provisioningErrors": [],
"proxyAddresses": [
"SMTP:Marcus@contoso.com"
],
"sipProxyAddress": null,
"state": null,
"streetAddress": null,
"surname": "Breyer",
"telephoneNumber": null
}
Response List
Status Code | Description |
---|---|
200 | OK. Indicates success. The contact is returned in the response body. |
Code Samples
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
/* OAuth2 is required to access this API. For more information visit:
https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks */
// Specify values for the following required parameters
queryString["api-version"] = "1.6";
// Specify values for path parameters (shown as {...})
var uri = "https://graph.windows.net/myorganization/contacts/{object_id}?" + queryString;
var response = await client.GetAsync(uri);
if (response.Content != null)
{
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
}
}
@ECHO OFF
REM OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
REM Specify values for path parameters (shown as {...}), values for query parameters
curl -v -X GET "https://graph.windows.net/myorganization/contacts/{object_id}?api-version=1.6&"^
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample {
public static void main(String[] args) {
HttpClient httpclient = HttpClients.createDefault();
try
{
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
URIBuilder builder = new URIBuilder("https://graph.windows.net/myorganization/contacts/{object_id}");
// Specify values for the following required parameters
builder.setParameter("api-version", "1.6");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
var params = {
// Specify values for the following required parameters
'api-version': "1.6",
};
$.ajax({
// Specify values for path parameters (shown as {...})
url: 'https://graph.windows.net/myorganization/contacts/{object_id}?' + $.param(params),
type: 'GET',
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
NSString* path = @"https://graph.windows.net/myorganization/contacts/{object_id}";
NSArray* array = @[
@"entities=true",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if(nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if(nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
[pool drain];
return 0;
}
<?php
// This sample uses the pecl_http package. (for more information: http://pecl.php.net/package/pecl_http)
require_once 'HTTP/Request2.php';
$headers = array(
);
$query_params = array(
// Specify values for the following required parameters
'api-version' => '1.6',
);
$request = new Http_Request2('https://graph.windows.net/myorganization/contacts/{object_id}');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setHeader($headers);
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
$url = $request->getUrl();
$url->setQueryVariables($query_params);
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
}
########### Python 2.7 #############
import httplib, urllib, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = httplib.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.parse.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = http.client.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
require 'net/http'
uri = URI('https://graph.windows.net/myorganization/contacts/{object_id}')
uri.query = URI.encode_www_form({
# Specify values for the following required parameters
'api-version' => '1.6',
})
request = Net::HTTP::Get.new(uri.request_uri)
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body
Update a contact
PATCH https://graph.windows.net/myorganization/contacts/{object_id}?api-version
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
URL | |||
object_id | string | 7163f3b8-70c9-43d2-b9e1-4467ddaf087a | The object ID (GUID) of the target contact. |
Query | |||
api-version | string | 1.6 | The version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
Body | |||
Content-Type: application/json |
{
"department": "Sales",
"jobTitle": "Sales Rep"
}
PATCH https://graph.windows.net/myorganization/contacts/7163f3b8-70c9-43d2-b9e1-4467ddaf087a?api-version=1.6
Response
Status Code:204
Content-Type: application/json
Response List
Status Code | Description |
---|---|
204 | No Content. Indicates success. No response body is returned. |
Delete a contact
DELETE https://graph.windows.net/myorganization/contacts/{object_id}[?api-version]
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
URL | |||
object_id | string | 7163f3b8-70c9-43d2-b9e1-4467ddaf087a | The object ID (GUID) of the target contact. |
Query | |||
api-version | string | 1.6 | Specifies the version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
DELETE https://graph.windows.net/myorganization/contacts/7163f3b8-70c9-43d2-b9e1-4467ddaf087a?api-version=1.6
Response
Status Code:204
Content-Type: application/json
Response List
Status Code | Description |
---|---|
204 | No Content. Indicates success. |
Get a contact's manager
GET https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager?api-version
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
URL | |||
object_id | string | 31944231-fd52-4a7f-b32e-7902a01fddf9 | The object ID (GUID) of the target contact. |
Query | |||
api-version | string | 1.6 | The version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
GET https://graph.windows.net/myorganization/contacts/31944231-fd52-4a7f-b32e-7902a01fddf9/$links/manager?api-version=1.6
Response
Status Code:200
Content-Type: application/json
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/$links/manager",
"url": "https://graph.windows.net/myorganization/directoryObjects/35110b16-360c-4c4a-93b2-03f065fabd93/Microsoft.WindowsAzure.ActiveDirectory.Contact"
}
Response List
Status Code | Description |
---|---|
200 | OK. Indicates success. A link to the contact's manager is returned. |
404 | Not Found. The requested resource was not found. This can occur if the manager property is not currently set for the specified contact. It can also have other causes, for example, a bad domain. A code and associated message is returned with the error. |
Code Samples
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
/* OAuth2 is required to access this API. For more information visit:
https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks */
// Specify values for the following required parameters
queryString["api-version"] = "1.6";
// Specify values for path parameters (shown as {...})
var uri = "https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager?" + queryString;
var response = await client.GetAsync(uri);
if (response.Content != null)
{
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
}
}
@ECHO OFF
REM OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
REM Specify values for path parameters (shown as {...}), values for query parameters
curl -v -X GET "https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager?api-version=1.6&"^
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample {
public static void main(String[] args) {
HttpClient httpclient = HttpClients.createDefault();
try
{
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
URIBuilder builder = new URIBuilder("https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager");
// Specify values for the following required parameters
builder.setParameter("api-version", "1.6");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
var params = {
// Specify values for the following required parameters
'api-version': "1.6",
};
$.ajax({
// Specify values for path parameters (shown as {...})
url: 'https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager?' + $.param(params),
type: 'GET',
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
NSString* path = @"https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager";
NSArray* array = @[
@"entities=true",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if(nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if(nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
[pool drain];
return 0;
}
<?php
// This sample uses the pecl_http package. (for more information: http://pecl.php.net/package/pecl_http)
require_once 'HTTP/Request2.php';
$headers = array(
);
$query_params = array(
// Specify values for the following required parameters
'api-version' => '1.6',
);
$request = new Http_Request2('https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setHeader($headers);
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
$url = $request->getUrl();
$url->setQueryVariables($query_params);
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
########### Python 2.7 #############
import httplib, urllib, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = httplib.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}/$links/manager?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.parse.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = http.client.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}/$links/manager?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
require 'net/http'
uri = URI('https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager')
uri.query = URI.encode_www_form({
# Specify values for the following required parameters
'api-version' => '1.6',
})
request = Net::HTTP::Get.new(uri.request_uri)
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body
Assign a contact's manager
PUT https://graph.windows.net/myorganization/contacts/{object_id}/$links/manager?api-version
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
URL | |||
object_id | string | 31944231-fd52-4a7f-b32e-7902a01fddf9 | The object ID (GUID) of the target contact. |
Query | |||
api-version | string | 1.6 | The version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
Body | |||
Content-Type: application/json |
{
"url": "https://graph.windows.net/myorganization/directoryObjects/35110b16-360c-4c4a-93b2-03f065fabd93"
}
PUT https://graph.windows.net/myorganization/contacts/31944231-fd52-4a7f-b32e-7902a01fddf9/$links/manager?api-version=1.6
Response
Status Code:204
Content-Type: application/json
Response List
Status Code | Description |
---|---|
204 | No Content. Indicates success. No response body is returned. |
Get a contact's direct reports
GET https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports?api-version
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
URL | |||
object_id | string | 31944231-fd52-4a7f-b32e-7902a01fddf9 | The object ID (GUID) of the target contact. |
Query | |||
api-version | string | 1.6 | The version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
GET https://graph.windows.net/myorganization/contacts/31944231-fd52-4a7f-b32e-7902a01fddf9/$links/directReports?api-version=1.6
Response
Status Code:200
Content-Type: application/json
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/$links/directReports",
"value": [
{
"url": "https://graph.windows.net/myorganization/directoryObjects/8c1315ce-bf6f-4e26-b24f-c830606ef41c/Microsoft.DirectoryServices.Contact"
}
]
}
Response List
Status Code | Description |
---|---|
200 | OK. Indicates success. One or more direct reports are returned. |
Code Samples
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
/* OAuth2 is required to access this API. For more information visit:
https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks */
// Specify values for the following required parameters
queryString["api-version"] = "1.6";
// Specify values for path parameters (shown as {...})
var uri = "https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports?" + queryString;
var response = await client.GetAsync(uri);
if (response.Content != null)
{
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
}
}
@ECHO OFF
REM OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
REM Specify values for path parameters (shown as {...}), values for query parameters
curl -v -X GET "https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports?api-version=1.6&"^
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample {
public static void main(String[] args) {
HttpClient httpclient = HttpClients.createDefault();
try
{
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
URIBuilder builder = new URIBuilder("https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports");
// Specify values for the following required parameters
builder.setParameter("api-version", "1.6");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
var params = {
// Specify values for the following required parameters
'api-version': "1.6",
};
$.ajax({
// Specify values for path parameters (shown as {...})
url: 'https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports?' + $.param(params),
type: 'GET',
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
NSString* path = @"https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports";
NSArray* array = @[
@"entities=true",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if(nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if(nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
[pool drain];
return 0;
}```
``` php
<?php
// This sample uses the pecl_http package. (for more information: http://pecl.php.net/package/pecl_http)
require_once 'HTTP/Request2.php';
$headers = array(
);
$query_params = array(
// Specify values for the following required parameters
'api-version' => '1.6',
);
$request = new Http_Request2('https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setHeader($headers);
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
$url = $request->getUrl();
$url->setQueryVariables($query_params);
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>```
``` Python
########### Python 2.7 #############
import httplib, urllib, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = httplib.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}/$links/directReports?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.parse.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = http.client.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}/$links/directReports?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
require 'net/http'
uri = URI('https://graph.windows.net/myorganization/contacts/{object_id}/$links/directReports')
uri.query = URI.encode_www_form({
# Specify values for the following required parameters
'api-version' => '1.6',
})
request = Net::HTTP::Get.new(uri.request_uri)
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body
Get a contact's group memberships
GET https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf?api-version
Parameters
Parameter | Type | Value | Notes |
---|---|---|---|
URL | |||
object_id | string | 31944231-fd52-4a7f-b32e-7902a01fddf9 | The object ID (GUID) of the target contact. |
Query | |||
api-version | string | 1.6 | The version of the Graph API to target. Beginning with version 1.5, the api-version string is represented in major.minor format. Prior releases were represented as date strings: '2013-11-08' and '2013-04-05'. Required. |
GET https://graph.windows.net/myorganization/contacts/31944231-fd52-4a7f-b32e-7902a01fddf9/$links/memberOf?api-version=1.6
Response
Status Code:200
Content-Type: application/json
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/$links/memberOf",
"value": [
{
"url": "https://graph.windows.net/myorganization/directoryObjects/12345678-b942-47c9-a10e-a4bee353ce60/Microsoft.DirectoryServices.Group"
}
]
}
Response List |Status Code|Description| |-----------|-----------| |200 |OK. Indicates success. One or more groups and/or directory roles are returned.|
Code Samples
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
/* OAuth2 is required to access this API. For more information visit:
https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks */
// Specify values for the following required parameters
queryString["api-version"] = "1.6";
// Specify values for path parameters (shown as {...})
var uri = "https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf?" + queryString;
var response = await client.GetAsync(uri);
if (response.Content != null)
{
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
}
}
@ECHO OFF
REM OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
REM Specify values for path parameters (shown as {...}), values for query parameters
curl -v -X GET "https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf?api-version=1.6&"^
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample {
public static void main(String[] args) {
HttpClient httpclient = HttpClients.createDefault();
try
{
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
URIBuilder builder = new URIBuilder("https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf");
// Specify values for the following required parameters
builder.setParameter("api-version", "1.6");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
var params = {
// Specify values for the following required parameters
'api-version': "1.6",
};
$.ajax({
// Specify values for path parameters (shown as {...})
url: 'https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf?' + $.param(params),
type: 'GET',
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
NSString* path = @"https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf";
NSArray* array = @[
@"entities=true",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if(nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if(nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
[pool drain];
return 0;
}
<?php
// This sample uses the pecl_http package. (for more information: http://pecl.php.net/package/pecl_http)
require_once 'HTTP/Request2.php';
$headers = array(
);
$query_params = array(
// Specify values for the following required parameters
'api-version' => '1.6',
);
$request = new Http_Request2('https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setHeader($headers);
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
$url = $request->getUrl();
$url->setQueryVariables($query_params);
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
########### Python 2.7 #############
import httplib, urllib, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = httplib.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}/$links/memberOf?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
headers = {
}
params = urllib.parse.urlencode({
# Specify values for the following required parameters
'api-version': '1.6',
})
try:
conn = http.client.HTTPSConnection('graph.windows.net')
# Specify values for path parameters (shown as {...}) and request body if needed
conn.request("GET", "/myorganization/contacts/{object_id}/$links/memberOf?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
require 'net/http'
uri = URI('https://graph.windows.net/myorganization/contacts/{object_id}/$links/memberOf')
uri.query = URI.encode_www_form({
# Specify values for the following required parameters
'api-version' => '1.6',
})
request = Net::HTTP::Get.new(uri.request_uri)
# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body