Genesys Cloud - Developer Community!

 View Only

Sign Up

Expand all | Collapse all

Issue with API handling multiple data inputs

  • 1.  Issue with API handling multiple data inputs

    Posted 06-02-2025 14:45

    Hello, 

    I have an API that is receiving multiple data inputs (profile ID's) and should be adding them to a gamification profile but it continues to fail. It works when only one ID is passed. 

    Here is what the data looks like when its passed to the API:

    Here is what the API looks like:

    Input Contract

    Configuration

    Is there a way for it to handle adding all the ID's?


    #PlatformAPI

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


  • 2.  RE: Issue with API handling multiple data inputs

    Posted 06-03-2025 05:20

    Hi Connor,

    I think that on you Input Schema your variables should be set to Array.

    You probably need to adjust the Request Body Template when changing the input type.



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 3.  RE: Issue with API handling multiple data inputs

    Posted 06-03-2025 08:51

    Hi Jan, 

    Thank you for your reply, I tried changing the input type to Array but I get the below error.

    I know this API can handle multiple responses based on the API explorer page:

    So I am wondering if I should be changing the formatting of the output of the previous API to match what that is looking for ^ ?



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



  • 4.  RE: Issue with API handling multiple data inputs

    Posted 06-03-2025 09:49

    Hi Connor,

    Sorry, Data Actions don't accept Array as input so had to do a test on this myself.

    How I got it to work is to have Input Contract

    {
      "type": "object",
      "properties": {
        "profileId": {
          "type": "string"
        },
        "membersToAdd": {
          "type": "string"
        }
      }
    }

    This is my Action configuration

    {
      "requestType": "POST",
      "requestTemplate": "{\n${input.membersToAdd}\n}",
      "requestUrlTemplate": "/api/v2/gamification/profiles/${input.profileId}/members",
      "headers": {}
    }

    Then when running the data action I need to provide profileId for the Gamification profile and the JSON for which members to add, so it would look something like this



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 5.  RE: Issue with API handling multiple data inputs

    Posted 06-03-2025 10:10

    Hi Jan, 

    Thank you for investigating, mine does work with that as well but when in the workflow, it fails. I think it is because the formatting of the data doesn't match what you input in your test for MemebersToAdd. Do you know how I should edit the below API to have the data output look like what you put in the test?



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



  • 6.  RE: Issue with API handling multiple data inputs

    Posted 06-03-2025 10:32

    You could save the result in a String Collection.

    Then you should be able to use an input looking something like this to add them to the Gamification profile.

    "\"membersToAdd\": " + ToString(ToJson(Flow.stringCollection))

    I would need to test the exact use case but the above should be close to the solution.



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 7.  RE: Issue with API handling multiple data inputs

    Posted 06-04-2025 11:08

    I did some more testing on this and adjusted the Data Action

    Input Contract

    {
      "type": "object",
      "properties": {
        "profileId": {
          "type": "string"
        },
        "membersToAssign": {
          "type": "string"
        }
      }
    }

    Action Configuration

    {
      "requestType": "POST",
      "requestTemplate": "{\n  \"membersToAssign\": ${input.membersToAssign}\n}",
      "requestUrlTemplate": "/api/v2/gamification/profiles/${input.profileId}/members",
      "headers": {}
    }

    This allows me to add a string collection (Flow.userIds) with userIds in a workflow



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 8.  RE: Issue with API handling multiple data inputs

    Posted 06-05-2025 08:42

    Hi Jan, 

    Thank you for testing! This is my first time doing something like this so my apologies for the continued questions but I tired using that "ToString(ToJson(variable))" and I think I did something wrong because it failed even with only one string in there(I tested with 2 and same result). Should I be updating the data outside the data action (in between 47 and 48 below)?



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



  • 9.  RE: Issue with API handling multiple data inputs

    Posted 06-05-2025 08:52

    Hi Connor,

    The flow looks correct, might be something in your data action.

    Try to Test the Data Action and input [ "userId" ]

    The Data Action should look similar to this



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 10.  RE: Issue with API handling multiple data inputs

    Posted 06-05-2025 10:40

    Hi Jan, 

    Thank you for your screenshot! Mine had a few extra characters in the body template. After removing them to make it the same as yours, it was able to work through it! 

    I have run into another issue in this same flow now with the same data, would you be able to take a look and see if you know how to fix it?

    So after the user profile ID's are added to the gamification profile, I have a data action to add a Gamification Role to the user profiles but after looking more at this API (POST /api/v2/authorization/subjects/{subjectId}/bulkadd), its not setup to handle multiple ID's. 

    My first thought was to create a loop for this data action and go through the variable one ID at a time, but is there anything you could recommend? 

    Here is the data action:

    Input Contract

    {
      "type": "object",
      "properties": {
        "userid": {
          "type": "string"
        }
      }
    }
    Here is the flow if you need context:


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



  • 11.  RE: Issue with API handling multiple data inputs

    Posted 06-05-2025 11:08

    Hi,

    Personally I prefer to add people to Groups and have the permissions come from group membership instead of adding roles to each user.
    You can also bulk add up to 50 members to groups.

    If you wanna add roles you'll have to loop through each user since there's no API to add a role to multiple users (that I can find).



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 12.  RE: Issue with API handling multiple data inputs

    Posted 06-05-2025 12:31

    Hi Jan, 

    I agree that groups would be a nicer solution but for our org, we will be needing to add the roles to profiles. 

    I have the loop logic figured out except I don't know how to pull the ID's out individually. This is what I have:

    My plan is to use the variable "AddRoleLoopNumber" as the notifier of what number ID to grab from the list but not sure what the syntax/command would do this. 

    This is what the data looks like in "MemberIDtoAdd_Array"



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



  • 13.  RE: Issue with API handling multiple data inputs

    Posted 06-05-2025 15:40

    Hi

    Use Count(State.MemberIDtoAdd_Array) in expression mode instead of 99 in your loop block 57 and use State.MemberIDtoAdd_Array[State.AddRoleLoopNumber] as userid input in Data Action block 49.



    ------------------------------
    Cheers
    Zubair
    ------------------------------



  • 14.  RE: Issue with API handling multiple data inputs

    Posted 06-05-2025 16:13

    Hi Zubair, 

    That did it! Thank you!!!



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