How make a comparison in Google Workflows from a received token in a http.call (get)

Viewed 638

I've got a simple Cloud Function that responds with either:

{"pasValidate":true} or {"pasValidate":false}

I need Cloud Workflows to correctly compare between true and false to take the correct route. I've tried quotes, no quotes, the only part in the documentation is that the variable must be referenced through the "body" part of the response and then use it (really, nothing else in the docs) so this is what I did:

- getData:
        call: http.get
        args:
            url: https://us-central1-ACCOUNT.cloudfunctions.net/Cloud_Function
        result: jsonResponse
  - evaluateRes:
        switch:
         - condition: $(jsonResponse.body.pasValidate == "true")
           next: logStep1
         - condition: $(jsonResponse.body.pasValidate == "false")
           assign:
            - failLvl: "step1"
           next: endFail

After all of this I got the following fail run response:

in step "evaluateRes": {"message":"TypeError: in conditional predicate: expected boolean, got str","tags":["TypeError"]}

I understand that it is getting a string instead of the desired True/False, but at this point, I am daring to ask the community what am I a missing. Perhaps there's something simpler that I am not catching.

Sources:

1 Answers

First, make sure that the response of your function is application/json. You can do so by setting a response header to application/json. For example:

res.setHeader("Content-Type", "application/json");

You may encounter parsing issues if not done, as noted:

When a response of type application/json is stored in a variable, the JSON response is converted to a dictionary you access as a response body. Workflows includes a built-in parser for accessing this data.

Next, use curly braces {} instead of parenthesis () when using a switch block. Remove the double quotes on the boolean values as well.

switch:
    - condition: ${jsonResponse.body.pasValidate == true}
      next: logStep1
    - condition: ${jsonResponse.body.pasValidate == false}
      assign:
      - failLvl: "step1"
      next: endFail
Related