Skip to main content

Notifications

Community site session details

Community site session details

Session Id : K3Cj98DioyOLBYIVA5YaME
Copilot Studio - General
Answered

How to Send a Variable to an HTTP Post Request in AI Copilot Studio

Like (0) ShareShare
ReportReport
Posted on 28 Nov 2023 04:48:38 by 6

I am attempting to send the contents of a variable, timecode_val, in the body to an HTTP service using AI Copilot Studio. The HTTP service takes JSON as input. I have created a topic with a trigger containing phrases setting an Entity, Timecode, as the first step. In the second step, I'm setting the contents of a variable, timecode_val to the entity, Timecode. In the third step, I attempt to call an HTTP Request with the following body, but I keep receiving an unknown error in the body of the script. 

 

{
 "timecode": @{variables('timecode_val')}
}

Unfortunately, the online help doesn't cover the case of sending JSON variables. Perform HTTP requests - Microsoft Copilot Studio | Microsoft Learn 

 

Might anyone know how to send a variable to an http post service using JSON format in AI Copilot Studio? 

 

Screenshot of http request properties panel below.

billbaer_0-1701146634774.png

billbaer_1-1701146686284.png

 

Categories:
  • kush-sg Profile Picture
    on 27 May 2024 at 06:01:43
    Re: How to Send a Variable to an HTTP Post Request in AI Copilot Studio

    I got the correct solution for this - 
    To add a variable to the content of JSON select JSON as the Body format and switch to the Formula Tab. You can then enter JSON strings as literals and access the variable using Topic.Var1. When entering the JSON note that the tags don't need double or single quotes. Just the values.  Power FX will convert that to valid JSON with the variable value.


    kushsg_2-1716789636416.png

    pass for variable as - Topic.<<Variablename>>
    example - Topic.Var1



    Thanks

     

  • kush-sg Profile Picture
    on 26 May 2024 at 04:10:24
    Re: How to Send a Variable to an HTTP Post Request in AI Copilot Studio

    Hello, @HenryJammes 

    I am experiencing an issue with passing user input (variable) in the body of an HTTP POST request in CoPilot Studio. Attached are screenshots illustrating the problem.

    Could you please help me resolve this issue?

    Thank you.

    Best regards,
    Kushagra Sharma

    Variable (Var1), that i want to pass inside HTTP post payloadVariable (Var1), that i want to pass inside HTTP post payload

     

    HTTP - Post request payloadHTTP - Post request payload

     

    OutputOutput

     

  • Surlig1213 Profile Picture
    18 on 21 Mar 2024 at 06:03:36
    Re: How to Send a Variable to an HTTP Post Request in AI Copilot Studio

    and I try to use the following FX 

    {
    messages: [
    {
    role: "system",
    content: "prompt string."
    },
    {
    role: "user",
    content: "Topic.UserPrompt"
    },
    {
    role: "assistant",
    content: Topic.UserPrompt
    }
    ],
    max_tokens: 1500,
    temperature: 0.2,
    frequency_penalty: 0,
    presence_penalty: 0,
    top_p: 0.95,
    stop:
    }
    And got 
    Unexpected characters. Characters are used in the formula in an unexpected way.
    Unexpected characters. The formula contains 'Eof' where 'CurlyClose' is expected.
  • Surlig1213 Profile Picture
    18 on 21 Mar 2024 at 05:52:51
    Re: How to Send a Variable to an HTTP Post Request in AI Copilot Studio

    Dear @HenryJammes  , I got the same question with @sgupt187 
    I need use My own LLM to answer user's question. And I don't like get response via Power automate HTTP Action, cause 2min timeout limit.

    So I plan to use HTTP POST in topic to get my own LLM(fine-tuned) response and answer user's question.
    My question is How to send Var like Activity.Text in JSON content along with my prompt
    {
    "messages": [
    {
    "role": "system",
    "content": "My sys prompt." #my sys prompt string
    },
    {
    "role": "user",
    "content": "Var in Copilot studio" # here, I need Var like Activity.Text. how to do that?
    },
    {
    "role": "assistant",
    "content": ""
    }
    ],
    "max_tokens": 1500,
    "temperature": 0.2,
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "top_p": 0.95,
    "stop": null
    }

  • sgupt187 Profile Picture
    19 on 28 Feb 2024 at 05:32:37
    Re: How to Send a Variable to an HTTP Post Request in AI Copilot Studio

    I want to send Activity.Text in JSON content along with my prompt, but it is not working.

    {
    "prompt": "Generate a response based on the user query present in Activity.Text."
    }

    Can anyone tell me a way so that I can achieve it?
    Is there any way where the user query can be passed into a variable in the body of the HTTP Request feature of Microsoft Copilot Studio along with some other JSON content ?

  • billbaer Profile Picture
    6 on 28 Nov 2023 at 18:39:51
    Re: How to Send a Variable to an HTTP Post Request in AI Copilot Studio

    Thanks, Henry. That fixed that issue. You rock.

  • Verified answer
    HenryJammes Profile Picture
    on 28 Nov 2023 at 12:35:53
    Re: How to Send a Variable to an HTTP Post Request in AI Copilot Studio

    Hi @billbaer 

     

    Can you switch your HTTP Request body from JSON for formula? (your endpoint will still receive JSON).

    That way you can send this:

     

    {
     timecode: Topic.timecode_val
    }

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,700 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard
Loading started