Planet-Zoom
Planet-Zoom

Reputation: 1185

How to set assignee to ticket in Zenpy python client library

I am integrating Zendesk ITSM API in my python library using Zenpy client.

For creating ticket using zenpy client , I can set reporter of ticket by email id, but for assignee I am not able to set assignee by email id.

This is the code I have tried so far.

ticket_payload = Ticket(
    description="some description",
    type="task",
    priority="high",
    status="open"
    )

ticket_payload.requester = User(email="[email protected]"])
ticket_payload.assignee = User(email="[email protected]")

response = self.zenpy_client.tickets.create(ticket_payload)

Response ticket I get has reporter set, but assigneee is None.

If I pass id along with the email as

ticket_payload.assignee = User(id= 354876354,email="[email protected]")

then it works and I can see assignee is set to ticket. But this is not required for reporter.

Is this the defult behaviour of zenpy, or am I missing something?

Upvotes: 1

Views: 1323

Answers (1)

mtcronin99
mtcronin99

Reputation: 11

It took me a while but I think I understand your issue. From the doc in the API Objects section under the Object Properties section:

When the assignee attribute is accessed, Zenpy first attempts to locate the related User in the User cache and if it cannot be found will generate and execute an API call to retrieve, instantiate, cache and return the object.

I mistakenly assumed that is meant I could set the value of the assignee attribute and zenpy would look it up and then put the id in the assignee_id field. This is an incorrect interpretation. The quote means if you set the assignee_id and then attempt to access the assignee attribute it will look it up and return it. But there must be an id.

From the next section of the docs:

It is important to note that most property setters throw away all information except for the id. This is because Zendesk only expects the id, so any modifications made to the object will not be persisted automatically.

So when you set the assignee or requestor without an id, the email address is thrown away and the respective id is set to None.

As to why the requester ID is set, it is probably set to the User that you use to authenticate the request rather than the one that you specify.

Upvotes: 1

Related Questions