Create conversation
Article
07/06/2023
11 contributors
Feedback
In this article
Namespace: microsoft.graph
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": "Take your wellness days and rest",
"threads": [
{
"posts": [
{
"body": {
"contentType": "html",
"content": "Contoso cares about you: Rest and Recharge"
},
"newParticipants": [
{
"emailAddress": {
"name": "Adele Vance",
"address": "AdeleV@contoso.onmicrosoft.com"
}
}
]
}
]
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Conversation
{
Topic = "Take your wellness days and rest",
Threads = new List<ConversationThread>
{
new ConversationThread
{
Posts = new List<Post>
{
new Post
{
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Contoso cares about you: Rest and Recharge",
},
NewParticipants = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Name = "Adele Vance",
Address = "AdeleV@contoso.onmicrosoft.com",
},
},
},
},
},
},
},
};
var result = await graphClient.Groups["{group-id}"].Conversations.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
mgc groups conversations create --group-id {group-id} --body '{\
"topic": "Take your wellness days and rest",\
"threads": [\
{\
"posts": [\
{\
"body": {\
"contentType": "html",\
"content": "Contoso cares about you: Rest and Recharge"\
},\
"newParticipants": [\
{\
"emailAddress": {\
"name": "Adele Vance",\
"address": "AdeleV@contoso.onmicrosoft.com"\
}\
}\
]\
}\
]\
}\
]\
}\
'
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewConversation()
topic := "Take your wellness days and rest"
requestBody.SetTopic(&topic)
conversationThread := graphmodels.NewConversationThread()
post := graphmodels.NewPost()
body := graphmodels.NewItemBody()
contentType := graphmodels.HTML_BODYTYPE
body.SetContentType(&contentType)
content := "Contoso cares about you: Rest and Recharge"
body.SetContent(&content)
post.SetBody(body)
recipient := graphmodels.NewRecipient()
emailAddress := graphmodels.NewEmailAddress()
name := "Adele Vance"
emailAddress.SetName(&name)
address := "AdeleV@contoso.onmicrosoft.com"
emailAddress.SetAddress(&address)
recipient.SetEmailAddress(emailAddress)
newParticipants := []graphmodels.Recipientable {
recipient,
}
post.SetNewParticipants(newParticipants)
posts := []graphmodels.Postable {
post,
}
conversationThread.SetPosts(posts)
threads := []graphmodels.ConversationThreadable {
conversationThread,
}
requestBody.SetThreads(threads)
result, err := graphClient.Groups().ByGroupId("group-id").Conversations().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Conversation conversation = new Conversation();
conversation.topic = "Take your wellness days and rest";
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 = "Contoso cares about you: Rest and Recharge";
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);
PostCollectionResponse postCollectionResponse = new PostCollectionResponse();
postCollectionResponse.value = postsList;
PostCollectionPage postCollectionPage = new PostCollectionPage(postCollectionResponse, null);
threads.posts = postCollectionPage;
threadsList.add(threads);
ConversationThreadCollectionResponse conversationThreadCollectionResponse = new ConversationThreadCollectionResponse();
conversationThreadCollectionResponse.value = threadsList;
ConversationThreadCollectionPage conversationThreadCollectionPage = new ConversationThreadCollectionPage(conversationThreadCollectionResponse, null);
conversation.threads = conversationThreadCollectionPage;
graphClient.groups("29981b6a-0e57-42dc-94c9-cd24f5306196").conversations()
.buildRequest()
.post(conversation);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const conversation = {
topic: 'Take your wellness days and rest',
threads: [
{
posts: [
{
body: {
contentType: 'html',
content: 'Contoso cares about you: Rest and Recharge'
},
newParticipants: [
{
emailAddress: {
name: 'Adele Vance',
address: 'AdeleV@contoso.onmicrosoft.com'
}
}
]
}
]
}
]
};
await client.api('/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations')
.post(conversation);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Conversation();
$requestBody->setTopic('Take your wellness days and rest');
$threadsConversationThread1 = new ConversationThread();
$postsPost1 = new Post();
$postsPost1Body = new ItemBody();
$postsPost1Body->setContentType(new BodyType('html'));
$postsPost1Body->setContent('Contoso cares about you: Rest and Recharge');
$postsPost1->setBody($postsPost1Body);
$newParticipantsRecipient1 = new Recipient();
$newParticipantsRecipient1EmailAddress = new EmailAddress();
$newParticipantsRecipient1EmailAddress->setName('Adele Vance');
$newParticipantsRecipient1EmailAddress->setAddress('AdeleV@contoso.onmicrosoft.com');
$newParticipantsRecipient1->setEmailAddress($newParticipantsRecipient1EmailAddress);
$newParticipantsArray []= $newParticipantsRecipient1;
$postsPost1->setNewParticipants($newParticipantsArray);
$postsArray []= $postsPost1;
$threadsConversationThread1->setPosts($postsArray);
$threadsArray []= $threadsConversationThread1;
$requestBody->setThreads($threadsArray);
$result = $graphServiceClient->groups()->byGroupId('group-id')->conversations()->post($requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Groups
$params = @{
topic = "Take your wellness days and rest"
threads = @(
@{
posts = @(
@{
body = @{
contentType = "html"
content = "Contoso cares about you: Rest and Recharge"
}
newParticipants = @(
@{
emailAddress = @{
name = "Adele Vance"
address = "AdeleV@contoso.onmicrosoft.com"
}
}
)
}
)
}
)
}
New-MgGroupConversation -GroupId $groupId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// THE PYTHON SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
client = GraphServiceClient(request_adapter)
request_body = Conversation()
request_body.topic = 'Take your wellness days and rest'
threads_conversation_thread1 = ConversationThread()
posts_post1 = Post()
posts_post1body = ItemBody()
posts_post1body.contenttype(BodyType.Html('bodytype.html'))
posts_post1body.content = 'Contoso cares about you: Rest and Recharge'
posts_post1.body = posts_post1body
new_participants_recipient1 = Recipient()
new_participants_recipient1email_address = EmailAddress()
new_participants_recipient1email_address.name = 'Adele Vance'
new_participants_recipient1email_address.address = 'AdeleV@contoso.onmicrosoft.com'
new_participants_recipient1.email_address = new_participants_recipient1email_address
newParticipantsArray []= newParticipantsRecipient1;
posts_post1.newparticipants(newParticipantsArray)
postsArray []= postsPost1;
threads_conversation_thread1.posts(postsArray)
threadsArray []= threadsConversationThread1;
request_body.threads(threadsArray)
result = await client.groups.by_group_id('group-id').conversations.post(request_body = request_body)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('4d81ce71-486c-41e9-afc5-e41bf2d0722a')/conversations/$entity",
"id": "AAQkAGRhZmRhMWM3LTYwZTktNDZmYy1hNWU1LThhZWU4NzI2YTEyZgAQADamkjVbzvRKnUq1oBRdwhk=",
"threads": [
{
"id": "AAQkAGRhZmRhMWM3LTYwZTktNDZmYy1hNWU1LThhZWU4NzI2YTEyZgMkABAANqaSNVvO9EqdSrWgFF3CGRAANqaSNVvO9EqdSrWgFF3CGQ=="
}
]
}