Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I found an error while saving invoice into quickbook online php api here is my code, ...

require_once(__DIR__ . '/quickbook/vendor/autoload.php');
    $config = include('quickbook/config.php');

    use QuickBooksOnlineAPICoreServiceContext;
    use QuickBooksOnlineAPIDataServiceDataService;
    use QuickBooksOnlineAPIPlatformServicePlatformService;
    use QuickBooksOnlineAPICoreHttpSerializationXmlObjectSerializer;
    use QuickBooksOnlineAPIFacadesInvoice;


    //include("connect.php");
    session_start();
    $cid = $_REQUEST['cid'];

    $token_file = 'quickbook/token.txt';
    $atf = unserialize(file_get_contents($token_file));
    $accessToken = $atf;

    $invoice_id = $_SESSION['invoice_id'];
    $firstname = $_SESSION['firstname'];
    $lastname = $_SESSION['lastname'];
    $company_name = $_SESSION['company_name'];
    $email = $_SESSION['email'];
    $cust_phone = $_SESSION['cust_phone'];
    $cust_address = $_SESSION['cust_address'];
    $cust_city = $_SESSION['cust_city'];
    $cust_pincode = $_SESSION['cust_pincode'];
    $cust_country = $_SESSION['cust_country'];
    $invoice_service = $_SESSION['invoice_service'];
    $invoice_amount = $_SESSION['invoice_amount'];

    $dataService = DataService::Configure(array(
        'auth_mode' => 'oauth2',
        'ClientID' => $config['client_id'],
        'ClientSecret' =>  $config['client_secret'],
        'accessTokenKey'  => $accessToken->getAccessToken(),
        'refreshTokenKey' => $accessToken->getRefreshToken(),
        'QBORealmID' => $accessToken->getRealmID(),
        'baseUrl' => "development"
    ));

    $theResourceObj = Invoice::create([
        "DocNumber" => $invoice_id,
        "Line" => [
                       [
                         "Description" => $invoice_service,
                         "Amount" => number_format($invoice_amount,2),
                         "DetailType" => "SalesItemLineDetail",
                         "SalesItemLineDetail" => [
                           "ItemRef" => [
                             "value" => 1,
                             "name" => "Services"
                            ],
                            "UnitPrice" => $invoice_amount,
                            "Qty" => 1
                          ]
                      ]
                    ],
        "CustomerRef"=> [
            "value"=> $cid,
        ]
    ]);
    //print_r($theResourceObj);
    $resultingObj = $dataService->Add($theResourceObj);
    $error = $dataService->getLastError();
    if ($error) {
        echo "The Status code is: " . $error->getHttpStatusCode() . "<br>";
        echo "The Helper message is: " . $error->getOAuthHelperError() . "<br>";
        echo "The Response message is: " . $error->getResponseBody() . "<br>";
    }
    else {
        echo "Created Id={$resultingObj->Id}. Reconstructed response body:<br><br>";
        $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingObj, $urlResource);
        echo $xmlBody . "<br>";
    }
    exit;
    //location('invoice.php');

....

Here is error

        The Status code is: 400
        The Helper message is: Invalid auth/bad request (got a 400, expected HTTP/1.1 20X or a redirect)
        The Response message is: Required param missing, need to supply the required value for the APIRequired parameter Line.Amount is missing in the request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
505 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...