Set query parameter to default if not set by URL

HI

want to get from a mysql DB the list of entries when the ID is not part of the URL. IT works, but I think I make it too complicated …

https://n8n_web.domain.test/webhook/SQMS/TOPIC/READ
https://n8n_web.domain.test/webhook/SQMS/TOPIC/READ?topic_id=12

webhook → if topic_id is empty
→ True - Mysql node SELECT * FROM sqms_topic;
→ False - Mysql node SELECT * FROM sqms_topic where sqms_topic_id = {{$json[“query”][“topic_id”]}};

Then I make two identical calls (for each path) to a translation API

There must be a smarter way … can someone help me?

  1. Do I really need 2 mysql and 2 http query nodes or can I send the query dynamically depending on topic_id is sent or not?
  2. I tried to add a merge node after the 2 sql calls but I could only add 1 http request but I failed …
  3. the http request node returns only the last result - how can I merge the sql query result and the translation result?

Thanks - this is my first more complex workflow-
rob

Hey @ico,

  1. Do I really need 2 mysql and 2 http query nodes or can I send the query dynamically depending on topic_id is sent or not?

I would use two different nodes like the way you did. This allows me to understand the data flow in the workflow better. This approach will also make debugging easy.

  1. I tried to add a merge node after the 2 sql calls but I could only add 1 http request but I failed

You can connect only one node to the output of the Merge node. Do you really need two different HTTP Request nodes? Looking at your workflow, both the nodes are identical. Did you try with a single node? Can you share what error you get, if any?

    1. the http request node returns only the last result - how can I merge the sql query result and the translation result?

Can you share some more information here? If the MySQL node returns 10 items, the HTTP Request node will process these 10 items and return you 10 translations.
You can use the Set node or the Function node to merge the outputs from the SQL Query node and the translation node.

Hi & Thanks

  1. ok make sense
  2. have one http request node without merge node - it is so easy - just did not think about it
  3. from mysql node i get back
[
    {
    "sqms_topic_id": 1,
    "name": "Topic with ID [1]",
    "sqms_role_id": 2
    },{...}, 
    {
    "sqms_topic_id": 19,
    "name": "Topic with ID [19]",
    "sqms_role_id": 6
    }
]

from the translate node I get back

[
    {
    "source_text": "Topic with ID [1]",
    "source_lang": "EN",
    "target_text": "Tema con ID [1]",
    "target_lang": "ES"
    },
    {...},
    {
    "source_text": "Topic with ID [19]",
    "source_lang": "EN",
    "target_text": "Tema con ID [19]",
    "target_lang": "ES"
    }
]

I would like to have

[
        {
        "sqms_topic_id": 1,
    	"source_text": "Topic with ID [1]",
    	"source_lang": "EN",
    	"target_text": "Tema con ID [1]",
    	"target_lang": "ES"
        "sqms_role_id": 2
        },        {...}, 
        {
        "sqms_topic_id": 19,
        "source_text": "Topic with ID [19]",
    	"source_lang": "EN",
    	"target_text": "Tema con ID [19]",
    	"target_lang": "ES"
    	"sqms_role_id": 3
        }
]

thanks Rob

hi Harshil

Answere to 3
is this the right video to watch?
n8n Nodemation basic - transforming json (3/3) (Tutorial)

I read Key concepts | Docs
but since I’m not a programmer (only some php) I don’t know where to start … but an example is most of the time enought …

thsi could be a start - But 2 Have 2 Inputs, or?

Thanks rob

Hey Rob,

Did you try the Set node? You can specify the fields you want and only return these fields.

Since you have two SQL nodes connected to the HTTP Request node, and we need to take care of the condition when either of the nodes runs, you can add a NoOp node before the HTTP Request node. In the Set node, you can refer these values from the NoOp node.

1 Like

THANKS for your help - 1st workflow which might go to production is ready now!

3 Likes

That’s amazing! I am happy that I could help :sparkling_heart:

Have fun!

1 Like