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.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
✅ |
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
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 example shows a 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.com"
}
}
]
}
]
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
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.com",
},
},
},
},
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
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.com"\
}\
}\
]\
}\
]\
}\
]\
}\
'
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
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.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)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
conversations, 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.
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Conversation conversation = new Conversation();
conversation.setTopic("Take your wellness days and rest");
LinkedList<ConversationThread> threads = new LinkedList<ConversationThread>();
ConversationThread conversationThread = new ConversationThread();
LinkedList<Post> posts = new LinkedList<Post>();
Post post = new Post();
ItemBody body = new ItemBody();
body.setContentType(BodyType.Html);
body.setContent("Contoso cares about you: Rest and Recharge");
post.setBody(body);
LinkedList<Recipient> newParticipants = new LinkedList<Recipient>();
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setName("Adele Vance");
emailAddress.setAddress("AdeleV@contoso.com");
recipient.setEmailAddress(emailAddress);
newParticipants.add(recipient);
post.setNewParticipants(newParticipants);
posts.add(post);
conversationThread.setPosts(posts);
threads.add(conversationThread);
conversation.setThreads(threads);
Conversation result = graphClient.groups().byGroupId("{group-id}").conversations().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.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
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Conversation;
use Microsoft\Graph\Generated\Models\ConversationThread;
use Microsoft\Graph\Generated\Models\Post;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\BodyType;
use Microsoft\Graph\Generated\Models\Recipient;
use Microsoft\Graph\Generated\Models\EmailAddress;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$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.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)->wait();
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.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.
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.conversation import Conversation
from msgraph.generated.models.conversation_thread import ConversationThread
from msgraph.generated.models.post import Post
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.body_type import BodyType
from msgraph.generated.models.recipient import Recipient
from msgraph.generated.models.email_address import EmailAddress
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Conversation(
topic = "Take your wellness days and rest",
threads = [
ConversationThread(
posts = [
Post(
body = ItemBody(
content_type = BodyType.Html,
content = "Contoso cares about you: Rest and Recharge",
),
new_participants = [
Recipient(
email_address = EmailAddress(
name = "Adele Vance",
address = "AdeleV@contoso.com",
),
),
],
),
],
),
],
)
result = await graph_client.groups.by_group_id('group-id').conversations.post(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 example shows 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=="
}
]
}