https://developer.genesys.cloud/forum/t/how-to-omit-empty-null-optional-fields/4881/3?u=jason_mathison
Original Message:
Sent: 05-09-2025 09:30
From: Robert Herms
Subject: Data action to create an external contact
Hi Jason,
ahhh YES, THANKS! It's working now :-D
May I ask you if there is any possibilty to include a check for each data set if data is provided?
So there is not every time a second or third phone numer available at the source.
If I leave the input field e.g. of Phone_Work empty (set to "not required at the input contract), I get the error:
Resolve request body template: Substitution values invalid in action config. Reference ${input.Phone_Work} evaluated to null when attempting to render at BodyTemplate[line 1, column 101] A common reason for this error is needing to prepend the variable with 'input.' or 'credentials.'
The "Resolve request body template" states:
{ "message": "Substitution values invalid in action config. Reference ${input.Phone_Work} evaluated to null when attempting to render at BodyTemplate[line 1, column 101] A common reason for this error is needing to prepend the variable with 'input.' or 'credentials.'",
"code": "invalid.substitution",
... }
THANKS!
BR, Robert
Original Message:
Sent: 05-09-2025 08:51
From: Jason Mathison
Subject: Data action to create an external contact
That you for including the whole data action. The endpoint is complaining about the content-type that is being used. The data action has this header configured:
"Content-Type": "application/x-www-form-urlencoded",
Chances are the endpoint wants the content type to be application/JSON, which is the default value. If you remove the content-type header configuration from your action I would guess that it would work.
------------------------------
--Jason
Original Message:
Sent: 05-08-2025 09:49
From: Robert Herms
Subject: Data action to create an external contact
Hi guys,
I am trying to setup a data action that is able to create an external contact.
HTTP Method: POST
Request URL Template: /api/v2/externalcontacts/contacts
Request Body Template:
{ "firstName": "${input.First_Name}", "lastName": "${input.Last_Name}", "workPhone": { "display": "${input.Phone_Work}" }, "cellPhone": { "display": "${input.Phone_Mobile}" }, "address": { "address1": "${input.Address_Street}", "city": "${input.Address_City}", "countryCode": "${input.Address_CountryCode}" } }
=> When I run a test I get an error about an unexpected condition:
Execute: The server encountered an unexpected condition which prevented it from fulfilling the request.
REST call for action execute failed. Message: Request to backend service failed. Response from web service: {"message":"HTTP 415 Unsupported Media Type","code":"unsupported media type","status":415,"contextId":"3967ff8e-7d0e-4dcd-8092-75448ab253e8","details":[],"errors":[]} [3ea83bbe-e3a1-4e17-b2a8-f229854ebb4f]
The last green check is at "Resolve request body template":
"{ \"firstName\": \"123\", \"lastName\": \"123\", \"workPhone\": { \"display\": \"+49123456\" }, \"cellPhone\": { \"display\": \"+49123456\" }, \"address\": { \"address1\": \"123\", \"city\": \"123\", \"countryCode\": \"DE\" } }"
At "Execute" I get the error:
{
"message": "The server encountered an unexpected condition which prevented it from fulfilling the request.",
"code": "internal.server.error",
"status": 500,
"messageParams": {},
"contextId": "3ea83bbe-e3a1-4e17-b2a8-f229854ebb4f",
"details": [
{
"errorCode": "ACTION.REMOTE_ENDPOINT"
}
],
"errors": [
{
"message": "REST call for action execute failed. Message: Request to backend service failed. Response from web service: {\"message\":\"HTTP 415 Unsupported Media Type\",\"code\":\"unsupported media type\",\"status\":415,\"contextId\":\"3967ff8e-7d0e-4dcd-8092-75448ab253e8\",\"details\":[],\"errors\":[]} [3ea83bbe-e3a1-4e17-b2a8-f229854ebb4f]",
"code": "INTERNAL_SERVER_ERROR",
"status": 415,
"messageParams": {},
"details": [],
"errors": []
}
]
}
I've copied the data from "Resolve request body template" to the API Explorer (without the " at the beginning and at the end) and it was working fine.
The external contact "123, 123" was created without any problem.
The complete data action as JSON looks like this:
{
"requestType": "POST",
"requestTemplate": "{ \"firstName\": \"${input.First_Name}\", \"lastName\": \"${input.Last_Name}\", \"workPhone\": { \"display\": \"${input.Phone_Work}\" }, \"cellPhone\": { \"display\": \"${input.Phone_Mobile}\" }, \"address\": { \"address1\": \"${input.Address_Street}\", \"city\": \"${input.Address_City}\", \"countryCode\": \"${input.Address_CountryCode}\" } }",
"requestUrlTemplate": "/api/v2/externalcontacts/contacts",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"UserAgent": "PureCloudIntegrations/1.0"
}
}
Does anybody see my mistake?
THANKS!!!
BR, Robert
#DataActions
#PlatformAPI