Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of a POST request as a function #134

Open
s1061429 opened this issue Feb 3, 2024 · 4 comments
Open

Example of a POST request as a function #134

s1061429 opened this issue Feb 3, 2024 · 4 comments

Comments

@s1061429
Copy link

s1061429 commented Feb 3, 2024

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!

@jekalmin
Copy link
Owner

jekalmin commented Feb 5, 2024

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}}'

@s1061429
Copy link
Author

s1061429 commented Feb 7, 2024

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.

jekalmin added a commit that referenced this issue Feb 8, 2024
[#134] Add "payload_template" in "rest" and "scrape" function
@jekalmin
Copy link
Owner

jekalmin commented Feb 8, 2024

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.

@s1061429
Copy link
Author

s1061429 commented Feb 8, 2024

Works like a charm! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants