数据操作的 URI (URL) 形式编码

注意: 本文适用于 Genesys Cloud、Google、Microsoft Dynamics 365、Salesforce、Web 服务和 Zendesk 数据操作集成。

某些 API,尤其是登录 API,需要对 HTTP 请求进行 URL 形式编码。 要配置 URI 编码的 Genesys Cloud 数据操作:

  1. Create a Content-Type request header with the value x-www-form-urlencoded.

  2. Set the Request Body Template in the UI, or requestTemplate in JSON or Terraform with the parameters as key-value pairs separated by ampersand (&). For example, key1=value1&key2=value2.

    注意: 请求正文不是 JSON,它是一个格式化为 URL 查询参数的字符串。

  3. Use $esc.uriEncode() around values or variables that contain any URL reserved characters, such as / ? : @ – . _ ! ~ $ & ‘ ( ) * + , ; =.

json 示例

"config": { 
     "request": { 
          "requestTemplate": "grant_type=client_credentials&scope=customers_read_write&audience=$esc.uriEncode(\"https://api.example.com/v1/customers\")", 
          "headers": { 
               "Authentication": "Basic $encoding.base64(\"${credentials.clientid}:${credentials.clientSecret}\"", 
               "Content-Type": "application/x-www-form-urlencoded" 
               },
          "requestType": "POST", 
          "requestUrlTemplate": "${credentials.loginUrl}" 
       } 
   } 

以下示例显示了具有保留字符的用户输入值:

"config": {
	"request": {
		"headers": {
			"Content-Type": "application/x-www-form-urlencoded"
		},
		"requestUrlTemplate": "https://api.example.com/v1/customers",
		"requestTemplate": "description=$esc.uriEncode(\"${input.DESCRIPTION}\")&email=$esc.uriEncode(\"${input.EMAIL}\")",
		"requestType": "POST"
	}
}
Note: To protect from injection attacks, always use the $esc.uriEncode() function with the user input. Because the data actions cannot automatically escape the user input with special characters, you have to use the function where applicable for security purposes. Though the data comes from an entity that is invoked includes Architect or Script, escaping must be done when handling the URLs and URL forms.

有关集成的更多信息,请参阅 关于数据操作集成