Raman Nayyar
Raman Nayyar

Reputation: 13

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:[email protected]/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.

Upvotes: 0

Views: 1333

Answers (1)

Vikrant Singh
Vikrant Singh

Reputation: 702

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:[email protected]/messages",
    "method": "POST",
    "body": {
      "body": {
        "content": "Hello World"
      }
    },
    "headers": {
      "Content-Type": "application/json"
    }
  }
]
}

Upvotes: 1

Related Questions