Why did I get API error code 10413?

Issue
PayPal returned API error code 10413 - The totals of the cart item amounts do not match order amounts.

Cause
When you passed item-level detail in an API call, your item amounts multiplied by the item quantities didn't add up to the ItemTotal you're passing, or the ItemTotal, ShippingTotal, HandlingTotal, TaxTotal, etc. didn't add up to the OrderTotal. This error usually occurs for DoExpressCheckoutPayment or DoDirectPayment, but is possible for any API call where you pass item-level detail.

Solution
The example in the following SOAP request passes $10.00 for ItemTotal (red) but the PaymentDetailsItem parameters (blue) add up to $20.00. The result would produce the 10413 error.

Example request

<!-- Request -->
<DoExpressCheckoutPaymentRequest xmlns="urn:ebay:api:PayPalAPI">
   <Version xmlns="urn:ebay:apis:eBLBaseComponents">53</Version>
   <DoExpressCheckoutPaymentRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">
      <PaymentAction>Sale</PaymentAction>
      <Token>EC-83338285UY017901W</Token>
      <PayerID>U7HE5XJZTBUUA</PayerID>
      <PaymentDetails>
         <OrderTotal currencyID="USD">14</OrderTotal>
         <ItemTotal currencyID="USD">10</ItemTotal>
         <ShippingTotal currencyID="USD">1</ShippingTotal>
            <HandlingTotal currencyID="USD">1</HandlingTotal>
         <TaxTotal currencyID="USD">1</TaxTotal>
         <PaymentDetailsItem>
            <Name>test_item_1</Name>
            <Quantity>3</Quantity>
            <Amount currencyID="USD">5.00</Amount>
         </PaymentDetailsItem>
         <PaymentDetailsItem>
            <Name>test_item_2</Name>
            <Quantity>1</Quantity>
            <Amount currencyID="USD">5.00</Amount>
         </PaymentDetailsItem>
         <InsuranceTotal currencyID="USD">1</InsuranceTotal>
      </PaymentDetails>
   </DoExpressCheckoutPaymentRequestDetails>
</DoExpressCheckoutPaymentRequest>
 
Example response
In the following example, error code 10413 returns an Ack of SuccessWithWarning. This means that the payment has completed but the item detail will be dropped from any payment transaction detail you see in your PayPal account.  
   
<!-- Response -->   
<DoExpressCheckoutPaymentResponseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2008-09-06T01:52:00Z</Timestamp>
   <Ack xmlns="urn:ebay:apis:eBLBaseComponents">SuccessWithWarning</Ack>
   <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">f18b92a228861</CorrelationID>
   <Errors xmlns="urn:ebay:apis:eBLBaseComponents">
      <ShortMessage>Transaction refused because of an invalid argument. See additional error messages for details.</ShortMessage>
      <LongMessage>The totals of the cart item amounts do not match order amounts.</LongMessage>
      <ErrorCode>10413</ErrorCode>
      <SeverityCode>Warning</SeverityCode>
   </Errors>
   <Version xmlns="urn:ebay:apis:eBLBaseComponents">53</Version>
   <Build xmlns="urn:ebay:apis:eBLBaseComponents">676720</Build>
   <DoExpressCheckoutPaymentResponseDetails xmlns="urn:ebay:apis:eBLBaseComponents">
      <Token>EC-83338285UY017901W</Token>
      <PaymentInfo>
         <TransactionID>65S49636U69329349</TransactionID>
         <ParentTransactionID />
         <ReceiptID />
         <TransactionType>express-checkout</TransactionType>
         <PaymentType>instant</PaymentType>
         <PaymentDate>2008-09-06T01:51:57Z</PaymentDate>
         <GrossAmount currencyID="USD">13.00</GrossAmount>
         <FeeAmount currencyID="USD">0.68</FeeAmount>
         <TaxAmount currencyID="USD">1.00</TaxAmount>
         <ExchangeRate />
         <PaymentStatus>Completed</PaymentStatus>
         <PendingReason>none</PendingReason>
         <ReasonCode>none</ReasonCode>
         <ShippingMethod>Default</ShippingMethod>
      </PaymentInfo>
      <Note />
   </DoExpressCheckoutPaymentResponseDetails>
</DoExpressCheckoutPaymentResponseType>