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

Data from rest_command appears double #145

Open
KTHconsult opened this issue Oct 9, 2024 · 2 comments
Open

Data from rest_command appears double #145

KTHconsult opened this issue Oct 9, 2024 · 2 comments

Comments

@KTHconsult
Copy link

Im using the rest_command to get a json data array. Rest_command add this response to a dictionary where data as json is kept in the item called content alongside the item status that has the response status code.
For easy reproduction i added a script with hardcoded result that shows the issue.

Flex Table Card configuration

type: custom:flex-table-card
title: Recipes from script
service: script.recipes
entities: []
columns:
  - name: Id
    data: content
    modify: x.id
  - name: Name
    data: content
    modify: x.name

Output from flex-table-card

Recipes from script

Id | Name

1 | Production Sprint of Painkiller Syringe
2 | Final Sprint of Association Council
3 | Final Testing of Association Syringe
1 | Production Sprint of Painkiller Syringe
2 | Final Sprint of Association Council
3 | Final Testing of Association Syringe

I would expect to only see 3 rows instead of 6

Script that reproduces rest_command wrapping logic

alias: Recipes
sequence:
  - variables:
      recipes: |
        {% set myrecipes = {"content": [ 
          {
            "name": "Production Sprint of Painkiller Syringe",
            "description": "a",
            "id": 1,
            "created": "2024-09-30T09:15:19.203"
          },
          {
            "name": "Final Sprint of Association Council",
            "description": "b",
            "id": 2,
            "created": "2024-09-30T09:15:19.417"
          },
          {
            "name": "Final Testing of Association Syringe",
            "description": "c",
            "id": 3,
            "created": "2024-09-30T09:15:19.64"
          }
        ] , "status":200} %} {{ myrecipes }}
  - stop: All done
    response_variable: recipes

Result from rest_command action

content:
  - name: Production Sprint of Painkiller Syringe
    description: >-
      a
    id: 1
    created: "2024-09-30T09:15:19.203"
  - name: Final Sprint of Association Council
    description: >-
      b
    id: 2
    created: "2024-09-30T09:15:19.417"
  - name: Final Testing of Association Syringe
    description: >-
      c
    id: 3
    created: "2024-09-30T09:15:19.64"
status: 200

How can I configure the flex-table-card to only render 3 rows and thereby reflect the actual data result from the content section?

@EdLeckert
Copy link
Contributor

EdLeckert commented Oct 13, 2024

The logic normally used to iterate on entities is looping on the two top-level keys in the response: content and status.

The , "status":200 is what's causing the duplication, so you'll need to find a way to remove it.

@EdLeckert
Copy link
Contributor

You could use a script like this to strip the status from the response:

call_recipes:
  alias: Call Recipes
  sequence:
    - action: script.recipes
      response_variable: rest_response
    - variables:
        correct_reponse: >
          {{ { "content" : rest_response["content"] } }}
    - stop: All done
      response_variable: correct_reponse

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

No branches or pull requests

2 participants