Data action to search PureCloud user by phone number

Hi. Have anyone created data action to search PureCloud user by phone number?

You can use POST /api/v2/users/search with a request like the one below to search for users by phone numbers. You can also search primaryContactInfo.voice if you want to limit it to those fields.

{
	"pageSize": 25,
	"pageNumber": 1,
	"query": [{
		"type": "CONTAINS",
		"fields": ["addresses.voice"],
		"value": "13175551000"
	}]
}

Thanks Tim. The API endpoint is good but I have issues setting up the data action. Can you please help?

" 8. 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: {"status":415,"code":"unsupported media type","message":"HTTP 415 Unsupported Media Type","contextId":"d8c79d82-13fa-4ca8-8a20-2d26b9ed192c","details":[],"errors":[]} [f769cbe8-ca0a-4c2e-9b8d-865d28932eb9]"

Input Contract:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "UserIdRequest",
"description": "ANI search.",
"type": "object",
"properties": {
"address": {
"description": "The ANI.",
"type": "string"
}
},
"additionalProperties": true
}

Output contract: (just try to pull total for testing)
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"total"
],
"properties": {
"total": {
"type": "string"
}
},
"additionalProperties": true
}

Request:
{
"requestUrlTemplate": "/api/v2/users/search",
"requestType": "POST",
"headers": {
"UserAgent": "PureCloudIntegrations/1.0",
"Content-Type": "application/x-www-form-urlencoded"
},
"requestTemplate": "{\n\t"pageSize": 25,\n\t"pageNumber": 1,\n\t"query": [{\n\t\t"type": "CONTAINS",\n\t\t"fields": ["addresses.voice"],\n\t\t"value": "${input.address}"\n\t}]\n}"
}

Response:
{
"translationMap": {
"total": ".total" }, "translationMapDefaults": {}, "successTemplate": "{\n \"total\": {total}\n}"
}

Oh I found I put in the wrong content type. It should be "Content-Type": "application/json"

Now I ran into another issue. For the response, if there is no record found, it threw an error. How should I address it?

{
"translationMap": {
"name": ".results[0].name" }, "translationMapDefaults": {}, "successTemplate": "{\n \"name\": {name}\n}"
}

Hi wu_edward,

You have a couple of choices for how to handle this situation. The approach I would generally take is that the data action taking the error path indicates that the user couldn't be found for whatever reason, so proceed without it.

If you want to be able to differentiate "User couldn't be found" from "Data action had an error" you could use the translationMapDefaults configuration area to set a default value for name. You would then need ensure that your success path does the right thing if the data action returned the default value for the name.

Translation map defaults are shown here:


--Jason

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.