dongyin8009 2014-11-24 14:46
浏览 24

OAuth2与ExactOnline集成

I am trying to integrate our app with Exact Online website using OAuth2,or more specifically i am trying to create hour registration which should include "Employee","Project","Hours","Hours type".

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);
}

And this is the error i get

Error: call to URL Resource id #56 failed with status 500, response { "error": { "code": "", "message": { "lang": "", "value": "Mandatory: Employee Mandatory: Hours Mandatory: Hour type" } } }, curl_error , curl_errno 0

But when i try to include any of these mandatroy fileds i get:

Error: call to URL Resource id #56 failed with status 400, response { "error": { "code": "", "message": { "lang": "", "value": "Error processing request stream. The property name 'Hours' specified for type 'Exact.Web.Api.Models.TimeTransaction' is not valid." } } }, curl_error , curl_errno 0

  • 写回答

2条回答 默认 最新

  • dox19458 2015-05-14 12:30
    关注

    please note that /api/v1/638842 contains your division ID. You might want to change that into a variable.

    Regarding your problem: please note that the error messages contain text to be consumed by humans. The actual technical names can be different. I always do it the other way around: I query the existing data and look at all fields, and then I know what to send. You can use the Query Tool for Exact Online in the app center of Exact to do the query on REST api of Exact Online (but I am biased because involved).

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度