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 appreciate any insights or guidance on resolving the HTTP 400 BadRequest issue and ensuring the successful delivery of my JSON payload to the endpoint.
Hi adilei.
1. In the SetVariable activity, I'm constructing a string representation of my json payload.
2. Then in the second step I'm trying to convert this string into a variable named Topic.MessagesJson of type Record.
3. Finally I'm sending this Record (assuming that it's a Json) with the HttpRequest activity.
Unfortunately the test that I've done proved that this is not working approach and the body is None.
The question is : how to dynamically construct the json payload correctly and send send it?
Hope it's clear now.
Thank you once again for the effort!
I'm sorry but I'm not following. You mean when you try to parse the APIs response the body is empty?
Anything?
Hi and thanks for your help.
I did what you suggested - created a simple app to play with the httpRequest.
it seem that when I put a json like this:
I got the result successfully :
But when I want to assign it to the parsed variable the body is None.
There is no error.
What do you mean "in your context"? Populate the payload dynamically? You already seem to be doing that.
Sorry. I forgot to mention that I've already send a successful request with hardcoded json payload. And I got my result. The problem is : how to construct the json in my context?
Try sending the payload to an endpoint you can listen to. Either your own custom endpoint or any mock API service.
Pablo Roldan
49
Romain The Low-Code...
40
stampcoin
10