#Tandoor rest api

1 messages · Page 1 of 1 (latest)

ebon hull
#

Hi

I would like to add items from HA to Tandoor shopping list. For this there is a Tandoor’s api.

I must make a post rest call to an end point with bearer token.

So I added a rest command to configuration.yaml but every time I tried to launch the command in the developer section of HA, I had an error 403 : CSRF verification failed. Request aborted.

I don’t find a way to pass this error.

Do you have an idea ?

Thanks for your help.

thick lodge
stray thorn
#

That seems like the reverse of what they were asking, but would work if they'd want to use Tandoor to manage instead of HA. Otherwise, you should share your rest command config.

ebon hull
thick lodge
#

And is there documentation for the API? As it does sound like the other end is rejecting it rather then a HA problem.

ebon hull
#
rest_command:
    post_tandoor_food:
        url: "http://192.:8002/api/shoppng-list-entry/"
        method: post
        headers:
            authorization: bearer tda_
            content_type: 'application/json'
        payload: '{"food"{"name":"Banane"},"amount":1}'```
stray thorn
#

You missed the i in shopping

#

Also, content_type: 'application/json' belongs up 1 level under the command name itself, not under headers

ebon hull
#

Oh thanks it works ! Don’t see the missing letter 😑

#

Do you know how to use the result of a first request in a second request ?

#

The goal is to have a list in HA and for each item of the list, make 2 api call.

ebon hull
#
rest_command:
    find_tandoor_food:
        url: "http://192…/api/ingredient-from-string/"
        method: post
        headers:
            authorization: bearer tda_
        content_type: 'application/json'
        payload: '{"text":"{{ item }}"}'

    post_tandoor_food:
        url: "http://192…/api/shopping-list-entry/"
        method: post
        headers:
            authorization: bearer tda_
        content_type: 'application/json'
        payload: '{{ item }}'```
#

Ok on my configuration.yaml I have this

#
actions:
  - action: rest_command.find_tandoor_food
    metadata: {}
    data:
      item: 25 mascarpone
    response_variable: tandoor_response
    alias: Find food in Tandoor
  - alias: If response = 200
    if:
      - condition: template
        value_template: "{{ tandoor_response['status'] == 200 }}"
        alias: "True"
    then:
      - alias: Post food in Tandoor
        action: rest_command.post_tandoor_food
        metadata: {}
        data:
          item: "{{ tandoor_response['content'] }}"
        response_variable: tandoor_response2 ```
#

This is my automation

ebon hull
#

First result give me this : {'amount': 25.0, 'unit': None, 'food': {'name': 'Mascarpone', 'id': 49}, 'note': ''}

#

Second result give me this : {'detail': 'JSON parse error - Expecting property name enclosed in double quotes: line 1 column 2 (char 1)'}

#

I guess is the way I put data in second call but I don’t find the right way to do it

torpid elbow
#
    post_tandoor_food:
        url: "http://192…/api/shopping-list-entry/"
        method: post
        headers:
            authorization: bearer tda_
        content_type: 'application/json'
        payload: '{{ item | to_json }}'
ebon hull
#

Thanks a lot it works great now !

ebon hull
#

Do you know how to foreach items in a list ?

#
actions:
  - action: todo.get_items
    metadata: {}
    data:
      status: needs_action
    target:
      entity_id: todo.shopping_list
    response_variable: shopping_list
  - repeat:
      sequence:
        - action: telegram_bot.send_message
          metadata: {}
          data:
            config_entry_id: 01K1WYNSEQPRNR86Q3H3BJK1N8
            message: Item
      for_each: shopping_list[] ```
#

When I validate it tells me :

Message malformed: template value does not contain a dynamic template for dictionary value @ data['actions'][1]['repeat']['for_each']

stray thorn