---
title: Response
slug: xero/response
description: Learn about the response structure and keys returned from a request call in this insightful document. Discover the different parameters included in the response, such as version, action, timestamp, and more. Gain an understanding of the Error key and its 
docTags: 
createdAt: 2021-11-04T07:23:26.000Z
---

Response is the information returned from the Request call. This will be returned in the form of a Map\<String, Object>.

Below is the list of Keys or Parameters returned in the Response Map:

| **Key (String)** | **Value (Object)**                                                                                                      | **Additional Detail**                                                                        |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| version          | ‘1.0’                                                                                                                   | Returns the same version sent in the Request                                                 |
| action           | See the list of available actions.                                                                                      | Returns the same action sent in the Request.                                                 |
| timestamp        | Timestamp in milliseconds (Unix).                                                                                       | The time at which the Response was returned.  This can be used to troubleshoot.              |
| validRequest     | Either true or false.                                                                                                   | True if the Request satisfies the Breadwinner validations; False if it does not              |
| apiErrors        | Returns [Error](https://app.archbee.io/docs/gaRAXzBPU8gEodLU0-0q-/OgomMeMODdbeI0fCIY2t4#ig-error) list as a JSON string | List of errors that occurred while validating the request before making the request to Xero. |
| responseJSON     | Returns the response of the record(s) as a JSON string.                                                                 | Includes the records data as well as any errors that were sent to Breadwinner from Xero.     |

### Error

| **Key (String)** | **Data Type** | **Description**                                                                                                                           |
| ---------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| code             | String        | A short string indicating the error code reported.                                                                                        |
| message          | String        | A detailed explanation of the Error occurred. Example: Breadwinner was unable to process the request as the action parameter was invalid. |

## Errors

### Before requesting Xero

Errors that occur while validating the request, or while making a request to Xero are returned as ‘apiErrors’ in the response.&#x20;

### After requesting Xero

Errors occurred within Xero while processing the request, or while processing the data in Breadwinner are sent as ‘errors’ in the responseJSON key of the Response map.

### Examples

:::::Tabs
::::Tab{title="Breadwinner API Errors"}
Breadwinner does validation prior to calling out to Xero.

:::CodeblockTabs
Invalid Request

```json
{
    action=readCustomer, 
    apiErrors={"errors":[
        {"message":"Breadwinner was unable to process the request as the version parameter was not valid.",
        "code":"INVALID_VERSION"
        }
        ]
    }, 
    timestamp=1635186915365, 
    validRequest=false, 
    version=1.1
}
```
:::
::::

::::Tab{title="Errors that Xero returns"}
The errors that Xero returns will be included as "errors"in the "responseJSON". Below is the example that was reformatted for easier reading.

:::CodeblockTabs
400

```json
{
  action=createCustomer,
  responseJSON={
    "customers": null,
    "errors": [
      {
        "message": "Please enter value(s) for: Display Name",
        "code": "USER_ERROR"
      }
    ],
    "statusCode": "400"
  },
  timestamp=1635239587001,
  validRequest=true,
  version=1.0
}
```
:::
::::
:::::

### Sample Structure on how to parse the Response

```apex
if(respMap.containsKey('apiErrors') &&  respMap.get('apiErrors')!=null){
    // add any custom apex code.
}
else if(respMap.containsKey('responseJSON')  &&  String.isNotBlank((String)respMap.get('responseJSON'))){
    // parse it to Map or optionally to a wrapper
    Map<String,Object> invoiceResponseJSONMap = (Map<String,Object>)JSON.deserializeUntyped((String)respMap.get('responseJSON'));
    
    if(invoiceResponseJSONMap != NULL && invoiceResponseJSONMap.containskey('statusCode') && invoiceResponseJSONMap.get('statusCode')!=null){
        // add any custom apex code.
    }
    if(invoiceResponseJSONMap != NULL && invoiceResponseJSONMap.containskey('invoices') && invoiceResponseJSONMap.get('invoices')!=null){
        // parse it to Object or optionally to a wrapper
        List<Object> soObj = (List<Object>)invoiceResponseJSONMap.get('invoices');
        Map<String,Object> savedSO = (Map<String,Object>)soObj[0];
        // now we are inside the success case, please add your update field (DML) apex code here.
    }
    if(invoiceResponseJSONMap != NULL && invoiceResponseJSONMap.containskey('errors') && invoiceResponseJSONMap.get('errors')!=null){
        // add any custom apex code.
    }
}

```

