Skip to content

RESTful example of creating a new Invoice and Memo entry

Brian Wharton edited this page Jul 15, 2015 · 3 revisions

##Example of how to create a new Invoice and Memo batch

####Create a screen object with all the defaults Call the templates/getNewScreen API call The easiest way to get going with creating a new entry in the Invoice and Memo is to create a blank screen object with all the defaults pre-filled by the ctAPI API. This is done by calling the below API call

  • Endpoint: /api/accountsReceivable/invoiceAndMemo/templates/getNewScreen
  • HttpMethod: POST
  • Request PayLoad: InvoiceAndMemo.Screen object (In this case, pass a null: {})
  • Response PayLoad: InvoiceAndMemo.Screen object (this will be the returned screen object with all the Dynamics SL defaults loaded
  • Headers:
    • Content-Type: either application/json or application/xml
    • Accept: either application/json or application/xml
    • Authorization: your APIKey and Secret Key (see Prerequisites and Authentication for more information)

When you post a {} in the body, you will get something similar returned as the Response PayLoad:

{
"errorMessage": "",
"myBatch": {
	"errorMessage": "",
	"notes": "",
	"resultCode": 0,
	"Acct": "",
	"AutoRev": 0,
	"AutoRevCopy": 0,
	"BalanceType": "",
	"BankAcct": "",
	"BankSub": "",
	"BaseCuryID": "USD",
	"BatNbr": "",
	"BatType": "",
	"clearamt": 0,
	"Cleared": 0,
	"CpnyID": "0060",
	"Crtd_DateTime": "1900-01-01T00:00:00",
	"Crtd_Prog": "08050",
	"Crtd_User": "SYSADMIN",
	"CrTot": 0,
	"CtrlTot": 0,
	"CuryCrTot": 0,
	"CuryCtrlTot": 0,
	"CuryDepositAmt": 0,
	"CuryDrTot": 0,
	"CuryEffDate": "1900-01-01T00:00:00",
	"CuryId": "BAS ",
	"CuryMultDiv": "M",
	"CuryRate": 0,
	"CuryRateType": "",
	"Cycle": 0,
	"DateClr": "1900-01-01T00:00:00",
	"DateEnt": "2015-07-15T00:00:00",
	"DepositAmt": 0,
	"Descr": "",
	"DrTot": 0,
	"EditScrnNbr": "08050",
	"GLPostOpt": "S",
	"JrnlType": "AR",
	"LedgerID": "",
	"LUpd_DateTime": "1900-01-01T00:00:00",
	"LUpd_Prog": "08050",
	"LUpd_User": "SYSADMIN",
	"Module": "AR",
	"NbrCycle": 0,
	"NoteID": 0,
	"OrigBatNbr": "",
	"OrigCpnyID": "",
	"OrigScrnNbr": "",
	"PerEnt": "",
	"PerPost": "199912",
	"Rlsed": 0,
	"S4Future01": "",
	"S4Future02": "",
	"S4Future03": 0,
	"S4Future04": 0,
	"S4Future05": 0,
	"S4Future06": 0,
	"S4Future07": "1900-01-01T00:00:00",
	"S4Future08": "1900-01-01T00:00:00",
	"S4Future09": 0,
	"S4Future10": 0,
	"S4Future11": "",
	"S4Future12": "",
	"Status": "H",
	"Sub": "",
	"User1": "AC",
	"User2": "",
	"User3": 0,
	"User4": 0,
	"User5": "",
	"User6": "",
	"User7": "1900-01-01T00:00:00",
	"User8": "1900-01-01T00:00:00"
},
"myARDoc": {
	"errorMessage": "",
	"notes": "",
	"resultCode": 0,
	"AcctNbr": "",
	"AgentID": "",
	"ApplAmt": 0,
	"ApplBatNbr": "",
	"ApplBatSeq": 0,
	"ASID": 0,
	"BankAcct": "",
	"BankID": "",
	"BankSub": "",
	"BatNbr": "",
	"BatSeq": 0,
	"Cleardate": "1900-01-01T00:00:00",
	"CmmnAmt": 0,
	"CmmnPct": 0,
	"ContractID": "",
	"CpnyID": "0060",
	"Crtd_DateTime": "1900-01-01T00:00:00",
	"Crtd_Prog": "08050",
	"Crtd_User": "SYSADMIN",
	"CurrentNbr": 0,
	"CuryApplAmt": 0,
	"CuryClearAmt": 0,
	"CuryCmmnAmt": 0,
	"CuryDiscApplAmt": 0,
	"CuryDiscBal": 0,
	"CuryDocBal": 0,
	"CuryEffDate": "1900-01-01T00:00:00",
	"CuryId": "BAS ",
	"CuryMultDiv": "M",
	"CuryOrigDocAmt": 0,
	"CuryRate": 0,
	"CuryRateType": "",
	"CuryStmtBal": 0,
	"CuryTaxTot00": 0,
	"CuryTaxTot01": 0,
	"CuryTaxTot02": 0,
	"CuryTaxTot03": 0,
	"CuryTxblTot00": 0,
	"CuryTxblTot01": 0,
	"CuryTxblTot02": 0,
	"CuryTxblTot03": 0,
	"CustId": "",
	"CustOrdNbr": "",
	"Cycle": 0,
	"DiscApplAmt": 0,
	"DiscBal": 0,
	"DiscDate": "2015-07-15T00:00:00",
	"DocBal": 0,
	"DocClass": "",
	"DocDate": "2015-07-15T00:00:00",
	"DocDesc": "",
	"DocType": "PA",
	"DraftIssued": 0,
	"DueDate": "2015-07-15T00:00:00",
	"InstallNbr": 0,
	"JobCntr": 0,
	"LineCntr": 0,
	"LUpd_DateTime": "1900-01-01T00:00:00",
	"LUpd_Prog": "08050",
	"LUpd_User": "SYSADMIN",
	"MasterDocNbr": "",
	"NbrCycle": 0,
	"NoPrtStmt": 0,
	"NoteId": 0,
	"OpenDoc": 0,
	"OrdNbr": "",
	"OrigBankAcct": "",
	"OrigBankSub": "",
	"OrigCpnyID": "",
	"OrigDocAmt": 0,
	"OrigDocNbr": "",
	"PC_Status": "",
	"PerClosed": "",
	"PerEnt": "",
	"PerPost": "",
	"PmtMethod": "",
	"ProjectID": "",
	"RefNbr": "000128",
	"RGOLAmt": 0,
	"Rlsed": 0,
	"S4Future01": "",
	"S4Future02": "",
	"S4Future03": 0,
	"S4Future04": 0,
	"S4Future05": 0,
	"S4Future06": 0,
	"S4Future07": "1900-01-01T00:00:00",
	"S4Future08": "1900-01-01T00:00:00",
	"S4Future09": 0,
	"S4Future10": 0,
	"S4Future11": "",
	"S4Future12": "",
	"ServiceCallID": "",
	"ShipmentNbr": 0,
	"SlsperId": "",
	"Status": "",
	"StmtBal": 0,
	"StmtDate": "1900-01-01T00:00:00",
	"TaskID": "",
	"TaxCntr00": 0,
	"TaxCntr01": 0,
	"TaxCntr02": 0,
	"TaxCntr03": 0,
	"TaxId00": "",
	"TaxId01": "",
	"TaxId02": "",
	"TaxId03": "",
	"TaxTot00": 0,
	"TaxTot01": 0,
	"TaxTot02": 0,
	"TaxTot03": 0,
	"Terms": "",
	"TxblTot00": 0,
	"TxblTot01": 0,
	"TxblTot02": 0,
	"TxblTot03": 0,
	"User1": "",
	"User2": "",
	"User3": 0,
	"User4": 0,
	"User5": "",
	"User6": "",
	"User7": "1900-01-01T00:00:00",
	"User8": "1900-01-01T00:00:00",
	"WSID": 0
},
"myARTran": null,
"batchNote": null,
"documentNote": null
}

####Overriding values in the returned screen You will then want to override values in the returned screen. Things that would be overridden could be:

  • CustId: Put the customer ID that you want to tie this invoice to
  • DocType: If you are creating an Invoice, set this to "IN"
  • DocDate: Normally would be today. But you can set this to whatever you need.
  • DueDate: Put the date you want the invoice to be due
  • Terms: This would be the terms you want to set the invoice to be. Normally comes from the Customer
  • Acct: The bank account you want to tie to the transaction
  • Sub: the Sub Account you want to tie to the transaction

Getting a CustId

NOTE: You can retrieve a customer record (and find out terms, etc.) via the PV Lookup using the endpoint:

api/accountsReceivable/invoiceAndMemo/pvLookup/customers?custID={custID}

Where you can do a partial word search on the custID passed in the query string, which brings back an array of Customer records.

You can also use the Customers web service to bring back a complete customer record (once you know a valid custID) by the following endpoint:

api/customer/{custID}

This customer API call will retrieve a complete Customer Object.

Getting Terms You can retrieve a list of valid terms ID's using the following endpoint:

api/accountsReceivable/invoiceAndMemo/pvLookup/terms?acct={acct}

Getting Acct You can retrieve a list of valid Acct ID's using the following endpoint:

api/accountsReceivable/invoiceAndMemo/pvLookup/acctXrefs?acct={acct}

Getting Sub You can retrieve a list of valid Sub Account ID's using the following endpoint:

api/accountsReceivable/invoiceAndMemo/pvLookup/subXrefs?sub={sub}

NOTE: as with all pvLookup's, they are partial word searchs. If you leave them blank, you will retrieve all records.

Example: 
api/accountsReceivable/invoiceAndMemo/pvLookup/subXrefs?sub=

The above will retrieve all sub accounts since the field value for sub is left blank.

####Additional Fields Now that you have overridden key fields in the Batch and ARDoc objects of the screen, you can now add other fields that aren't set by the getNewScreen API call. These are:

  • batchNote: A note tied to the Batch
  • documentNote: A note tied to the Document
  • myARTran: the individual transaction records of the screen

Adding Notes for batchNote and documentNote

Notes are defined by the SNote class. This looks like the following:

{
}

To update the notes in the screen object, you can do something similar to the example below:

"batchNote": null,
"documentNote": null

Saving the Screen

Once you have updated the screen object (along with all of it's child data), you can then save the screen back to Dynamics SL with the following endpoint:

api/accountsReceivable/invoiceAndMemo/screen
  • HttpMethod: POST if it is a new record and PUT if it is an existing record
  • Request PayLoad: InvoiceAndMemo.Screen object (You will post the InvoiceAndMemo.Screen object you modified above.)
  • Response PayLoad: InvoiceAndMemo.Screen object (this will be the returned screen object with all the Dynamics SL defaults loaded
  • Headers:
    • Content-Type: either application/json or application/xml
    • Accept: either application/json or application/xml
    • Authorization: your APIKey and Secret Key (see Prerequisites and Authentication for more information)
Clone this wiki locally