web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : Qg5YU2m5XUm55r1SkbdCVI
Copilot Studio - General
Unanswered

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

Like (0) ShareShare
ReportReport
Posted on 30 Mar 2024 06:44:58 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.

I have the same question (0)
  • adilei Profile Picture
    on 30 Mar 2024 at 06:52:27
    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.

  • Gosh Profile Picture
    26 on 01 Apr 2024 at 06:56:36
    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 01 Apr 2024 at 08:55:12
    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 01 Apr 2024 at 11:42:53
    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.

     

  • Gosh Profile Picture
    26 on 02 Apr 2024 at 14:33:11
    Re: Troubleshooting 400 BadRequest Error in Copilot Studio Generated HTTP Request with Custom JSON Payload

    Anything? 

  • adilei Profile Picture
    on 02 Apr 2024 at 17:20:39
    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 03 Apr 2024 at 08:04:42
    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!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Copilot Studio

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 457 Super User 2025 Season 2

#2
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 339 Super User 2025 Season 2

#3
CU15090955-0 Profile Picture

CU15090955-0 46

Last 30 days Overall leaderboard
Loading complete