APIでTeamsにメッセージを投稿する際に添付ファイルを付与して投稿する方法
Microsoft Graph APIを使用してTeamsにメッセージを投稿する際に、添付ファイルを付与するには、POST /teams/{team-id}/channels/{channel-id}/messages エンドポイントを使用します。以下は、添付ファイルを含めたメッセージの投稿例です。エンドポイント:httpCopy codePOST /teams/{team-id}/channels/{channel-id}/messages{team-id}と{channel-id}は対象のTeamsチームとチャネルのIDに置き換える必要があります。ヘッダー:httpCopy codeAuthorization: Bearer {access-token}Content-Type: multipart/form-dataアクセストークンをAuthorizationヘッダーに含め、Content-Typeをmultipart/form-dataに設定します。ボディ:メッセージの本文や添付ファイルの情報を含むJSON形式のデータを送信します。jsonCopy code{ "body": { "content": "Hello, this is a test message with an attachment in Microsoft Teams!", "contentType": "html" }, "attachments": [ { "@odata.type": "#microsoft.graph.fileAttachment", "name": "example.txt", "contentType": "text/plain", "contentBytes": "SGVsbG8sIHdvcmxkIQ==" } ]}上記の例では、attachmentsプロパティを使用して添付ファイルの情報を指定しています。@odata.typeはファイルのタイプを示し、contentBytesは添付ファイルのBase64エンコードされたコンテンツを表します。完全な例:httpCopy codePOST /teams/{team-id}/channels/{channel-id}/messages HTTP/1.1Host: graph.microsoft.comAuthorization: Bearer {access-token}Content-Type: multipart/form-data{ "body": { "content": "Hello, this is a test message with an attachment in Microsoft Teams!", "contentType": "html" }, "attachments": [ { "@odata.type": "#microsoft.graph.fileAttachment", "name": "example.txt", "contentType": "text/plain", "contentBytes": "SGVsbG8sIHdvcmxkIQ==" } ]}上記の例では、example.txtという名前のテキストファイルが添付されています。実際の使用に応じて、添付ファイルの種類や内容を適切に設定してください。