XeroAPI / xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
MIT License
90 stars 64 forks source link

createEmployee fails with JSON de/serialization. #279

Closed DeanOutlaw closed 1 year ago

DeanOutlaw commented 2 years ago

SDK you're using (please complete the following information):

Describe the bug createEmployee fails with JSON de/serialization

To Reproduce Steps to reproduce the behavior:

  1. Call createEmployee using the following code
  2. $dateOfBirth = new DateTime('2000-10-28');

$homeAddress = new XeroAPI\XeroPHP\Models\PayrollAu\HomeAddress; $homeAddress->setAddressLine1('123 Test st'); $homeAddress->setRegion('VIC'); $homeAddress->setPostalCode(3000); $homeAddress->setCity('Melbourne');

$employee = new XeroAPI\XeroPHP\Models\PayrollAu\Employee; $employee->setFirstName('Adam'); $employee->setLastName('Adamson'); $employee->setDateOfBirthAsDate($dateOfBirth); $employee->setHomeAddress($homeAddress); $result = $apiInstance->createEmployee($xeroTenantId, $employee);

  1. error returns as requestError occurred during JSON de/serialization. Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Paycycle.API.DTO.AU.Employee.UpdateEmployeeRequest' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'DateOfBirth', line 1, position 15.
  2. createEmployeeWithHttpInfo [class] => XeroAPI\XeroPHP\Api\PayrollAuApi [type] => -> [args] => Array ( [0] => **** [1] => XeroAPI\XeroPHP\Models\PayrollAu\Employee Object ( [container:protected] => Array ( [first_name] => Adam [last_name] => Adamson [date_of_birth] => /Date(972691200000+0000)/ [home_address] => XeroAPI\XeroPHP\Models\PayrollAu\HomeAddress Object ( [container:protected] => Array ( [address_line1] => 123 Test st [address_line2] => [city] => Melbourne [region] => VIC [postal_code] => 3000 [country] => ) ) [start_date] => [title] => [middle_names] => [email] => [gender] => [phone] => [mobile] => [twitter_user_name] => [is_authorised_to_approve_leave] => [is_authorised_to_approve_timesheets] => [job_title] => [classification] => [ordinary_earnings_rate_id] => [payroll_calendar_id] => [employee_group_name] => [employee_id] => [termination_date] => [termination_reason] => [bank_accounts] => [pay_template] => [opening_balances] => [tax_declaration] => [leave_balances] => [leave_lines] => [super_memberships] => [status] => [updated_date_utc] => [validation_errors] => )

Expected behavior create new employee entry

Additional context I tried copying the sample SDK code found at https://xeroapi.github.io/xero-php-oauth2/docs/v2/payroll_au/index.html#api-PayrollAu-createEmployee and that just throws the same error

DeanOutlaw commented 1 year ago

OK I worked it out, so for my future reference and for others, you need to push $employee into an array so $newEmployees = [];
array_push($newEmployees, $employee); $result = $apiInstance->createEmployee($xeroTenantId, $newEmployees);