简体   繁体   中英

MS Teams Graph API using JSON BATCH request to post message in channel

I am trying to Combine multiple requests in one HTTP call using JSON batching to post message in MS Teams channel using GRAPH Explorer.

url=https://graph.microsoft.com/beta/$batch
Request Body ={
"requests": [
  {
    "id": "1",
      "url": "/teams/cf82621f-bbe1-4bf1-a973-030fc6e58f03/channels/19:832f5e8d49ad4bfe96944d47cdd921d2@thread.skype/messages",
    "method": "POST",

    "body": {
  "content": "HelloWorld"
},"headers": {
      "Content-Type": "application/json"
    }

  }

]
}

On posting it I am getting Success - Status Code 200 but the response is coming as

{
    "responses": [
        {
            "id": "1",
            "status": 400,
            "body": {
                "error": {
                    "code": "BadRequest",
                    "message": "Value cannot be null.\r\nParameter name: Content",
                    "innerError": {
                        "request-id": "e23a0012-f40b-45e8-bae8-d68204217921",
                        "date": "2019-12-04T13:23:16"
                    }
                }
            }
        }
    ]
}

I have mentioned the value of content in body, without JSON batch it is working fine for me.

Can you try Json given below? You need to send two body attribute one Batch request and one for actual payload for teams endpoint.

"requests": [
  {
    "id": "1",
    "url": "/teams/cf82621f-bbe1-4bf1-a973-030fc6e58f03/channels/19:832f5e8d49ad4bfe96944d47cdd921d2@thread.skype/messages",
    "method": "POST",
    "body": {
      "body": {
        "content": "Hello World"
      }
    },
    "headers": {
      "Content-Type": "application/json"
    }
  }
]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM