Infos:
- Used Zammad version: 5.1.x
- Used Zammad installation type: docker-compose
Expected behavior:
The ticket should be created without a lookup error.
Actual behavior:
The ticket creating sometimes fails with invalid Customer ID if the customer is new and it was created in the previous API call.
Steps to reproduce the behavior:
Our code works in a way, that:
- it is checking the user existence based on the email address (/api/v1/users/search → email.keyword:USER EMAIL ADDRESS)
- if the user was not found, it is creating a new user (/api/v1/users) and remembers the returned user ID of the newly created user ($data->id). If the user is found, then the returned user ID ($data[0]->id) is remembered
- creates a new ticket using the user ID got in the previous steps (/api/v1/tickets → ‘customer’ => $customerId)
The ticket creation sometimes fails with error:
{“error”:“No lookup value found for 'customer': \“667\””,“error_human”:“No lookup value found for 'customer': \“667\””}',
It is very strange as at point 2 the customer ID 667 was returned by zammad, we see it in our logs, so the customer was definitely created.
Is this a bug, or an expected behavior? Is there any best practice, how we can handle this case? Retry? Wait?
Just for completeness, here are the exact API calls for user and ticket creation:
$url = $this->_zammadBaseUrl . '/api/v1/users';
$postData = array(
'body' => array(
"firstname"=> $splitName[0],
"lastname"=> $splitName[1],
"email"=> $userEmail,
"roles"=> ["Customer"]
),
'headers' => array(
'Authorization' => 'Token token=' . $this->_zammadApiToken
)
);
...
$customerId = 0;
if(!is_wp_error($resp)){
$data = json_decode($resp['body']);
if($data !== null){
$customerId = $data->id;
$this->logExt('New customer id', $customerId);
}
}else{
$this->log('Failed to create the customer.');
}
$url = $this->_zammadBaseUrl . '/api/v1/tickets';
$postData = array(
'body' => array(
'title' => $subject,
'group' => $group,
'customer' => $customerId,
'article' => array(
'subject' => $subject,
'body' => $message,
'from' => $email,
'type' => 'web',
'content_type' => 'text/html'
)
),
'headers' => array(
'Authorization' => 'Token token=' . $this->_zammadApiToken
)
);
Any help is appreciated!