Skip to content

Latest commit

 

History

History
180 lines (140 loc) · 3.36 KB

c-sharp-examples.md

File metadata and controls

180 lines (140 loc) · 3.36 KB
title description author
C Sharp examples
Examples Snippets generated by the api
andrueastman

CSharp examples

This shows how snippets requests look like for C#

Examples

GET Request

Example GET Request

GET /v1.0/me/events/AAMkAGIAAAoZDOFAAA=?$select=subject,body,bodyPreview,organizer,attendees,start,end,location HTTP/1.1
Host: graph.microsoft.com
Prefer: outlook.timezone="Pacific Standard Time"

Example GET Request snippet generated

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var @event = await graphClient.Me.Events["AAMkAGIAAAoZDOFAAA="]
	.Request()
	.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
	.Select( e => new {
			 e.Subject,
			 e.Body,
			 e.BodyPreview,
			 e.Organizer,
			 e.Attendees,
			 e.Start,
			 e.End,
			 e.Location 
			 })
	.GetAsync();

POST Request

Example POST Request

POST /v1.0/users HTTP/1.1
Host: graph.microsoft.com
Content-type: application/json

{
  "accountEnabled": true,
  "displayName": "displayName-value",
  "mailNickname": "mailNickname-value",
  "userPrincipalName": "upn-value@tenant-value.onmicrosoft.com",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password-value"
  }
}

Example POST Request snippet generated

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var user = new User
{
	AccountEnabled = true,
	DisplayName = "displayName-value",
	MailNickname = "mailNickname-value",
	UserPrincipalName = "upn-value@tenant-value.onmicrosoft.com",
	PasswordProfile = new PasswordProfile
	{
		ForceChangePasswordNextSignIn = true,
		Password = "password-value",
	},
};

await graphClient.Users
	.Request()
	.AddAsync(user);

PATCH Request

Example PATCH Request

PATCH /v1.0/me HTTP/1.1
Host: graph.microsoft.com
Content-type: application/json
Content-length: 491

{
  "accountEnabled": true,
  "businessPhones": [
    "businessPhones-value"
  ],
  "city": "city-value"
}

Example PATCH Request snippet generated

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var user = new User
{
	AccountEnabled = true,
	BusinessPhones = new List<String>()
	{
		"businessPhones-value",
	},
	City = "city-value",
};

await graphClient.Me
	.Request()
	.UpdateAsync(user);

PUT Request

Example PUT Request

PUT /beta/applications/{id}/synchronization/templates/{templateId} HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer <token>
Content-type: application/json

{
    "id": "Slack",
    "applicationId": "{id}",
    "factoryTag": "CustomSCIM"
}

Example PUT Request snippet generated

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var synchronizationTemplate = new SynchronizationTemplate
{
	Id = "Slack",
	ApplicationId = "{id}",
	FactoryTag = "CustomSCIM",
};

await graphClient.Applications["{id}"].Synchronization.Templates["{templateId}"]
	.Request()
	.Header("Authorization","Bearer <token>")
	.PutAsync(synchronizationTemplate);

DELETE Request

Example DELETE Request

DELETE /v1.0/me/messages/{id} HTTP/1.1
Host: graph.microsoft.com

Example DELETE Request snippet generated

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

await graphClient.Me.Messages["{id}"]
	.Request()
	.DeleteAsync();