Data Action to Create Preffered Agent List

Hello,

I'm trying to create a data action that searches for all users with a given skill and their proficiency with that skill to build and agent-pair list for preferred agent routing. We were able to get the list of users based on the skill but pulling their proficiency in that skill is eluding me. Here is the API call we are using-

/api/v2/users/search

The Request Body Template is coded like this-

{
  "sortOrder": "ASC",
  "sortBy": "id",
  "pageSize": 500,
  "pageNumber": 1,
  "expand": ["skills"],
  "query": [
    {
      "value": "${input.Skill}",
      "fields": [
        "routingSkills.name"
      ],
      "type": "EXACT"
    }

  ]
}

The Response is coded like this (which I suspect is part of the issue)-

{
  "translationMap": {
    "proficiency": "$..skills.[?(@.name==\"PSI General\")].proficiency",
    "id": "$.results[*].id"
  },
  "translationMapDefaults": {
    "proficiency": "\"[]\"",
    "id": "\"[]\""
  },
  "successTemplate": "${id}"
}

The Output Contract JSON looks like this-

{
  "type": "object",
  "properties": {
    "results": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    },
    "undefined": {
      "type": "object",
      "properties": {
        "results.skills": {
          "type": "array",
          "items": {
            "title": "proficiency",
            "type": "string"
          }
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}

And the Simple screenshot-

When I run this I get the error-

11. Validate output against schema: JSON failed output schema validation for the following reasons: instance type (array) does not match any allowed primitive type (allowed: ["object"])

I believe the error is generated due to the Response coding but in trying to correct it, I've gotten nothing to return. Any clue on how I can fix this and get it to return the userID and their Proficiency for the skill I'm searching in the API call?

Few things wrong with your contract and success template so may be easier if I show a fixed version I did on my org with my sample skill "SJB Voice skill"

Do note though you CANNOT use input variables in the translation maps, a massive hinderance, and can see that being issue with your mock up. See this idea to vote for it!

Configuration response JSON
NOTE: I had to use \ before the * in array as this reply editor drops it even in a blockquote

{
"translationMap": {
"proficiency": "$.results[*].skills[?(@.name=='SJB Voice skill')].proficiency",
"id": "$.results[*].id"
},
"translationMapDefaults": {
"proficiency": ""[]"",
"id": ""[]""
},
"successTemplate": " { "id": $id, "proficiency": $proficiency }"
}

The Output contract

{
"title": "response",
"type": "object",
"properties": {
"id": {
"type": "array",
"items": {
"title": "Item",
"type": "string"
}
},
"proficiency": {
"type": "array",
"items": {
"title": "item",
"type": "number"
}
}
},
"additionalProperties": true
}

Better in pictures
image

NOTE: The output order may not match the JSON input, when I checked though the id and proficiency level matched the entries in the response result.

Result portion, the other 2 off screen

I think that is what you were after?

Thank you for the assistance, @SimonBrown!

I'm fairly new to JSON outside of parsing results and pulling data so I figured it was something with the way I was trying to set up the Configuration Response JSON. I had found another topic stating the input variables can't be used in the translation maps. I'll see if I can get my team to upvote the idea.

When I copy/pasted this in and adjusted the skill name to our skill, I still get errors. You'd mentioned that you had to put the \ in front of the * array but I must be implementing that wrong because then I get a 'bad string' error.

Could you possibly put the code in Preformatted Text?

Response block again, didn't notice it messed up!

{
  "translationMap": {
    "proficiency": "$.results[*].skills[?(@.name=='SJB Voice skill')].proficiency",
    "id": "$.results[*].id"
  },
  "translationMapDefaults": {
    "proficiency": "\"[]\"",
    "id": "\"[]\""
  },
  "successTemplate": " { \"id\": $id, \"proficiency\": $proficiency }"
}

Thank you! Now I see where I went wrong!

I wasn't aware that it required the "" before the arrays in the success template but I guess that makes sense. And my Schema was completely wrong. I've learned a lot from this, I appreciate you taking the time.

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