extended_openai_conversation icon indicating copy to clipboard operation
extended_openai_conversation copied to clipboard

Example of a POST request as a function

Open s1061429 opened this issue 1 year ago • 4 comments

Thanks for this great project! I am trying to do a POST request as a function, but can you provide an example of how to do this? Thanks!

s1061429 avatar Feb 03 '24 19:02 s1061429

For rest type, schema is same as REST in Home Assistant. The difference is that value_template is added in this integration, so that you can modify API result.

Form data

- spec:
    name: get_your_data
    description: Get your data
    parameters:
      type: object
      properties:
        dummy:
          type: string
          description: Nothing.
  function:
    type: rest
    method: POST
    resource: "https://YOUR_POST_API"
    payload: "foo=foo&bar=bar"
    headers:
      "Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
    value_template: '{{value_json}}'

JSON

- spec:
    name: get_your_data
    description: Get your data
    parameters:
      type: object
      properties:
        dummy:
          type: string
          description: Nothing.
  function:
    type: rest
    method: POST
    resource: "https://YOUR_POST_API"
    payload: >-
      {"foo": "foo", "bar": "bar"}
    headers:
      "Content-Type": "application/json; charset=utf-8"
    value_template: '{{value_json}}'

jekalmin avatar Feb 05 '24 17:02 jekalmin

Thanks! So in that case no templating is available for the payload? Like

- spec:
    name: get_your_data
    description: Get your data
    parameters:
      type: object
      properties:
        foo:
          type: string
          description: Some interesting payload variable.
  function:
    type: rest
    method: POST
    resource: "https://YOUR_POST_API"
    payload: >-
      {"foo": "{{foo}}", "bar": "bar"}
    headers:
      "Content-Type": "application/json; charset=utf-8"
    value_template: '{{value_json}}'

This would be nice to have.

s1061429 avatar Feb 07 '24 18:02 s1061429

I just realized that rest and scrape of HA doesn't support payload as a template.

I added payload_template variable in rest and scrape function. Please try 1.0.3-beta1 version and give a feedback.

jekalmin avatar Feb 08 '24 11:02 jekalmin

Works like a charm! Thanks a lot!

s1061429 avatar Feb 08 '24 18:02 s1061429

Closing the issue.

jekalmin avatar Dec 01 '24 15:12 jekalmin