Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Trying to add members to a Group using a data action/workflow

    Posted 24 days ago

    Hello, I am trying to use the API: POST /api/v2/groups/{groupId}/members. It works perfectly when only being passed one user ID but it fails when trying to add multiple User ID's. 

    The workflow would be passing it anywhere from 1-50 ID's. I tried using JsonStringify(State.MemberIDtoAdd_Array) to get the array list into one string but I cant figure out what format this API is looking for. Any help would be greatly appreciated. 

    Current Setup:

    Input:

    Config:


    #Architect
    #DataActions
    #PlatformAPI

    ------------------------------
    Connor Maxwell
    -
    ------------------------------


  • 2.  RE: Trying to add members to a Group using a data action/workflow

    Posted 24 days ago

    Olá Connor,

    No endpoint POST /api/v2/groups/{groupId}/members o corpo esperado é um array JSON de objetos, cada um com o campo id do usuário. Para múltiplos membros, o body deve ser assim:

    [ { "id": "USER_ID_1" }, { "id": "USER_ID_2" }, { "id": "USER_ID_3" } ]

    Se você enviar uma string única, ou um array de strings, ou um objeto com memberIds, o Genesys retorna erro.

    A forma mais simples de montar isso em Data Action + Workflow é:

    1. Input Contract da Data Action (exemplo)

    { "type": "object", "properties": { "groupId": { "type": "string" }, "members": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" } }, "required": ["id"] } } }, "required": ["groupId", "members"] }
    1. Request URL Template

    /api/v2/groups/${input.groupId}/members
    1. Request Body Template

    ${input.members:json}

    Observação importante: o sufixo :json instrui a Data Action a injetar o array já como JSON, sem aspas. Se você não usar :json, o payload vira string e a API falha.

    1. No Workflow (Architect)

    • Construa uma lista de String com os userIds.

    • Converta essa lista para a coleção de objetos no formato [{"id":"..."}]. Duas alternativas:

      • Já montar um JSON pronto em uma variável de fluxo e mapear para members usando tipo object collection (se estiver usando custom action com mapeamento avançado), ou

      • Transformar a lista em coleção de objetos {id:<userId>} antes de chamar a Data Action.

    • Passe essa coleção para o campo members da Data Action.

    Exemplo de Request resultante:

    [ { "id": "a1b2c3d4-..." }, { "id": "e5f6g7h8-..." } ]
    1. Erros comuns que causam falha ao enviar múltiplos:

    • Enviar algo como:

      { "memberIds": ["id1","id2"] }

      ou

      { "members": "[{\"id\":\"id1\"},{\"id\":\"id2\"}]" }

      (no segundo caso, virou string por falta do :json).

    • Esquecer Content-Type: application/json.

    • Misturar groupId de um tenant/deployment com userIds de outro ambiente.



    ------------------------------
    Fernando Sotto dos Santos
    ConsultorVIA VAREJO
    ------------------------------



  • 3.  RE: Trying to add members to a Group using a data action/workflow

    Posted 24 days ago
    Edited by Luiz Rosa 23 days ago

    Hi @Connor Maxwell,

    Well, I had this problem in the flow, and this is how it worked for me:
    Here's an example - keep in mind that it depends on your business logic and you'll need to add extra validations.


    1) Data Action:

    {
      "name": "testegroup",
      "integrationType": "purecloud-data-actions",
      "actionType": "custom",
      "config": {
        "request": {
          "requestUrlTemplate": "/api/v2/groups/${input.groupId}/members",
          "requestType": "POST",
          "headers": {},
          "requestTemplate": "${input.members}"
        },
        "response": {
          "translationMap": {},
          "translationMapDefaults": {},
          "successTemplate": "${rawResult}"
        }
      },
      "contract": {
        "input": {
          "inputSchema": {
            "type": "object",
            "properties": {
              "groupId": {
                "type": "string"
              },
              "members": {
                "type": "string"
              }
            }
          }
        },
        "output": {
          "successSchema": {
            "type": "object",
            "properties": {}
          }
        }
      },
      "
    secure": false
    }

    2) In the flow, I build the agent list and initialize the auxiliary index.



    2) I build the API body

    Update Data: The loop builds a JSON body with all member IDs.
    It starts the list, adds each member in sequence, and after finishing, calls the API with the complete body.

    Task.j == 0 ?
    "{\"memberIds\": [\"" + ToString(Task.members[Task.j]) + "\"]}" :
    Replace(Task.body, "]}", ", \"" + ToString(Task.members[Task.j]) + "\"]}")

    3) After finishing the body, I call the API.

    Example of execution:

    Hope this helps.



    ------------------------------
    Luiz Rosa
    Full stack developer
    ------------------------------