zammad/zammad-api-client-php

Adding Contacts / Unable to create http client request

wucherpfennig opened this issue · 4 comments

Dear all

Whilst creating new contacts via the API we are getting constantly the error:

Unable to create http client request

https://github.com/zammad/zammad-api-client-php/blob/14099928589c1a9e9b3fafcf596241ddff666143/src/Client.php#L79-82

During development we cannot reproduce this kind of error. Does anybody have an idea why this error is thrown?

BR wucherpfennig

I have updated the title in order to potentially narrow down this issue. Creating textmodules and organisations works without any issues. This error appears only while creating customer contacts.

Please provide the payload or script you're trying to use against the API.

After further investigation I notice that the issue appears only while creating contacts. In addition I saw (from the "source" side) that creating the first entity is not an issue but the second yields in this error.

The payload used looks like this:

Array
(
    [login] => someUserNameWithoutSpecialCars
    [firstname] => SomeFirstName
    [lastname] => SomeName
    [email] => frank@someemail.ch
    [web] =>
    [phone] => +41123123
    [fax] =>
    [mobile] => +41123123
    [department] =>
    [street] => Street 116
    [zip] => 9999
    [city] => City
    [country] => Country
    [address] => Street 116
9999 Some Place
Country
    [vip] =>
    [verified] => 1
    [active] => 1
    [note] => Direktion/Directeur / Spricht CH/Geschäftsführung
    [roles] => Customer
    [organization_id] => 1189
    [cus_crm_number] => XYZ15469
)

The script used (which works fine for textmodules and organisations) looks like:

    protected function getApiClient($tenant): Client
    {
        $credentials = $this->getCredentials($tenant);
        return new Client($credentials);
    }

    public function createEntity(string $tenantMachineName, $entity)
    {
        $result = array();
        /* @var $resource AbstractResource */
        $resource = $this->getApiClient($tenantMachineName)->resource($this->getResourceType());
        $entityReturned = $resource->setValues($entity)->save();
        if ($entityReturned->hasError() !== TRUE) {
            $result = $entityReturned->getValues();
        } else {
            $error = sprintf(
                "message: %s\nentity: %s",
                $entityReturned->getError(),
                print_r($entity, TRUE)
            );
            throw new Exception($error);
        }
        return $result;
    }

Update 1
Corresponding logs

I, [2021-05-19T20:44:21.453453 #27199-70254431077160]  INFO -- : Started POST "/api/v1/users?expand=1" for 82.136.112.154 at 2021-05-19 20:44:21 +0200
I, [2021-05-19T20:44:21.456370 #27199-70254431077160]  INFO -- : Processing by UsersController#create as JSON
I, [2021-05-19T20:44:21.456440 #27199-70254431077160]  INFO -- :   Parameters: {REDACTED}
I, [2021-05-19T20:44:21.552396 #27199-70254431077160]  INFO -- : Authentication against Auth::Internal for user api@MYSECRET.com ok.
I, [2021-05-19T20:44:21.561327 #27199-70254431077160]  INFO -- : Won't enqueue SearchIndexJob (Job ID: ff48879e-b7ea-4f40-8883-7c7e60b81dc0) because of already existing job with lock key 'SearchIndexJob/User/35'.
I, [2021-05-19T20:44:21.561399 #27199-70254431077160]  INFO -- : Enqueued SearchIndexJob (Job ID: ff48879e-b7ea-4f40-8883-7c7e60b81dc0) to DelayedJob(default) with arguments: "User", 35
I, [2021-05-19T20:44:21.561759 #27199-70254431077160]  INFO -- : Won't enqueue SearchIndexAssociationsJob (Job ID: 4f89cbf5-5f66-4632-9033-b4cd6778a770) because of already existing job with lock key 'SearchIndexAssociationsJob/User/35'.
I, [2021-05-19T20:44:21.561801 #27199-70254431077160]  INFO -- : Enqueued SearchIndexAssociationsJob (Job ID: 4f89cbf5-5f66-4632-9033-b4cd6778a770) to DelayedJob(default) with arguments: "User", 35
I, [2021-05-19T20:44:21.620234 #27199-70254431077160]  INFO -- : Enqueued SearchIndexJob (Job ID: 3f7877d3-dd8e-4ed7-9fb2-4632eb5ca7c1) to DelayedJob(default) with arguments: "User", 3125
I, [2021-05-19T20:44:21.622234 #27199-70254431077160]  INFO -- : Enqueued SearchIndexAssociationsJob (Job ID: 7d6d6d94-a6d9-4f1f-ba6c-e59f17cdb940) to DelayedJob(default) with arguments: "User", 3125
I, [2021-05-19T20:44:21.625624 #27199-70254431077160]  INFO -- : Enqueued SearchIndexJob (Job ID: e017f253-df2d-4a28-a8e7-edeaa8e37ce1) to DelayedJob(default) with arguments: "Organization", 1189
I, [2021-05-19T20:44:21.627413 #27199-70254431077160]  INFO -- : NOTICE create - self.updated_by_id is different: 1/35
I, [2021-05-19T20:44:21.627447 #27199-70254431077160]  INFO -- : NOTICE create - self.created_by_id is different: 1/35
I, [2021-05-19T20:44:22.119405 #27027-47300488307160]  INFO -- :  - no message
I, [2021-05-19T20:44:22.119458 #27027-47300488307160]  INFO -- : done

Update 2
I do not see any errors while CREATING the customer... After checking in the system the contact was created successfully. Therefore I do think the issues might be somewhere else...

any ideas?

Update 3
I did notice that some requests took around 6+ seconds. I noticed that this has gotten worse with zammad v4+ and therefore I have added a timeout of 30 seconds... it looks like it is working better

As mentioned the issue was tied to the timeout. Therefore I close this ticket.