Rest API请求无效请求

时间:2015-07-27 11:07:07

标签: php api rest

仍在努力使用RestAPI请求。我提出以下要求:

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

}

我从SWAGGER的API文档中获得了结构。如果我尝试提交帖子请求,我会得到以下回复:

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 [...]

我已经确定,我在帖子中获得并使用的令牌是有效的令牌。我尝试传递像" 0"或"真"没有"。还尝试了没有JSON_PRETTY_PRINT的JSON ENCODE。我也尝试将类型放到" json"或" text / json"。没有帮助。

有人知道如何开始调试吗?

0 个答案:

没有答案