---
title: Update
slug: xero/update
description: Learn how to update a purchase order in Xero using Apex code. This document includes the necessary fields required for a purchase order, as well as line item details. Discover how to create a request JSON and utilize the Breadwinner Global API to update t
docTags: 
createdAt: 2021-11-02T07:47:50.000Z
---

To update a PO in Xero, make sure you set the field "PurchaseOrderID" with the unique reference value (ID generated by Xero for the PO)&#x20;

:::CodeblockTabs
Request

```apex
//  Create a Map to store all the data of a Purchase Order
List<Object> purchaseOrderList = new List<Object>();
Map<String, Object> purchaseOrderMap = new Map<String, Object>();
    purchaseOrderMap.put('DateString', '2021-11-11T00:00:00');
    purchaseOrderMap.put('DeliveryDate', '2021-12-06T00:00:00');
    purchaseOrderMap.put('Status', 'AUTHORISED');
    purchaseOrderMap.put('PurchaseOrderID', '2fef007e-1979-4634-9bb7-87c4559a0038');

    //  Initializing the Contact
    Map<String, Object> contactMap = new Map<String, Object>();
    contactMap.put('ContactID', 'c84ebb15-0a8d-4145-933f-203e68d014a0');
    purchaseOrderMap.put('Contact', contactMap);
    //  Initializing the Purchase Order Line Items
    List<Object> lineItemList = new List<Object>();
        Map<String, Object> lineItemMap = new Map<String, Object>(); 
        lineItemMap.put('Description', 'Line Item Description updated');
        lineItemMap.put('UnitAmount', 100);
        lineItemMap.put('Quantity', 10);
		lineItemMap.put('AccountCode', '310');
        lineItemMap.put('LineItemID', 'fd9bd48c-9f10-44de-aee4-c6185b2868c3');
        lineItemList.add(lineItemMap);
        
    //  Adding the Line Items to Purchase Order
    purchaseOrderMap.put('LineItems', lineItemList);
    purchaseOrderList.add(purchaseOrderMap);

//  Initializing the RequestJSON Data to be passed.
    Map<String, Object> reqJSONMap = new Map<String, Object>(); 
    reqJSONMap.put('purchaseOrders', purchaseOrderList); 
    String reqJSON = JSON.serialize(reqJSONMap); 

    Map<String, Object> finalReqMap = new Map<String, Object>();  
    finalReqMap.put('version', '1.0'); 
    finalReqMap.put('action', 'updatePurchaseOrder'); 
    finalReqMap.put('RequestJSON', reqJSON); 
    finalReqMap.put('skipDML', false); 
    //Required, if Xero Multi-Org is enabled in Breadwinner. 
    finalReqMap.put('xeroOrgId', '!aa00TM');
    System.debug('Request ::: ' + finalReqMap);

//  Placing a request to Breadwinner Global API
    Map<String, Object> respMap = bread_winner.BreadwinnerXeroAPI.call(finalReqMap);
    System.debug('Response ::: ' + respMap);
```

Response

```json
{
   action=updatePurchaseOrder,
   responseJSON={
       "statusCode":200,
      "purchaseOrders":[
         {
            "UpdatedDateUTC":null,
            "Type":"PURCHASEORDER",
            "TotalTax":0.00,
            "TotalDiscount":0.00,
            "Total":1000.00,
            "Telephone":"",
            "SubTotal":1000.00,
            "Status":"AUTHORISED",
            "SentToContact":false,
            "SalesforceRecordId":"a0K7F00001eFt7nUAC",
            "Reference":null,
            "PurchaseOrderNumber":"PO-0001",
            "PurchaseOrderID":"2fef007e-1979-4634-9bb7-87c4559a0038",
            "Payments":null,
            "LineItems":[
               {
                  "UnitAmount":100.0000,
                  "Tracking":[
                     
                  ],
                  "TaxType":"INPUT",
                  "TaxAmount":0.00,
                  "Quantity":10.0000,
                  "LineItemID":"fd9bd48c-9f10-44de-aee4-c6185b2868c3",
                  "LineAmount":1000.00,
                  "ItemCode":null,
                  "DiscountRate":null,
                  "Description":"Line Item Description updated",
                  "AccountCode":"310"
               }
            ],
            "LineAmountTypes":"Exclusive",
            "IsDiscounted":false,
            "InvoiceNumber":null,
            "InvoiceID":null,
            "HasErrors":false,
            "DueDateString":null,
            "DueDate":null,
            "DeliveryInstructions":"",
            "DeliveryDateString":"2021-12-06T00:00:00",
            "DeliveryDate":"2021-12-06",
            "DeliveryAddress":"",
            "DateVariable":"/Date(1636588800000+0000)/",
            "DateString":"2021-11-11T00:00:00",
            "CurrencyRate":1.0000000000,
            "CurrencyCode":"INR",
            "CreditNotes":null,
            "Contact":{
               "Name":"Test Contact 2",
               "ContactStatus":"ACTIVE",
               "ContactID":"c84ebb15-0a8d-4145-933f-203e68d014a0"
            },
            "BrandingThemeID":null,
            "AttentionTo":"",
            "AmountPaid":null,
            "AmountDue":null,
            "AmountCredited":0.00
         }
      ],
      "errors":[
         
      ]
   },
   timestamp=1636643453213,
   validRequest=true,
   version=1.0
}
```
:::

