Skip to main content

Notifications

Announcements

No record found.

Power Platform Community / Forums / General / How to dynamically con...
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

Categories:
  • 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

Exciting News for Copilot Studio Communi…

Get ready to experience a whole new level of engagement with the Copilot Studio…

Celebrating the May Super User of the…

LaurensM is an exceptional contributor to the Power Platform Community…

Check out the Copilot Studio Cookbook…

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

Leaderboard

#1
renatoromao Profile Picture

renatoromao 6,459

#2
Pstork1 Profile Picture

Pstork1 1,954

#3
Expiscornovus Profile Picture

Expiscornovus 1,648