Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Copilot Studio - General
Unanswered

Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

(0) ShareShare
ReportReport
Posted on by 26

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.

  • Gosh Profile Picture
    26 on at
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    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!

  • adilei Profile Picture
    on at
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    I'm sorry but I'm not following. You mean when you try to parse the APIs response the body is empty? 

  • Gosh Profile Picture
    26 on at
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    Anything? 

  • Gosh Profile Picture
    26 on at
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    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: 

    Gosh_0-1711971578760.png

    I got the result successfully :

    Gosh_1-1711971713152.png

    But when I want to assign it to the parsed variable the body is None.

     

    There is no error.

     

  • adilei Profile Picture
    on at
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    What do you mean "in your context"? Populate the payload dynamically? You already seem to be doing that.

  • Gosh Profile Picture
    26 on at
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    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?

  • adilei Profile Picture
    on at
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    Try sending the payload to an endpoint you can listen to. Either your own custom endpoint or any mock API service.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Copilot Studio - General

#1
Pablo Roldan Profile Picture

Pablo Roldan 49

#2
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 40

#3
stampcoin Profile Picture

stampcoin 10

Overall leaderboard