How to save Json api respont to datatable (Invoke Code)

Hi @UnyBots

I agree with @Allan_Zimmermann suggestion.

But I solved the same thing, by converting the json to datatable direct in python. You can create a new variable “dataTable” in OpenRPA with type “System.Data.DataTable”.
Then you can import the library pandas into your code. Don’t forget to install it if needed.

I recommend you to use “newObject” as a array with key-value pairs (dictionary).

import pandas as pd

[...]
   for record in data['records']:
        newObject = {
            "key1": record['Nº de Pedido'],
            "key2": record['Título'],
            "key3": record['Requisitante'],
            "key4": record['Email'],
            "key5": record['Catálogo'],
            "key6": record['Categoria (último nível)'],
            "key7": record['Data de Criação'],
            "key8": record['Estado']
        }
        newObjects.append(newObject)

    # Create a DataFrame from the newObjects list
    df = pd.DataFrame(newObjects)

    # Convert the DataFrame to a datatable
    dataTable = df.to_dict('records')

    # Print the datatable
    print(dataTable)

After executing the code you can use the variable “dataTable” in your workflow and do whatever you need/want.
I hope this helpes you.

2 Likes