Create conversation
8/12/2019
3 minutes to read
In this article
Create a new conversation by including a thread and a post.
Use reply thread or reply post to further post to that conversation.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Group.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
Not supported.
HTTP request
POST /groups/{id}/conversations
Header
Value
Authorization
Bearer {token}. Required.
Content-Type
application/json
Request body
In the request body, supply a JSON representation of conversation object containing a conversationThread and a post .
Response
If successful, this method returns 201 Created
response code and conversation object in the response body.
The response includes the IDs for the new conversation and thread, which you can use in the
list posts operation to get the new post as well.
Example
Request
The following is an example of the request.
POST https://graph.microsoft.com/v1.0/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations
Content-type: application/json
{
"topic":"New locations for this quarter",
"threads":[
{
"posts":[
{
"body":{
"contentType":"html",
"content":"What do we know so far?"
},
"newParticipants":[
{
"emailAddress":{
"name":"Adele Vance",
"address":"AdeleV@contoso.onmicrosoft.com"
}
}
]
}
]
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var conversation = new Conversation
{
Topic = "New locations for this quarter",
Threads = new List<ConversationThread>()
{
new ConversationThread
{
Posts = new List<Post>()
{
new Post
{
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "What do we know so far?"
},
NewParticipants = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Name = "Adele Vance",
Address = "AdeleV@contoso.onmicrosoft.com"
}
}
}
}
}
}
}
};
await graphClient.Groups["29981b6a-0e57-42dc-94c9-cd24f5306196"].Conversations
.Request()
.AddAsync(conversation);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
const conversation = {
topic:"New locations for this quarter",
threads:[
{
posts:[
{
body:{
contentType:"html",
content:"What do we know so far?"
},
newParticipants:[
{
emailAddress:{
name:"Adele Vance",
address:"AdeleV@contoso.onmicrosoft.com"
}
}
]
}
]
}
]
};
let res = await client.api('/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations')
.post(conversation);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphConversation *conversation = [[MSGraphConversation alloc] init];
[conversation setTopic:@"New locations for this quarter"];
NSMutableArray *threadsList = [[NSMutableArray alloc] init];
MSGraphConversationThread *threads = [[MSGraphConversationThread alloc] init];
NSMutableArray *postsList = [[NSMutableArray alloc] init];
MSGraphPost *posts = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"What do we know so far?"];
[posts setBody:body];
NSMutableArray *newParticipantsList = [[NSMutableArray alloc] init];
MSGraphRecipient *newParticipants = [[MSGraphRecipient alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setName:@"Adele Vance"];
[emailAddress setAddress:@"AdeleV@contoso.onmicrosoft.com"];
[newParticipants setEmailAddress:emailAddress];
[newParticipantsList addObject: newParticipants];
[posts setNewParticipants:newParticipantsList];
[postsList addObject: posts];
[threads setPosts:postsList];
[threadsList addObject: threads];
[conversation setThreads:threadsList];
NSError *error;
NSData *conversationData = [conversation getSerializedDataWithError:&error];
[urlRequest setHTTPBody:conversationData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Conversation conversation = new Conversation();
conversation.topic = "New locations for this quarter";
LinkedList<ConversationThread> threadsList = new LinkedList<ConversationThread>();
ConversationThread threads = new ConversationThread();
LinkedList<Post> postsList = new LinkedList<Post>();
Post posts = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "What do we know so far?";
posts.body = body;
LinkedList<Recipient> newParticipantsList = new LinkedList<Recipient>();
Recipient newParticipants = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.name = "Adele Vance";
emailAddress.address = "AdeleV@contoso.onmicrosoft.com";
newParticipants.emailAddress = emailAddress;
newParticipantsList.add(newParticipants);
posts.newParticipants = newParticipantsList;
postsList.add(posts);
threads.posts = postsList;
threadsList.add(threads);
conversation.threads = threadsList;
graphClient.groups("29981b6a-0e57-42dc-94c9-cd24f5306196").conversations()
.buildRequest()
.post(conversation);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability. All the properties will be returned from an actual call.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups('29981b6a-0e57-42dc-94c9-cd24f5306196')/conversations/$entity",
"id":"AAQkADDVKtMlRp4Txc6k=",
"threads@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups('29981b6a-0e57-42dc-94c9-cd24f5306196')/conversations('AAQkADDVKtMlRp4Txc6k%3D')/threads",
"threads":[
{
"id":"AAQkADQDarUNUq0yVGnhPFzqQ=="
}
]
}