Example of a draft sales ( ACCREC) invoice with enough detail to be approved once it's been created.
require 'chilkat'
rest = Chilkat::CkRest.new()
oauth1 = Chilkat::CkOAuth1.new()
oauth1.put_ConsumerKey("OAUTH1_CONSUMER_KEY")
oauth1.put_ConsumerSecret("OAUTH1_CONSUMER_SECRET")
oauth1.put_Token("OAUTH1_TOKEN")
oauth1.put_TokenSecret("OAUTH1_TOKEN_SECRET")
oauth1.put_SignatureMethod("RSA-SHA1")
rsaKey = Chilkat::CkPrivateKey.new()
# Insert code here to load the RSA private key...
# ...
# then call SetRsaKey to provide the RSA key to the OAuth1 class.
success = oauth1.SetRsaKey(rsaKey)
rest.SetAuthOAuth1(oauth1,false)
success = rest.Connect("api.xero.com",443,true,true)
if (success != true)
print rest.lastErrorText() + "\n";
exit
end
# The following code creates the JSON request body.
# The JSON created by this code is shown below.
jsonReq = Chilkat::CkJsonObject.new()
jsonReq.UpdateString("Type","ACCREC")
jsonReq.UpdateString("Contact.ContactID","eaa28f49-6028-4b6e-bb12-d8f6278073fc")
jsonReq.UpdateString("Date","/Date(1518685950940+0000)/")
jsonReq.UpdateString("DueDate","/Date(1518685950940+0000)/")
jsonReq.UpdateString("DateString","2009-05-27T00:00:00")
jsonReq.UpdateString("DueDateString","2009-06-06T00:00:00")
jsonReq.UpdateString("LineAmountTypes","Exclusive")
jsonReq.UpdateString("LineItems[0].Description","Consulting services as agreed (20% off standard rate)")
jsonReq.UpdateString("LineItems[0].Quantity","10")
jsonReq.UpdateString("LineItems[0].UnitAmount","100.00")
jsonReq.UpdateString("LineItems[0].AccountCode","200")
jsonReq.UpdateString("LineItems[0].DiscountRate","20")
sbReq = Chilkat::CkStringBuilder.new()
jsonReq.EmitSb(sbReq)
rest.AddHeader("Content-Type","application/json")
sbResponse = Chilkat::CkStringBuilder.new()
success = rest.FullRequestSb("POST","/api.xro/2.0/Invoices",sbReq,sbResponse)
if (success != true)
print rest.lastErrorText() + "\n";
exit
end
if (rest.get_ResponseStatusCode() != 200)
print "Received error response code: " + rest.get_ResponseStatusCode().to_s() + "\n";
print "Response body:" + "\n";
print sbResponse.getAsString() + "\n";
exit
end
print "Example Completed." + "\n";
{
"Type": "ACCREC",
"Contact": {
"ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc"
},
"Date": "\/Date(1518685950940+0000)\/",
"DueDate": "\/Date(1518685950940+0000)\/",
"DateString": "2009-05-27T00:00:00",
"DueDateString": "2009-06-06T00:00:00",
"LineAmountTypes": "Exclusive",
"LineItems": [
{
"Description": "Consulting services as agreed (20% off standard rate)",
"Quantity": "10",
"UnitAmount": "100.00",
"AccountCode": "200",
"DiscountRate": "20"
}
]
}