Skip to main content

Notifications

Copilot Studio - General
Answered

How to dynamically construct the json payload correctly and send send it with HTTP Request

Posted on by 26

I want to construct a json object in my Copilot chat bot (former PVA) with the following structure:

 

 

{

 "messages": [
 {
 "role": "bot",
 "content": "message1"
 },
 {
 "role": "user",
 "content": "message2"
 }
 ]
}

 

The tricky part is that I want the strings message1 and message2 to be read from variables.

 

I tried to create a string and then parse it to json with a schema, but I had no luck with that.

 

I'll appreciate any suggestions and recommendations. 

Thanks in advance

  • Gosh Profile Picture
    Gosh 26 on at
    Re: How to dynamically construct the json payload correctly and send send it with HTTP Request

    Hi, Thank you for the response, but the problem I want to solve is vice versa. I need to get the value from a variable and apply it on the json object. 
    best regards

  • Verified answer
    Re: How to dynamically construct the json payload correctly and send send it with HTTP Request

    Hi @Gosh ,

     

    I've made a test for your reference:

    1\Add a 'Parse value' and set data type to 'From sample data'

    vbofengmsft_0-1712567966641.png

    2\Get schema form sample JSON

    vbofengmsft_1-1712567995942.png

    vbofengmsft_2-1712568021346.png

    Result

    vbofengmsft_4-1712568195825.png

     

    3\Get first message

    First(Topic.Var1.messages).content

    vbofengmsft_3-1712568073274.png

    4\Get last message

    Last(Topic.Var1.messages).content

     

    Best Regards,

    Bof

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Getting Started…

Welcome to the Power Platform Community! We appreciate your visit…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 138,287

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,172

Leaderboard