How to update auto_assign_tickets agent field through the Freshservice API?

Hello,

I am attempting to update the auto_assign_tickets field in an agent through the Freshservice API, but I keep on getting the error below. I have successfully updated the “signature” agent field with the same logic, so I know my code is correct and it is just the “auto_assign_tickets” field that is causing the error.

I am attempting this at the request of a client that wants to remove an agent from their round-robin scheduler based on a response from a third party api. I will need to be able to change “auto_assign_tickets” repeatedly to achieve their request so certain agents are not assigned tickets based on their api response.

Is there any way around this error? Or is there a more efficient way to remove an agent from auto-scheduler through the Freshservice api that I am unaware of?

Error:

  status: 400,
  headers: {
    date: 'Wed, 28 Feb 2024 22:47:33 GMT',
    'content-type': 'application/json; charset=utf-8',
    'transfer-encoding': 'chunked',
    connection: 'close',
    status: '400 Bad Request',
    'cache-control': 'no-cache, no-store',
    'x-freshservice-api-version': 'latest=v2; requested=v2',
    pragma: 'no-cache',
    'x-request-id': 'df98f03b-cd2d-9641-9523-924cf291a9a3',
    expires: 'Wed, 13 Oct 2010 00:00:00 UTC',
    'x-envoy-upstream-service-time': '68',
    'x-fw-ratelimiting-managed': 'true',
    'x-ratelimit-total': '500',
    'x-ratelimit-remaining': '497',
    'x-ratelimit-used-currentrequest': '1',
    'x-trace-id': '00-06d8162e667745be83c6dddb30ac3c11-e9d6a9c8333f3e98-01',
    nel: '{ "report_to": "nel-endpoint-freshservice", "max_age": 2592000, "include_subdomains": true}',
    'report-to': '{ "group": "nel-endpoint-freshservice", "max_age": 2592000, "include_subdomains": true, "endpoints": [{"url": "https://edge-admin.us-east-1.freshedge.net/nelreports/freshservice"}]}',
    server: 'fwe'
  },
  response: '{"description":"Validation failed","errors":[{"field":"auto_assign_tickets","message":"Unexpected/invalid field in request","code":"invalid_field"}]}',
  attempts: 1,
  errorSource: 'APP'
}```

@Freddy can you give the solution for this?

Hello Jose and Gopi,

It seems like the “auto_assign_tickets” field cannot be directly edited through the Freshservice API. The error message you received indicates that this field is unexpected or invalid in the request.

However, you can achieve the desired behavior by leveraging the “Group” entity in Freshservice. Here are the steps:

  1. Create a group or multiple groups in Freshservice and add the agents.
  2. Enable the round-robin/auto-assignment for these groups under Admin → Ticket Dispatch’r (“auto_assign_group_id” field).
  3. Use the Freshservice API to update the agent’s group based on the conditions you receive from the third-party API. You can do this by updating the agent’s group membership.

To update the agent’s group membership through the API, follow these steps:

  • Make a PUT request to the Freshservice API at:https://yourdomain.freshservice.com/api/v2/agents/{agent_id}
  • In the request body, include the parameter "group_ids": [group_id] where group_id is the ID of the desired group.

For example, if agent with ID ‘12345’ should be moved to a group with ID ‘678’, you can use:

{
    "agent": {
        "group_ids": [678]
    }
}

Please note that you should replace “yourdomain” with your Freshservice subdomain, {agent_id} with the agent’s ID, and `group_id