Move_workspace works in CURL but same group_id and responder_id do not work in Python

I am trying to do a move_workspace on some tickets. I can do it successfully in CURL but it is not working with the exact same parameters in Python calls to the API

The API call in CURL that is working is:

curl -v -u adminAPIkey :X -H "Content-Type: application/json" -X PUT -d '{ "workspace_id": 4, "group_id": null, "responder_id": 23000-----1 }' 'https://mydomain.freshservice.com/api/v2/tickets/212/move_workspace'

The Python call is done with the same parameters.

import requests

# Define your API key & Endpoint
API_KEY = 'apikey'  # replace with your API key
DOMAIN = 'https://mydomain.freshservice.com'  # replace with your Freshservice domain
ENDPOINT = f"{DOMAIN}/api/v2"

# Set up the headers for the request
HEADERS = {
    'Content-Type': 'application/json',
    'Authorization': f'{requests.auth._basic_auth_str(API_KEY, "X")}'
}

# IDs for destination workspace, group, and responder
DEST_WORKSPACE_ID = 4
DEST_GROUP_ID = 23000-----2
RESPONDER_ID = 23000-----1


def move_ticket_to_dest(ticket_id):
    # Data to send in the request body
    data = {
        "workspace_id": DEST_WORKSPACE_ID,
        "group_id": DEST_GROUP_ID,
        "responder_id": RESPONDER_ID
    }
    # Make the API call
    response = requests.put(f"{ENDPOINT}/tickets/{ticket_id}/move_workspace", headers=HEADERS, json=data)

    if response.status_code == 200:
        print(f"Successfully moved ticket {ticket_id}")
    else:
        print(f"Error moving ticket {ticket_id}: {response.text}")

def main():
    # Example: move ticket with ID 1
    move_ticket_to_dest(213)

if __name__ == "__main__":
    main()

The tickets, 212 and 213, are duplicates of each other.

The Freshservice API rejects the Python call with the following:

Error moving ticket 213: {"description":"Validation failed","errors":[{"field":"group_id","message":"The value provided is of type String.It should be of type Positive Integer","code":"datatype_mismatch"}]}

The trouble is that “null” is acceptable in the CURL call for the group_id, but not in Python.
I tried 0 (zero) but got back this instead.

Error moving ticket 213: {"description":"Validation failed","errors":[{"field":"group_id","message":"It should be of type Positive Integer","code":"invalid_value"}]}

When I put in a valid destination group_id I get this:

Error moving ticket 259: {"description":"Validation failed","errors":[{"field":"responder_id_and_group_id","message":"Not a valid agent-group combination","code":"invalid_value"}]}

I know this is an error in how I do Python, as I am no expert, but I don’t see it.

-Race

UPDATE:

I found my error and solved it as to working now.

While I was using “null” in CURL, the counterpart in Python is “Null”

DEST_WORKSPACE_ID = 4
DEST_GROUP_ID = Null
RESPONDER_ID = 23000-----1

Just to note, the Group ID and Responder are not mandatory parameters, the just the workspace id is required to move the ticket. It can be a simple payload to the move_workspace method:

{
  "workspace_id": 3
}
1 Like

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