Xero API php 包装器的 createTimesheet 出现 500 错误

我正在使用 Xero API php 包装器来发布时间表,除了“发生错误”和状态 500 之外,没有返回任何详细信息。


我正在验证,它包含在范围内,据我所知,它是所请求格式的有效 json...


[{"EmployeeID":"a valid employee id","StartDate":"2020-08-03","EndDate":"2020-08-09","Status":"Draft","TimesheetLines":{"TimesheetLine":[{"EarningsRateID":"a valid pay item id","NumberOfUnits":{"NumberOfUnit":["0.00","0.00","8","0.00","0.00","0.00","0.00"]}},{"EarningsRateID":"a valid pay item id","NumberOfUnits":{"NumberOfUnit":["0.00","0.00","0.00","8.5","0.00","0.00","0.00"]}},{"EarningsRateID":"a valid pay item id","NumberOfUnits":{"NumberOfUnit":["0.00","0.00","0.00","0.00","8","0.00","0.00"]}},{"EarningsRateID":"a valid pay item id","NumberOfUnits":{"NumberOfUnit":["0.00","0.00","0.00","0.00","0.00","8","0.00"]}},{"EarningsRateID":"a valid pay item id","NumberOfUnits":{"NumberOfUnit":["0.00","0.00","0.00","0.00","0.00","0.00","8.5"]}}]}}]

这是通过...发送的


try {

      $result = $payrollAuApi->createTimesheet($xeroTenantId, $timesheet);

      print_r($result);

  } catch (Exception $e) {

      echo 'Exception when calling PayrollAuApi->createTimesheet: ', $e->getMessage(), PHP_EOL;

  }

并且tenantID没问题。


我很感激任何关于我出错的地方的指导。


UYOU
浏览 98回答 2
2回答

明月笑刀无情

看起来您的 TimesheetLines 是一个包含名为 TimesheetLine 的属性的对象,它是一个集合 - 但根据文档, TimesheetLines 本身应该是时间表行的集合。即你应该有类似的东西:[{ EmployeeID : 4fd71c0f-8612-4fd8-99d0-b3a2e8272b02 , StartDate : 2020-08-03 , EndDate : 2020-08-09 , Status : Draft , TimesheetLines :[{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 8 , 0.00 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 8.5 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8.5 ]}}]}]...代替...[{ EmployeeID : 4fd71c0f-8612-4fd8-99d0-b3a2e8272b02 , StartDate : 2020-08-03 , EndDate : 2020-08-09 , Status : Draft , TimesheetLines :{ TimesheetLine :[{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 8 , 0.00 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 8.5 , 0.00 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8 , 0.00 ]}},{ EarningsRateID : 0e30f933-04ed-4b96-9357-9747209c306f , NumberOfUnits :{ NumberOfUnit :[ 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 8.5 ]}}]}}]改变这个有帮助吗?

万千封印

对于遇到此问题的任何人来说,问题在于,与我在私人应用程序中使用的旧包装器不同,我在私人应用程序中构建了完整的 XML 时间表并发送它,Xero 的 oauth2 包装器并不需要完整的时间表。相反,您创建时间表的实例并为其设置属性。代码积分从存储库转到@wobinb$config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()- >setAccessToken( (string)$storage->getAccessToken() );$payrollApi = new XeroAPI\XeroPHP\Api\PayrollAuApi(  new GuzzleHttp\Client(),  $config);//first retrieve a list of active employees$apiResponse = $payrollApi->getEmployees($tenantId, null, "Status==\"ACTIVE\"");$employees = $apiResponse->getEmployees();foreach ($employees AS $employee) {  print $employee->getFirstName()." ".$employee->getLastName()." - ".$employee->getPayrollCalendarID();   if ($employee->getPayrollCalendarID() != null) {     $employeeID = $employee->getEmployeeID();     $payrollCalendarID = $employee->getPayrollCalendarID();     $ordinaryEarningsRateID = $employee->getOrdinaryEarningsRateID();   }   print "<br />";}print "<br />";//and now the payroll calendar$apiResponse = $payrollApi->getPayrollCalendar($tenantId,$payrollCalendarID);$calendar = $apiResponse->getPayrollCalendars()[0];print $calendar->getName()." - ".$calendar->getCalendarType();print "<br />";//finally create the timesheet$timesheet = new XeroAPI\XeroPHP\Models\PayrollAu\Timesheet();$timesheet->setEmployeeID($employeeID);$timesheet->setStartDateAsDate($calendar->getStartDateAsDate());//need to calculate how many days the timesheet will coverswitch ($calendar->getCalendarType()) {  case "WEEKLY":    $lengthofCalendar = 7;    break;  case "FORTNIGHTLY":    $lengthofCalendar = 14;    break;  case "FOURWEEKLY":    $lengthofCalendar = 28;    break;//monthly pay runs will be more complicated to calculate  }$endDate = $calendar->getStartDateAsDate();//end date will be start date plus the length and minus one day$period = "P". ($lengthofCalendar - 1) . "D";$endDate->add(new DateInterval($period));$timesheet->setEndDateAsDate($endDate);$timesheet->setStatus("DRAFT");$timesheetLine = new XeroAPI\XeroPHP\Models\PayrollAu\TimesheetLine();$timesheetLine->setEarningsRateId($ordinaryEarningsRateID);for ($day = 1; $day <= $lengthofCalendar; $day++) {   $numberOfUnits[] = $day;}$timesheetLine->setNumberOfUnits($numberOfUnits);$timesheetLines[] = $timesheetLine;$timesheet->setTimeSheetLines($timesheetLines);$timesheets[] = $timesheet;$apiResponse = $payrollApi->createTimesheet($tenantId,$timesheets);
打开App,查看更多内容
随时随地看视频慕课网APP