I'm developing a feature in Copilot Studio that involves dynamically constructing a JSON payload, parsing it, and sending it to an endpoint via an HTTP request. Despite the JSON being correctly parsed, the HTTP request fails with a 400 BadRequest error. I believe the way I'm constructing the JSON might be contributing to this issue. Here’s how I’m constructing the JSON and the YAML configuration generated by Copilot Studio for the HTTP request:
- kind: SetVariable
id: setVariable_XU3yK0
variable: Topic.history
value: |-
="{
history: [
{
content: " & Topic.Default & ",
type: 'default'
}
" & Global.ContextAccumulator & "
,{
content: " & System.Activity.Text & ",
type: 'latest'
}
]
}"
- kind: ParseValue
id: gSt2ro
variable: Topic.MessagesJson
valueType:
kind: Record
properties:
history:
type:
kind: Table
properties:
content: String
type: String
value: =Topic.message
HTTP Request Configuration:
- kind: HttpRequestAction
id: 6Rabc5
method: Post
url: ***
headers:
key: ***
Content-Type: application/json
body:
kind: JsonRequestContent
content: =Topic.MessagesJson
After successfully parsing the JSON without errors, the HTTP POST request configured as above results in the following error:
Error Message: HTTP request failed with status code 400 BadRequest. Error Code: HttpRequestFailure Conversation Id: ***
Context & Questions:
- I'm building this functionality in Copilot Studio, and the YAML configuration is auto-generated.
- Could the method I'm using to dynamically construct the JSON, particularly with the mix of single quotes and concatenation, be leading to a malformed JSON payload that's not evident at the parsing stage but causes the 400 BadRequest error when sent?
- Are there recommended practices or adjustments I should consider in the JSON construction phase, especially given the Copilot Studio environment, to ensure the payload is correctly formatted and accepted by the endpoint?
- What diagnostic steps can I take within Copilot Studio or the HTTP request configuration to pinpoint the exact cause of the BadRequest error?
I appreciate any insights or guidance on resolving the HTTP 400 BadRequest issue and ensuring the successful delivery of my JSON payload to the endpoint.