Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not post optional, unset Contact fields to Teamleader API #9

Merged
merged 1 commit into from Sep 7, 2018
Merged

Do not post optional, unset Contact fields to Teamleader API #9

merged 1 commit into from Sep 7, 2018

Conversation

svendecabooter
Copy link

When adding a contact through v2 of this Teamleader API library, I'm getting errors when only a few variables are provided.

Example use case:

    $contact_variables = [
      'first_name' => "First",
      'last_name' => "Last",
      'emails' => [
        [
          'type' => 'primary',
          'email' => "test@example.com",
        ],
      ],
    ];
    $contact = new Contact($contact_variables);
    $contactRepository->addContact($contact);

Problems:

  • If the "salutation" field is not added to $contact_variables, it gets set to a default empty string "". The Teamleader API returns an error indicating the salutation cannot be empty. If the salutation would not be in the posted body to Teamleader at all, there would be no problem (since it's an optional field).
  • In \Nascom\TeamleaderApiClient\Request\Contact\ContactsAddRequest I'm getting PHP errors in the constructor, e.g. in $this->setAddresses($contact->getAddresses()); Without values for addresses in $contact_variables, $contact->getAddresses() returns value null. However $this->setAddresses() expects an array object (via type hinting), not a null value.

This PR fixes this behaviour, allowing me to add contacts to Teamleader that only contain a few basic fields.

@mark-gerarts
Copy link
Collaborator

We encountered the same problem ourselves, and were thinking about a similar fix. Thanks for the PR!

@mark-gerarts mark-gerarts merged commit 6eaf30d into Nascom:v2 Sep 7, 2018
@svendecabooter
Copy link
Author

Thanks for the quick feedback & merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants