QBOv3 XML验证错误2500(无效的参考ID)

时间:2014-03-07 03:52:00

标签: ruby-on-rails ruby quickbooks quickbooks-online

我正在尝试使用quickbooks-ruby gem在quickbooks上创建测试发票。注意我在QB有一个没有任何东西的测试帐户:发票,客户等。这是一个仅为测试目的而创建的新帐户。所以这是我的代码:

service = Quickbooks::Service::Invoice.new
service.company_id = current_user.company_id
service.access_token = create_consumer

qb_invoice = Quickbooks::Model::Invoice.new
qb_invoice.customer_id = 123

line_item = Quickbooks::Model::InvoiceLineItem.new
line_item.amount = 100
line_item.sales_item! do |detail|
  detail.unit_price = 100
  detail.quantity = 1
  detail.item_id = 1
end

qb_invoice.line_items << line_item

res = service.create qb_invoice
p res.id #exception!

def create_consumer
  OAuth::AccessToken.new(.....)
end

请求:

   METHOD = post
   RESOURCE = https://qb.sbfinance.intuit.com/v3/company/fdsfdsfdsfds123/invoice

<?xml version="1.0" encoding="utf-8"?>
<Invoice xmlns="http://schema.intuit.com/finance/v3" sparse="false">
  <Line>
    <Amount>100.0</Amount>
    <DetailType>SalesItemLineDetail</DetailType>
    <SalesItemLineDetail>
    <ItemRef>1</ItemRef>
    <UnitPrice>100.0</UnitPrice>
    <RatePercent>0.0</RatePercent>
    <Qty>1.0</Qty>
    </SalesItemLineDetail>
  </Line>
  <CustomerRef>123</CustomerRef>
  <TotalAmt>0.0</TotalAmt>
  <Balance>0.0</Balance>
  <Deposit>0.0</Deposit>
</Invoice>

并回复错误:

RESPONSE CODE = 400

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-03-06T19:30:49.168-08:00">
  <Fault type="ValidationFault">
    <Error code="2500" element="">
      <Message>Invalid Reference Id</Message>
      <Detail>Invalid Reference Id : Something you're trying to use has been deleted. Check the fields with accounts, customers, items, vendors or employees.
      </Detail>
    </Error>
  </Fault>
</IntuitResponse>

可能是因为id = 123的客户不存在?如果没有,那么原因是什么?

1 个答案:

答案 0 :(得分:3)

请检查您的帐户中是否有客户(ID-123)和项目(Id-1)。

如果没有,则使用apiexplorer / code创建这两个条目,并使用相应的对象ID。

ApiExplorer - https://developer.intuit.com/apiexplorer?apiname=V3QBO

EntityRef - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference

ApiExplorer -

enter image description here

参考 - https://developer.intuit.com/docs/0025_quickbooksapi/0010_getting_started/0015_firstrequest

由于