Solved

REST API - Add PO Receipt to Bill - Need Help

  • 18 May 2021
  • 6 replies
  • 801 views

Userlevel 1
Badge

Hi community,

Where I work we have been using the REST API quite a lot to automate redundant tasks in Acumatica and tie some of our in house software in to it. However, I do not have a lot of experience using “Actions” aside from the “Release” button and so have come to you for help.

 

Objective: 

Add a PO Receipt to an existing Bill.

 

The Bill has already been created and is on “Hold”. I have added the “AddPOReceipt” action to my extended web service endpoint. When I POST to “AddPOReceipt” endpoint I get a 204 response to which I follow up with a GET to check the status of the request and I get a 200 response. When I look at the bill there is no receipt added to it though. What am I doing wrong?

 

myurl = "https://4iiii.acumatica.com/entity/ManleyEndpoint/17.200.001/Bill/AddPOReceipt"

jsonUpdate = {
'entity': {
'Type': {'value': 'Bill'},
'ReferenceNbr': {'value': '006357'},
},
'parameters': {
'ReceiptNbr': {'value': '003341'},
'ReceiptType': {'value': 'Receipt'},
'Selected': {'value': 1},
}

}


response = requests.post(url=myurl, json=jsonUpdate, headers=headers, cookies=cookies)

 

icon

Best answer by manley75 19 May 2021, 18:16

View original

6 replies

Userlevel 7
Badge +5

Hello manley75,

Action is not actually a recommended way of doing this through API. 

Especially in the case when you have popup window where you need to select things through API. 

 

You can add lines from specific PO receipt to AP Bill using just put request, like that:

Method: PUT 
Host: [<Acumatica ERP instance URL>]/entity/Default/20.200.001/Bill
Body:
{
"DocumentType": {
"value": "Bill"
},
"ReferenceNbr": {
"value": "006357"
},
"Details": [
{
"POReceiptNbr": {
"value": "003341"
},
"POReceiptLine": {
"value": 1
}
}
]
}

 

See more here:

https://help-2021r1.acumatica.com/(W(58))/Help?ScreenId=ShowWiki&pageid=a1116acb-66aa-4415-8148-5bbab45b0a50

It is also available in the default endpoint, so you don’t even need to create a custom one. 

Userlevel 1
Badge

Hello manley75,

Action is not actually a recommended way of doing this through API. 

Especially in the case when you have popup window where you need to select things through API. 

 

You can add lines from specific PO receipt to AP Bill using just put request, like that:

Method: PUT 
Host: [<Acumatica ERP instance URL>]/entity/Default/20.200.001/Bill
Body:
{
"DocumentType": {
"value": "Bill"
},
"RefNbr": {
"value": "Your Bill Nbr Here"
},
"Details": [
{
"POReceiptNbr": {
"value": "000001"
},
"POReceiptLine": {
"value": 1
}
}
]
}

 

See more here:

https://help-2021r1.acumatica.com/(W(58))/Help?ScreenId=ShowWiki&pageid=a1116acb-66aa-4415-8148-5bbab45b0a50

It is also available in the default endpoint, so you don’t even need to create a custom one. 

 

Hey dnaumov,

I should have mentioned that we did initially start with what you are suggesting but were unable to make it fully work. All of the information would get entered into the Bill except for the Purchase Order number and the Receipt number on the detail line item. 

exceptionMessage:'Purchase order RO - 211127 not found.'

 

We are not sure why we get the message but we believe it is because the Purchase Order has a status of Complete. We cannot add the PO and Receipt numbers in manually through the UI either. However, when we use the “Add PO Receipt” button it works and links the Bill to the Receipt in the PO. So this is why we went down the path of trying to get the API to work with the AddPOReceipt button.

 

Perhaps we are missing something?

 

 

Userlevel 7
Badge +5

manley75

I’m not sure why you’d see ‘Purchase Order not found’ exception while you linking Bill to Purchase receipt. 

Could you provide a request snippet so I can understand that better?

 

As for the fields being disabled on UI, there is a special handler for API that processes those field.

Userlevel 1
Badge

Here is the snippet of code making the request

 

export async function payPurchaseOrder(loginContext:LoginContext, poNumber:string):Promise<{bill:AcumaticaBill, check:AcumaticaCheck}> {
try {
const pos:AcumaticaPurchaseOrder[] = await loginContext.get('PurchaseOrder', `?$filter=OrderNbr eq '${poNumber}'&$expand=Details`, 'ManleyEndpoint', 0);
const po = pos[0];
const vendor:AcumaticaVendor = await loginContext.get('Vendor', `${po.VendorID.value}`, 'ManleyEndpoint', 0);
const receipt:AcumaticaReceiptDetailOData[] = await loginContext.getOData('Art_PurchaseReceiptDetail', 0, `$filter=POOrderNbr eq '${poNumber}'`);
const billDetails = receipt.map((receiptLine) => {
const myPoDetail = po.Details.find((poDetail) => {
return poDetail.OrderNbr.value === receiptLine.POOrderNbr && poDetail.LineNbr.value === receiptLine.POLineNbr;
})
if(!myPoDetail) {
throw new Error(`Could not find the appropriate purchaseorder line item when trying to make a bill for receipt ${receiptLine.OrderNbr}, line ${receiptLine.LineNbr}`);
}
return {
"note": `Payment for PO number ${poNumber}`,
"Account": { value: "2020"},
"Amount": { value: myPoDetail.UnitCost.value},
"Branch": { value: "CORPORATE"},
"Description": { "value": `Received with ${receiptLine.OrderNbr} for PO ${receiptLine.POOrderNbr}` },
"ExtendedCost": { value: myPoDetail.ExtendedCost.value},
"POOrderNbr": { value: `${receiptLine.POOrderNbr}`},
"POOrderType": { value: "Normal"},
"POOrderLine": { value: 1},
"Qty": { value: parseFloat(receiptLine.ReceiptQty)},
"Subaccount": { value: "00" },
"TaxCategory": { value: myPoDetail.TaxCategory.value},
"InventoryID": { value: receiptLine.InventoryID},
"TransactionDescription": {value: `$${myPoDetail.ExtendedCost.value} for ${parseFloat(receiptLine.ReceiptQty).toFixed(0)} x ${receiptLine.InventoryID} for PO ${receiptLine.POOrderNbr}`},
"UnitCost": { value: myPoDetail.UnitCost.value},
"UOM": { value: myPoDetail.UOM.value},
"ReceiptNbr": { value: receiptLine.OrderNbr},
"ReceiptLine": { value: receiptLine.LineNbr},
"POType2": { value: receiptLine.POOrderType},
"PONbr2": { value: receiptLine.POOrderNbr},
}
});
const myBill:any = {
"note": "Created by internal API for PO " + poNumber,
CreateBill: {value: true},
"Amount": null, // { value: po.OrderTotal.value},
"ApprovedForPayment": { value: false},
"Balance": null, // { value: po.OrderTotal.value},
"BranchID": { value: "CORPORATE"},
"CashAccount": null, // { value: vendor.CashAccount.value},
"CurrencyID": { value: po.CurrencyID.value},
"Date": null,
"Description": { value: po.Description.value},
"DueDate": null,
"Hold": { value: true},
"LocationID": { value: po.Location.value},
"PostPeriod": null, // {value: "112021"},
"ReferenceNbr": null, // this is the primary key. will be created by acumatica
"Status": null,
"TaxTotal": null, // { value: 0 },
"Terms": null, // { value: vendor.Terms.value },
"Type": { value: "Bill"},
"Vendor": { value: vendor.VendorID.value},
"VendorRef": { value: (po.VendorRef.value || "Unknown")},
"Details": billDetails, /*,*/
}
let puttedBill:AcumaticaBill;
try {
puttedBill = await loginContext.put('Bill', myBill, 'ManleyEndpoint');
puttedBill.Hold = {value: false};
puttedBill = await loginContext.put('Bill', puttedBill, 'ManleyEndpoint');
} catch(e) {
// hmm.. This can happen if there was already another bill with the same vendor ref because a previous bill-create failed partway through.
// test
puttedBill = await loginContext.get('Bill', `?$filter=VendorRef eq '${myBill.VendorRef.value}'`, 'ManleyEndpoint', 0);
debugger;
}
}

 

Userlevel 7
Badge +5

manley75

Honestly, I was not able to understand how that code creates Bill lines mapped to Purchase receipt lines. 

 

I’d suggest to try example that I’ve provided above in Postman to see how it works and then try implementing that in your code. 

 

Please also note that this method only works in default endpoint or endpoints derived from default. 

Userlevel 1
Badge

Hey @dnaumov ,

Not a problem, we have managed to figure the problem out and it looks to be the endpoint version 17.200.001. After choosing version 18.200.001 our scripting seems to work.

Thank you for your help and time!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved