Help with a workflow

Describe the problem/error/question

I have build a webform on webflow, it will lookup a stock symbol via TD Ameritrade’s API. I created a webhook that listens to the webflow form (or I should say it post to it). I get the data just fine and I’m able to lookup the stock (see screenshots). However, when it returns the object it does so by put it into an array with the stock symbol name, this causes problems for me when I try to execute a sql query to postgres because it uses the stock symbol in the middle of it and since each time it could be a new stock the query isn’t dynamic (see below)

Example : =INSERT INTO product_data.stock_picker (created_date, symbol,description)
VALUES(‘{{$now.toFormat(‘yyyy-MM-dd’)}}’,‘{{ $json.AMD.symbol}}’,‘{{ $json.AMD.description}}’,)
RETURNING id;

What is the error message (if any)?

This causes problems next time I look up another stock such as TSLA, it tries to use the same query but it wont work since it uses AMD in the query and now the objects are under TSLA

Please share your workflow

Webhook

  "meta": {
    "instanceId": "ee41659ce8187bdd3290300ba797a7c71a64cf3a2f774cc5e225a57bd807efc5"
  },
  "nodes": [],
  "connections": {}
}

**crypto node (to random a id uuid)**
{
  "meta": {
    "instanceId": "ee41659ce8187bdd3290300ba797a7c71a64cf3a2f774cc5e225a57bd807efc5"
  },
  "nodes": [
    {
      "parameters": {
        "action": "generate",
        "dataPropertyName": "id"
      },
      "id": "634ed391-045c-4c10-baae-b9250e7d38ee",
      "name": "Crypto",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        240,
        1220
      ]
    }
  ],
  "connections": {}
}

**TD lookup node:**
{
  "meta": {
    "instanceId": "ee41659ce8187bdd3290300ba797a7c71a64cf3a2f774cc5e225a57bd807efc5"
  },
  "nodes": [
    {
      "parameters": {
        "url": "=https://api.tdameritrade.com/v1/marketdata/quotes",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ $json.body.data.Stock }}"
            }
          ]
        },
        "options": {}
      },
      "id": "cf41b75c-a51f-47ee-9671-599d599dd19f",
      "name": "TDLookUp",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        480,
        1220
      ],
      "credentials": {
        "httpQueryAuth": {
          "id": "FWvBYzzdsCuXRwjc",
          "name": "MoSoG TD Ameritrade API Key"
        }
      }
    }
  ],
  "connections": {}
}


**Postgres node**
{
  "meta": {
    "instanceId": "ee41659ce8187bdd3290300ba797a7c71a64cf3a2f774cc5e225a57bd807efc5"
  },
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO product_data.stock_picker (created_date, symbol,description)\nVALUES('{{$now.toFormat('yyyy-MM-dd')}}','{{ $json.AMD.symbol}}','{{ $json.AMD.description}}',)\nRETURNING id;",
        "options": {}
      },
      "id": "f69d98fa-f377-4166-98e9-dba62a8cc35d",
      "name": "Postgres1",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.3,
      "position": [
        740,
        1220
      ],
      "credentials": {
        "postgres": {
          "id": "S3yzBHneiKtfh6ne",
          "name": "MoSoG DO - Prod - Connection Pool"
        }
      }
    }
  ],
  "connections": {}
}

![stock-picker#1|690x274](upload://nkTtuA0ipwcgYgJXD7l1BWRQIMj.png)
![stock-picker#2|690x339](upload://4L38QkfwPojPMTCAuqgutHQ3I28.png)


N8N version: 1.8.2

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @mosog,

Would you be able to share the full worklfow as it is hard to work out what you are doing from the small snippets you have provided. It looks like there was possibly meant to be some images as well which are not loading becuase of the formatting.

Sure, I tried doing that my doing a copy and past.

Does this work? I tried to upload pictures but it doesn’t seem to work. I selected to upload pictures but it doesn’t seem to format it correctly.

Trying to past in the images here to see if it works.

Perfect thanks, So it looks like the API will be returning TSLA as the data key for the response and we are using that so I suspect the issue is that $json.TSLA won’t always be the value you need so instead it might be worth trying something crazy like…

{{ $json[$('Crypto').item.json.body.data.Stock.toUppercase()].askPrice }} and see if that works.

Jon, thank you, where would I put this code? I also see that my screenshot was pasted twice, here is the 2nd picture that shows it a bit more.

I tried to do this but it didn’t work.

Is there a way to use a SET node to change the object name seen in the picture below so that it doesn’t put the objects under a stock symbol name but instead in a generic name?

Here is what I’m trying to do but I can’t get the right array index

Still can’t solve this issue, not sure how to get around it.

Hey @mosog,

What happened when you tried what I suggested?

I ended up getting the same error, however, I created a new post after I reworked some stuff and I got someone to provide me with the following workflow that ended up working great.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.