zendesk / zendesk_api_client_rb

Official Ruby Zendesk API Client
http://developer.zendesk.com/
Apache License 2.0
387 stars 183 forks source link

Prevent race conditions when finding tickets and adding new comments #362

Closed BallerChan closed 1 year ago

BallerChan commented 6 years ago

I am struggling to figure out how to grab the server response and make changes to the ticket after do a search. This is a common occurrence that is raising issues on my rails app.

client = Zendesk.client ticket = client.tickets.find(:id => TICKET_ID) ticket.comment = ZendeskAPI::Ticket::Comment.new(client, :body => BODY)

Due to me being unable to grab the response (200 or 304), I am unable to check if the ticket has been found or if there's an error leading to this lovely error:

undefined method 'comment=' for nil:NilClass when I try to add a new comment to the ticket.

Is there a way to grab the status code of the API request and wait until I receive a response from the server to proceed?

ecoologic commented 1 year ago

Since 2018 things changed and your API calls are now displayed in the terminal. Seems like the ticket ID you used was not associated with any ticket. This caused ticket == nil and therefor nil.comment= causing the error you saw, again, in 2018. I hope you had a better experience later on.