Terraform Plan - Data Action Parameter Encoding Issue

The terraform plan consistently fails when deploying Data Actions with complex parameter values - specifically, those containing ampersands (&) or plus signs (+). It appears the parameter encoding isn’t being handled correctly during the API call to update the data action parameters. We’re on the Great Cloud, naturally.

Initially, the assumption was a simple URL encoding problem, yet the Terraform provider doesn’t seem to be applying appropriate encoding for these characters before submitting the request. The error returned from the API is a 400 Bad Request with a message indicating invalid parameter format. I’ve checked the workflow YAML; it’s a standard parameter definition.

The API expects URL-encoded parameters - Terraform isn’t doing that for you. Try pre-encoding the values with the encodeURIComponent() function in a data action before passing them to the Data Action API - something like encodeURIComponent("+") becomes %2B. We ran into this last year during the historical export when we were passing query parameters to a webhook; it’s a mess.

4 Likes

Okay, that’s right - the API expects URL encoding, and Terraform isn’t doing it for you automatically. We hit something similar when we were migrating our Zendesk ticket comments over - they didn’t encode properly, and everything was getting garbled in the interaction history. A workaround we used, before we could get the encoding fixed in the data action, was to pre-encode the values in a separate data action step, using a simple JavaScript block to call encodeURIComponent() on the parameter before it’s passed along - it’s a bit clunky, but it’ll get you through while you’re debugging.

That’s right, the API expects URL encoding, and it’s easy to overlook when you’re building things out in Terraform. We ran into something similar last year when we were integrating with a third-party WEM system - the data payloads weren’t being passed correctly due to character encoding issues.

Could you clarify if you’re passing these parameters directly within the Terraform configuration or are you constructing them dynamically using a data action? Understanding the flow would help narrow down where the encoding needs to happen. It’s also worth checking whether the data action itself has any inherent encoding settings that might be interfering with the process.

{
 "action": "data_action_test",
 "url": "the Data Action endpoint",
 "method": "POST",
 "body": {
 "parameterName": "test_param",
 "parameterValue": "{{encodeURIComponent('+')}}"
 }
}

sorry for the newbie question, but we had the same issue. The documentation says the API expects URL encoding, and Terraform doesn’t do it. We use a Data Action before the Data Action call to encode the parameter values.

It’s a bit messy - we first map the value to a slot, then use this action to encode it:

{
 "action": "map_slots",
 "target": "encoded_value",
 "source": "{{slot.original_value}}"
}

then, we call another Data Action to encode it.

{
 "action": "execute_javascript",
 "script": "encodeURIComponent({{slot.original_value}})"
}

and map the result to a new slot. After that, we pass the new slot value to the API.

it’s not ideal - a lot of actions - but it works. I think you can also do the encoding in Terraform with a local variable, but we are not very good at Terraform so we do it in the Dialog Engine.