在Xero PHP SDK中创建员工
我已经从Xero开发人员网站复制了示例代码,但请继续遇到dateofth的错误 代码
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure OAuth2 access token for authorization: OAuth2
$config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken( 'YOUR_ACCESS_TOKEN' );
$apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi(
new GuzzleHttp\Client(),
$config
);
$xeroTenantId = "xeroTenantId_example";
$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->setDateOfBirth($dateOfBirth);
$employee->setHomeAddress($homeAddress);
try {
$result = $apiInstance->createEmployee($xeroTenantId, $employee);
} catch (Exception $e) {
echo 'Exception when calling PayrollAuApi->createEmployee: ', $e->getMessage(), PHP_EOL;
}
?>
这是我遇到的错误的 json de/serialization期间发生了不良要求。无法对当前的JSON对象(例如{“ name”:“ value”})进行'paycycle.api.dto.au.employee.updateEmployeeReeReequest',因为类型需要JSON数组(例如[1,2,3])正确化。要解决此错误要么将JSON更改为JSON阵列(例如[1,2,3])或更改供应类型,因此它是正常的.NET类型(例如,不是像Integer这样的原始类型,而不是类型的集合类型可以从JSON对象进行值得序列化的数组或列表。 JonobjectAttribute也可以将其添加到类型中,以强迫其从JSON对象进行验证。路径“ dateofbirth',第1行,位置15。
这是从Xeroapi \ Xerophp \ models \ payrollau \雇用对象
[date_of_birth] =&gt; gt; dateTime对象([[date] =&gt; 2000-10-28 00:00:00.000000 [TimeZone_Type] =&gt; 3 [TimeZone] =&GT; Australia/NSW)
I have copied the sample code from the Xero developers site but keep getting an error with the DateOfBirth
here is the code
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure OAuth2 access token for authorization: OAuth2
$config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken( 'YOUR_ACCESS_TOKEN' );
$apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi(
new GuzzleHttp\Client(),
$config
);
$xeroTenantId = "xeroTenantId_example";
$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->setDateOfBirth($dateOfBirth);
$employee->setHomeAddress($homeAddress);
try {
$result = $apiInstance->createEmployee($xeroTenantId, $employee);
} catch (Exception $e) {
echo 'Exception when calling PayrollAuApi->createEmployee: ', $e->getMessage(), PHP_EOL;
}
?>
The error I get is
Bad 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.
This is what is being posted from the XeroAPI\XeroPHP\Models\PayrollAu\Employee Object
[date_of_birth] => DateTime Object ( [date] => 2000-10-28 00:00:00.000000 [timezone_type] => 3 [timezone] => Australia/NSW )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样的员工通过和一系列员工对我有用。
这是成功执行的POST方法的屏幕截图。
Passing and array of employees like this worked for me.
Here is the screenshot of the post method that executed successfully.
也许通过员工的
数组
?The documentation doesn't look much different.
Maybe pass an
array
of employees instead?是的,对它进行了排序,我只需要将员工放入数组中
yep, got it sorted, I just needed to put the employee into an array