dse3168 2015-07-27 11:07
浏览 88

Rest API请求无效请求

still struggling with an RestAPI Request. I do the following request:

while($erg = odbc_fetch_array($query)){

    $count++;

    $sql_inner = "SELECT * from adadr WHERE idadadr = ".$erg['idAd']."";
    $query_inner = odbc_exec($connection, $sql_inner);
    $erg_inner = odbc_fetch_array($query_inner);

    $sql_inner_1 = "SELECT * from admemo WHERE idAdMemo = ".$erg['idAd']."";
    $query_inner_1 = odbc_exec($connection, $sql_inner_1);
    $erg_inner_1 = odbc_fetch_array($query_inner_1);

    $jsonpayload = json_encode(
    ['Code' => $erg['kurzcode'],
    'ShortName' => $erg['kurzcode'],
    'ClassificationType' => "0",
    'IsCompany' => "true",
    'ExternalKey' => $erg['idAd'],
    'Website' => $erg_inner['www'],
    'FederalTaxID' => ' ',
    'BankName' => ' ',
    'BankAccount' => ' ',
    'BankAccountName' => ' ',
    'BankControlKey' => ' ',
    'BankBranch' => ' ',
    'BankSwift' => ' ',
    'BankIBAN' => ' ',
    'IsCustomer' => "true",
    'CustOpeningText' => ' ',
    'CustClosingText' => ' ',
    'CustCreditLimit' => "0",
    'CustDiscountPercent' => "0",
    'CustTaxLiable' => "true",
    'CustDunningBlock' => "true",
    'CustDunningBlockReason' => ' ',
    'CustDeliveryBlock' => "true",
    'CustDeliveryBlockReason' => ' ',
    'CustExternalKey' => $erg['idAd'],
    'isSupplier' => "true",
    'SupOpeningText' => ' ',
    'SupClosingText' => ' ',
    'SupCreditLimit' => "0",
    'SupDiscountPercent' => "0",
    'SupTaxLiable' => "true",
    'SupDunningBlock' => "true",
    'SupDunningBlockReason' => ' ',
    'SupDeliveryBlock' => "true",
    'SupDeliveryBlockReason' => ' ',
    'SupExternalKey' => ' ',
    'OpenBalancesSales' => "0",
    'OpenBalancesPurchase' => "0",
    'OpenBalanceTotal' => "0",
    'BusinessPartnerGroupID' => ' ',
    'CurrencyID' => ' ',
    'SalesPersonID' => ' ',
    'LanguageID' => ' ',
    'RegionID' => ' ',
    'SectorID' => ' ',
    'BankCountryID' => ' ',
    'SalesPaymentTermID' => ' ',
    'SalesPricelistID' => ' ',
    'SalesPaymentTypeID' => ' ',
    'PurchasePaymentTermID' => ' ',
    'PurchasePricelistID' => ' ',
    'PurchaseTaxCodeID' => ' ',
    'PurchasePaymentType' => ' ',
    'ParentID' => ' ',
    'Tokens' => ' ',
    'OwnerID' => ' ',
    'ShortDescription' => ' ',
    'Title' => $erg['name1'],
    'IsInactive' => "true",
    'Description' => "".$erg_inner_1['interesse']."".$erg_inner_1['kumemo']."",], JSON_PRETTY_PRINT);   


    $http = new Client([
        'headers' => ['Authorization' => 'Bearer ' . $token["access_token"], 'Content-Length' => strlen($jsonpayload)]
    ]);

    $response = $http->post('https://test-api.appsolut.at:443/be14/crm/businesspartners?ApplicationKey=05122123715505505910414822421514420223122224104601322201721602610[...]', $jsonpayload, ['type' => 'application/json']);
    print_r($response);

}

I got the structure from the Documentation of the API from SWAGGER. If I try to submit the Post request I just get the following response:

Cake\Network\Http\Response Object ( [_code:protected] => 400 [_body:protected] => {"$id":"1","Message":"The request is invalid.","ModelState":{"$id":"2","EntityToAdd.BusinessPartnerGroupID":["An error has occurred."],"EntityToAdd.CurrencyID":["An error has occurred."],"EntityToAdd.SalesPersonID":["An error has occurred."],"EntityToAdd.LanguageID":["An error has occurred."],"EntityToAdd.RegionID":["An error has occurred."],"EntityToAdd.SectorID":["An error has occurred."],"EntityToAdd.BankCountryID":["An error has occurred."],"EntityToAdd.SalesPaymentTermID":["An error has occurred."],"EntityToAdd.SalesPricelistID":["An error has occurred."],"EntityToAdd.SalesPaymentTypeID":["An error has occurred."],"EntityToAdd.PurchasePaymentTermID":["An error has occurred."],"EntityToAdd.PurchasePricelistID":["An error has occurred."],"EntityToAdd.PurchaseTaxCodeID":["An error has occurred."],"EntityToAdd.ParentID":["An error has occurred."],"EntityToAdd.OwnerID":["An error has occurred."]}} [_xml:protected] => [_json:protected] => [_exposedProperties:protected] => Array ( [cookies] => _cookies [headers] => _headers [body] => _body [code] => _code [json] => _getJson [xml] => _getXml ) [_headers:protected] => Array ( [Cache-Control] => no-cache [Pragma] => no-cache [Content-Length] => 910 [Content-Type] => application/json; charset=utf-8 [Expires] => -1 [Server] => Microsoft-IIS/8.0 [X-Aspnet-Version] => 4.0.30319 [X-Powered-By] => ASP.NET [Set-Cookie] => ARRAffinity=f9083e983e049ddfbc317fa7ccfeec62cbe8ceb7f740470e4cd8e8a291cd206c;Path=/;Domain=test-api.appsolut.at [Date] => Mon, 27 Jul 2015 10:50:56 GMT [Connection] => close ) [_cookies:protected] => Array ( [ARRAffinity] => Array ( [value] => f9083e983e049ddfbc317fa7ccfeec62cbe8ceb7f740470e4cd8e8a291cd206c [path] => / [domain] => test-api.appsolut.at [name] => ARRAffinity ) ) [_version:protected] => 1.1 ) Cake\Network\Http\Response Object ( [_code:protected] => 500 [_body:protected] => {"$id":"1","Success":false,"Message":"Entity not defined","NewID":0,"Name":null,"Exception":null,"BrokenRules":null,"HasException":false,"HasBrokenRules":false} [_xml:protected] => [_json:protected] => [_exposedProperties:protected] => Array ( [cookies] => _cookies [headers] => _headers [body] => _body [code] => _code [json] => _getJson [xml] => _getXml ) [_headers:protected] => Array ( [Cache-Control] => no-cache [Pragma] => no-cache [Content-Length] => 160 [Content-Type] => application/json; charset=utf-8 [Expires] => -1 [Server] => Microsoft-IIS/8.0 [X-Aspnet-Version] => 4.0.30319 [X-Powered-By] => ASP.NET [Set-Cookie] => ARRAffinity=f9083e983e049ddfbc317fa7ccfeec62cbe8ceb7f740470e4cd8e8a291cd206c;Path=/;Domain=test-api.appsolut.at [Date] => Mon, 27 Jul 2015 10:50:58 GMT [Connection] => close ) [_cookies:protected] => Array ( [ARRAffinity] => Array ( [value] => f9083e983e049ddfbc317fa7ccfeec62cbe8ceb7f740470e4cd8e8a291cd206c [path] => / [domain] => test-api.appsolut.at [name] => ARRAffinity ) ) [_version:protected] => 1.1 ) Cake\Network\Http\Response Object ( [_code:protected] => 400 [_body:protected] => {"$id":"1","Message":"The request is invalid.","ModelState":{"$id":"2","EntityToAdd.BusinessPartnerGroupID":["An error has occurred."],"EntityToAdd.CurrencyID":["An error has occurred."],"EntityToAdd.SalesPersonID":["An error has occurred."],"EntityToAdd.LanguageID":["An error has occurred."],"EntityToAdd.RegionID":["An error has occurred."],"EntityToAdd.SectorID":["An error has occurred."],"EntityToAdd.BankCountryID":["An error has occurred."],"EntityToAdd.SalesPaymentTermID":["An error has occurred."],"EntityToAdd.SalesPricelistID":["An error has occurred."],"EntityToAdd.SalesPaymentTypeID":["An error has occurred."],"EntityToAdd.PurchasePaymentTermID":["An error has occurred."],"EntityToAdd.PurchasePricelistID":["An error has occurred."],"EntityToAdd.PurchaseTaxCodeID":["An error has occurred."],"EntityToAdd.ParentID":["An error has occurred."],"EntityToAdd.OwnerID":["An error has occurred."]}} [_xml:protected] => [_json:protected] => [_exposedProperties:protected] => Array ( [cookies] => _cookies [headers] => _headers [body] => _body [code] => _code [json] => _getJson [xml] => _getXml ) [_headers:protected] => Array ( [Cache-Control] => no-cache [Pragma] => no-cache [Content-Length] => 910 [Content-Type] => application/json; charset=utf-8 [Expires] => -1 [Server] => Microsoft-IIS/8.0 [X-Aspnet-Version] => 4.0.30319 [X-Powered-By] => ASP.NET [Set-Cookie] => ARRAffinity=f9083e983e049ddfbc317fa7ccfeec62cbe8ceb7f740470e4cd8e8a291cd206c;Path=/;Domain=test-api.appsolut.at [Date] => Mon, 27 Jul 2015 10:50:58 GMT [Connection] => close ) [_cookies:protected] => Array ( [ARRAffinity] => Array ( [value] => f9083e983e049ddfbc317fa7ccfeec62cbe8ceb7f740470e4cd8e8a291cd206c [path] => / [domain] => test-api.appsolut.at [name] => ARRAffinity ) ) [_version:protected] => 1.1 ) Cake\Network\Http\Response Object ( [_code:protected] => 400 [_body:protected] => {"$id":"1","Message":"The request is invalid.","ModelState":{"$id":"2","EntityToAdd.BusinessPartnerGroupID":["An error has occurred."],"EntityToAdd.CurrencyID":["An error has occurred."],"EntityToAdd.SalesPersonID":["An error has occurred."],"EntityToAdd.LanguageID":["An error has [...]

I already made sure, that the token I get and use in my post is a valid Token. And i tried passing values like "0" or "true" without ". Also tried JSON ENCODE without JSON_PRETTY_PRINT. I also tried to put the type just to "json" or "text/json". Does not help.

Does anybody has an idea how to start debugging that?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统