0

Using ActiveCampain work flows, I have a pipeline in which I want to execute code conditionally based on the output of a jq command.

For example, I want to execute and !http and !jq command if .status == "event-created".

JSON

{
    "id":1,
    "firstname": "Nj",
    "lastname": "Bhanushali",  
    "email": "test@test.com",  
    "title":"Call with new lead",
    "status":"event-created" 
}

Code

"!pipe": [
    {
        "!jq": ".status"
    },  
    //call this jq if .status == "event-created" 
    {
        "!http": {
            "method": "GET",
            "path": "/contact/fields"
        }
    },
    {
        "!jq": "${piped_content::1}"
    },
]
4

1 回答 1

1

A quick look at the docs suggest there's a !switch "command" you can use.

{
  "!switch": {
    "jq": "if .status == \"event-created\" then 0 else 1 end",
    "cases": [
      {
        "!pipe": [
          {
            "!http": {
              "method": "GET",
              "path": "/contact/fields"
            }
          },
          {
            "!jq": "${piped_content::1}"
          }
        ]
      },
      {
      }
    ]
  }
}

Notes:

  • I don't know if it's acceptable to have an empty hash for one of the cases. Maybe you have to use null? Maybe you have to omit it? If you omit it, maybe you have to use if .status == "event-created" then 0 else empty end? If that works, that would be the cleanest solution. Adjust as necessary.

  • I don't know if ${piped_content::1} is still correct with the changes I've made. Adjust as necessary.

于 2022-03-02T21:16:40.687 回答