Q:

Quickbooks API Explorer - How To Link Transactions To Invoices?

Using the QuickBooks Online v3 API (https://developer.intuit.com/apiexplorer?apiname=V3QBO)
How do I create a payment and then link that payment to an existing invoice using the API Explorer? I'm using sandbox for all my testing.
For example, I created a payment under a client and here is the response.
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-04-23T04:27:18.490-07:00">

  <Payment domain="QBO" sparse="false">

    <Id>162</Id>

    <SyncToken>0</SyncToken>

    <MetaData>

      <CreateTime>2015-04-23T04:28:55-07:00</CreateTime>

      <LastUpdatedTime>2015-04-23T04:28:55-07:00</LastUpdatedTime>

    </MetaData>

    <TxnDate>2013-07-11</TxnDate>

    <PrivateNote>Payment smoke test</PrivateNote>

    <CustomerRef name="ZeanabArafat">61</CustomerRef>

    <DepositToAccountRef>4</DepositToAccountRef>

    <TotalAmt>200.00</TotalAmt>

    <UnappliedAmt>200.00</UnappliedAmt>

    <ProcessPayment>false</ProcessPayment>

  </Payment>

</IntuitResponse>

My payment was for $200.  I then created an invoice, here is the response from that...
I then created an invoice the response I got from API below.
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-04-23T05:25:26.668-07:00">
  <Invoice domain="QBO" sparse="false">
    <Id>163</Id>
    <SyncToken>0</SyncToken>
    <MetaData>
      <CreateTime>2015-04-23T05:26:58-07:00</CreateTime>
      <LastUpdatedTime>2015-04-23T05:26:58-07:00</LastUpdatedTime>
    </MetaData>
    <CustomField>
      <DefinitionId>1</DefinitionId>
      <Name>Crew #</Name>
      <Type>StringType</Type>
    </CustomField>
    <DocNumber>1049</DocNumber>
    <TxnDate>2015-04-23</TxnDate>
    <Line>
      <Id>1</Id>
      <LineNum>1</LineNum>
      <Amount>2000.00</Amount>
      <DetailType>SalesItemLineDetail</DetailType>
      <SalesItemLineDetail>
        <ItemRef name="Concrete">3</ItemRef>
        <TaxCodeRef>NON</TaxCodeRef>
      </SalesItemLineDetail>
    </Line>
    <Line>
      <Amount>2000.00</Amount>
      <DetailType>SubTotalLineDetail</DetailType>
      <SubTotalLineDetail />
    </Line>
    <TxnTaxDetail>
      <TotalTax>0</TotalTax>
    </TxnTaxDetail>
    <CustomerRef name="ZeanabArafat">61</CustomerRef>
    <BillAddr>
      <Id>98</Id>
      <Line1>2007 Sailborough Ct Winter Garden, FL 34787</Line1>
      <Lat>28.522938</Lat>
      <Long>-81.605711</Long>
    </BillAddr>
    <ShipAddr>
      <Id>98</Id>
      <Line1>2007 Sailborough Ct Winter Garden, FL 34787</Line1>
      <Lat>28.522938</Lat>
      <Long>-81.605711</Long>
    </ShipAddr>
    <DueDate>2015-05-23</DueDate>
    <TotalAmt>2000.00</TotalAmt>
    <ApplyTaxAfterDiscount>false</ApplyTaxAfterDiscount>
    <PrintStatus>NeedToPrint</PrintStatus>
    <EmailStatus>NotSet</EmailStatus>
    <Balance>2000.00</Balance>
    <Deposit>0</Deposit>
    <AllowIPNPayment>false</AllowIPNPayment>
    <AllowOnlinePayment>false</AllowOnlinePayment>
    <AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
    <AllowOnlineACHPayment>false</AllowOnlineACHPayment>
  </Invoice>
</IntuitResponse>

I then run the following xml in API explorer for the update command on the invoice just to test and be sure it works and then I double checked and it did update the private comments for the invoice in the UI of sandbox... so ...so far so good.
<Invoice xmlns="http://schema.intuit.com/finance/v3" domain="QBO" sparse="true">

    <Id>163</Id>

    <SyncToken>0</SyncToken>

    <MetaData>

      <CreateTime>2014-10-15T14:13:24-07:00</CreateTime>

      <LastUpdatedTime>2014-10-15T14:13:24-07:00</LastUpdatedTime>

    </MetaData>

  <PrivateNote>Invoice update Test</PrivateNote>

  </Invoice>

So this worked.  I got the response...
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-04-23T05:30:04.336-07:00">
<Invoice domain="QBO" sparse="false"> <Id>163</Id> <SyncToken>1</SyncToken> <MetaData> <CreateTime>2015-04-23T05:26:58-07:00</CreateTime> <LastUpdatedTime>2015-04-23T05:31:36-07:00</LastUpdatedTime> </MetaData> <CustomField> <DefinitionId>1</DefinitionId> <Name>Crew #</Name> <Type>StringType</Type> </CustomField> <DocNumber>1049</DocNumber> <TxnDate>2015-04-23</TxnDate> <PrivateNote>Invoice update Test</PrivateNote> <Line> <Id>1</Id> <LineNum>1</LineNum> <Amount>2000.00</Amount> <DetailType>SalesItemLineDetail</DetailType> <SalesItemLineDetail> <ItemRef name="Concrete">3</ItemRef> <TaxCodeRef>NON</TaxCodeRef> </SalesItemLineDetail> </Line> <Line> <Amount>2000.00</Amount> <DetailType>SubTotalLineDetail</DetailType> <SubTotalLineDetail /> </Line> <TxnTaxDetail> <TotalTax>0</TotalTax> </TxnTaxDetail> <CustomerRef name="ZeanabArafat">61</CustomerRef> <BillAddr> <Id>98</Id> <Line1>2007 Sailborough Ct Winter Garden, FL 34787</Line1> <Lat>28.522938</Lat> <Long>-81.605711</Long> </BillAddr> <ShipAddr> <Id>98</Id> <Line1>2007 Sailborough Ct Winter Garden, FL 34787</Line1> <Lat>28.522938</Lat> <Long>-81.605711</Long> </ShipAddr> <DueDate>2015-05-23</DueDate> <TotalAmt>2000.00</TotalAmt> <ApplyTaxAfterDiscount>false</ApplyTaxAfterDiscount> <PrintStatus>NeedToPrint</PrintStatus> <EmailStatus>NotSet</EmailStatus> <Balance>2000.00</Balance> <Deposit>0</Deposit> <AllowIPNPayment>false</AllowIPNPayment> <AllowOnlinePayment>false</AllowOnlinePayment> <AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment> <AllowOnlineACHPayment>false</AllowOnlineACHPayment> </Invoice> </IntuitResponse>

as I said looking in the sandbox UI I did see the results.  I see in the private comments my text that I put. (or statement memo area)

Now for my problem: Trying to link the payment to the transaction.
According to the documentation and some guess work on my part I assume I got to go to UPDATE for the invoice and I need to supply my customerRef for the client, update the SyncToken by '1', and supply the linkedtransaction xml I will post what I tried to do so you can tell me what I did wrong.  Keep in mind my payment ID was 162, I assume this is what is meant by TxnId?
So my new XML command to try and link the transaction this time is...
<Invoice xmlns="http://schema.intuit.com/finance/v3" domain="QBO" sparse="true">
    <Id>163</Id>
    <SyncToken>1</SyncToken>
    <MetaData>
      <CreateTime>2014-10-15T14:13:24-07:00</CreateTime>
      <LastUpdatedTime>2014-10-15T14:13:24-07:00</LastUpdatedTime>
    </MetaData>
  <PrivateNote>Invoice update Test</PrivateNote>
  <LinkedTxn>
      <TxnId>162</TxnId>
     <TxnType>Payment</TxnType>
</LinkedTxn>
  </Invoice>

This returned the following response...
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-04-23T05:40:03.383-07:00">
  <Invoice domain="QBO" sparse="false">
    <Id>163</Id>
    <SyncToken>1</SyncToken>
    <MetaData>
      <CreateTime>2015-04-23T05:26:58-07:00</CreateTime>
      <LastUpdatedTime>2015-04-23T05:31:36-07:00</LastUpdatedTime>
    </MetaData>
    <CustomField>
      <DefinitionId>1</DefinitionId>
      <Name>Crew #</Name>
      <Type>StringType</Type>
    </CustomField>
    <DocNumber>1049</DocNumber>
    <TxnDate>2015-04-23</TxnDate>
    <PrivateNote>Invoice update Test</PrivateNote>
    <Line>
      <Id>1</Id>
      <LineNum>1</LineNum>
      <Amount>2000.00</Amount>
      <DetailType>SalesItemLineDetail</DetailType>
      <SalesItemLineDetail>
        <ItemRef name="Concrete">3</ItemRef>
        <TaxCodeRef>NON</TaxCodeRef>
      </SalesItemLineDetail>
    </Line>
    <Line>
      <Amount>2000.00</Amount>
      <DetailType>SubTotalLineDetail</DetailType>
      <SubTotalLineDetail />
    </Line>
    <TxnTaxDetail>
      <TotalTax>0</TotalTax>
    </TxnTaxDetail>
    <CustomerRef name="ZeanabArafat">61</CustomerRef>
    <BillAddr>
      <Id>98</Id>
      <Line1>2007 Sailborough Ct Winter Garden, FL 34787</Line1>
      <Lat>28.522938</Lat>
      <Long>-81.605711</Long>
    </BillAddr>
    <ShipAddr>
      <Id>98</Id>
      <Line1>2007 Sailborough Ct Winter Garden, FL 34787</Line1>
      <Lat>28.522938</Lat>
      <Long>-81.605711</Long>
    </ShipAddr>
    <DueDate>2015-05-23</DueDate>
    <TotalAmt>2000.00</TotalAmt>
    <ApplyTaxAfterDiscount>false</ApplyTaxAfterDiscount>
    <PrintStatus>NeedToPrint</PrintStatus>
    <EmailStatus>NotSet</EmailStatus>
    <Balance>2000.00</Balance>
    <Deposit>0</Deposit>
    <AllowIPNPayment>false</AllowIPNPayment>
    <AllowOnlinePayment>false</AllowOnlinePayment>
    <AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
    <AllowOnlineACHPayment>false</AllowOnlineACHPayment>
  </Invoice>
</IntuitResponse>

So looks like it worked no errors... but when I go to check the sandbox UI to see if its connected? I don't see anything, no status for the transaction and no change on the invoice?
What did I do wrong? Am I missing a step?

A:

I found the answer, trick is to create invoices first then reference the invoice via payments.  I was doing in the incorrect order, and after talking to the moderators of intuit I confirmed it was a bug.
Use something like this to link the payment to the invoice
<Payment xmlns="http://schema.intuit.com/finance/v3">
   <CustomerRef name="Customer Name Here">61</CustomerRef>
   <TotalAmt>500</TotalAmt>
       <Line>
       <Amount>500</Amount>
        <LinkedTxn>
            <TxnId>164</TxnId>
            <TxnType>Invoice</TxnType>
        </LinkedTxn>
    </Line>
</Payment>

TxnID is the invoice ID, make sure the amount and total amount line up!

