0

我正在尝试使用 OAuth2 将我们的应用程序与 Exact Online 网站集成,或者更具体地说,我正在尝试创建小时注册,其中应包括“员工”、“项目”、“小时”、“小时类型”。

function registerTime($access_token_for_data) {

    //$dataToFilterAccounts = array('$filter' => 'IsSales eq true');
    $dataToRetrieveFromEmployees = array('$select' => 'ID');
    // $queryToFilterAccounts = http_build_query($dataToFilterAccounts);   
    $queryToRetrieveFromEmployees = http_build_query($dataToRetrieveFromEmployees);

    // $dataToFilterItems = array('$filter' =>'IsSalesItem eq true');
    $dataToRetrieveProjects = array('$select' => 'ID');
    //$queryToFilterItems = http_build_query($dataToFilterItems);   
    $queryToRetrieveProjects = http_build_query($dataToRetrieveProjects);

    $urlProjects = 'https://start.exactonline.nl/api/v1/638842/project/Projects';
    $urlEmployees = 'https://start.exactonline.nl/api/v1/638842/payroll/Employees';

    $curlProjects = curl_init($urlProjects);
    $curlEmployees = curl_init($urlEmployees);

    $headers = array(
        'Authorization: Bearer ' . $access_token_for_data,
        'Accept: application/json',
        'Content-type: application/json'
    );

    curl_setopt($curlProjects, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curlProjects, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curlProjects, CURLOPT_URL, $urlProjects . '?' . $queryToRetrieveProjects);
    curl_setopt($curlProjects, CURLOPT_CUSTOMREQUEST, 'GET');

    curl_setopt($curlEmployees, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curlEmployees, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curlEmployees, CURLOPT_URL, $urlEmployees . '?' . $queryToRetrieveFromEmployees);
    curl_setopt($curlEmployees, CURLOPT_CUSTOMREQUEST, 'GET');


    $resultProjects = curl_exec($curlProjects);
    $resultEmployees = curl_exec($curlEmployees);

    $projectsData = json_decode($resultProjects, true);
    $projectID = $projectsData["d"]["results"]["0"]["ID"];

    $employeesData = json_decode($resultEmployees, true);
    $employeeID = $employeesData["d"]["results"]["0"]["ID"];

    curl_close($curlProjects);
    curl_close($curlEmployees);

    $urlTimeTransaction = 'https://start.exactonline.nl/api/v1/638842/project/TimeTransactions';

    $curlTimeTransacation = curl_init($urlTimeTransaction);
    $content = json_encode(array("Project" => $projectID, "Employee" => $employeeI));

    curl_setopt($curlTimeTransacation, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curlTimeTransacation, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curlTimeTransacation, CURLOPT_POST, true);
    curl_setopt($curlTimeTransacation, CURLOPT_POSTFIELDS, $content);

    $createdTimeTransaction = curl_exec($curlTimeTransacation);

    $status = curl_getinfo($curlTimeTransacation, CURLINFO_HTTP_CODE);
    if ($status != 201) {
        die("Error: call to URL $curlTimeTransacation failed with status $status, response $createdTimeTransaction, curl_error " . curl_error($curlTimeTransacation) . ", curl_errno " . curl_errno($curlTimeTransacation));
    }
    echo "HTTP status $status creating time registartion<br/><br/>";
    curl_close($curlTimeTransacation);
}

这是我得到的错误

错误:调用 URL 资源 id #56 失败,状态为 500,响应 {“error”:{“code”:“”,“message”:{“lang”:“”,“value”:“强制:员工\r \n强制:小时\r\n强制:小时类型" } } }, curl_error , curl_errno 0

但是,当我尝试包含任何这些 mandatroy 文件时,我得到:

错误:对 URL 资源 ID #56 的调用失败,状态为 400,响应 {“error”:{“code”:“”,“message”:{“lang”:“”,“value”:“错误处理请求流。为类型“Exact.Web.Api.Models.TimeTransaction”指定的属性名称“小时”无效。” } } }, curl_error , curl_errno 0

4

2 回答 2

2

请注意 /api/v1/638842 包含您的部门 ID。您可能希望将其更改为变量。

关于您的问题:请注意,错误消息包含供人类使用的文本。实际的技术名称可能不同。我总是反过来做:我查询现有数据并查看所有字段,然后我知道要发送什么。您可以使用 Exact 应用中心的 Exact Online 查询工具对 Exact Online 的 REST api 进行查询(但我有偏见,因为涉及)。

于 2015-05-14T12:30:15.077 回答
1

正如 Guido 正确指出的那样,在项目中没有命名Hours字段TimeTransaction 制造有一个字段。这有点令人困惑,特别是因为错误消息不是很清楚。Hours TimeTransaction

您需要设置QuantityTimeTransactions指定项目时间事务的小时数。

于 2015-07-31T09:35:15.303 回答