Branch if statement help: Cannot read properties of undefined
I have a Rest API Call node at the top of my workflow. It has a query param called "api_key". For the next node, I have a branch node. I thought it would be simple to have an "if" statement with the branch.
So, in the branch node, I have this code: ctx["root"]["request"]["query"].api_key == '12345'
Then, on the true branch, I go ahead and run my next bit of code. On the false branch, I just return a message.
No matter what I do, I can't get a simple if statement to work. It says it is a javascript so I have tried to do a simple if statement in JS as well:
if (ctx["root"]["request"]["query"].api_key == 'HRauoD4QypplwAfiev7NnSeITtbIiMXX') {
return true;
} else {
return false;
}
But, that just returns an error as well. This is very confusing for a simple branch node. But, nothing seems to be working? What am I doing wrong here?
So, in the branch node, I have this code: ctx["root"]["request"]["query"].api_key == '12345'
Then, on the true branch, I go ahead and run my next bit of code. On the false branch, I just return a message.
No matter what I do, I can't get a simple if statement to work. It says it is a javascript so I have tried to do a simple if statement in JS as well:
if (ctx["root"]["request"]["query"].api_key == 'HRauoD4QypplwAfiev7NnSeITtbIiMXX') {
return true;
} else {
return false;
}
But, that just returns an error as well. This is very confusing for a simple branch node. But, nothing seems to be working? What am I doing wrong here?

Solution
@macphreak
The are a couple of issues in your workflow you submitted:
1. You are matching the condition to the wrong value due to which it is failing, the request header should match the value to which you are comparing. For example, if your request header is 123 then the match condition should be: (refer to the image below).
image.png
2. Also adding a field in the inputs won't have any effect, you'll be required to add the query or body in the Request object, to learn more about how to use REST API Trigger - https://docs.buildship.com/trigger-nodes/rest-api and API call methods you can refer to this documentation - https://docs.buildship.com/basics/ship-an-api.
I've sent you an email with the fixed workflow. You can followup on the email.
The are a couple of issues in your workflow you submitted:
1. You are matching the condition to the wrong value due to which it is failing, the request header should match the value to which you are comparing. For example, if your request header is 123 then the match condition should be: (refer to the image below).
image.png
2. Also adding a field in the inputs won't have any effect, you'll be required to add the query or body in the Request object, to learn more about how to use REST API Trigger - https://docs.buildship.com/trigger-nodes/rest-api and API call methods you can refer to this documentation - https://docs.buildship.com/basics/ship-an-api.
I've sent you an email with the fixed workflow. You can followup on the email.
