/// <summary> /// Return a list of fixed assets /// </summary> /// <param name="status">Required when retrieving a collection of assets. See Asset Status Codes</param> /// <param name="onlypage">Up to 100 records will be returned in a single API call with line items details (optional)</param> /// <param name="orderBy">Requests can be ordered by AssetType, AssetName, AssetNumber, PurchaseDate and PurchasePrice. If the asset status is DISPOSED it also allows DisposalDate and DisposalPrice. (optional)</param> /// <param name="sortDirection">ASC or DESC (optional)</param> /// <param name="filterBy">A string that can be used to filter the list to only return assets containing the text. Checks it against the AssetName, AssetNumber, Description and AssetTypeName fields. (optional)</param> /// <param name="pageSize">The number of records returned per page. By default the number of records returned is 10. (optional)</param> /// <returns>List of Assets</returns> public List <Asset> Assets(AssetStatusQueryParam status, int?onlypage = null, string orderBy = null, string sortDirection = null, string filterBy = null, int pageSize = 50) { int?page = 1; if (onlypage.HasValue) { page = onlypage.Value; } try { var records = new List <Asset>(); // Hold the records int count = pageSize; // This is how many per page - setting this will ensure we check for the first page is a full 100 and loop until all returned while (count == pageSize) { if (page == -1) { page = null; // This allows a quick first page of records } var results = Task.Run(() => APIClient.GetAssetsAsync(APICore.XeroConfig.AccessTokenSet.AccessToken, APICore.XeroConfig.SelectedTenantID, status, page, pageSize, orderBy, sortDirection, filterBy)).ConfigureAwait(false).GetAwaiter().GetResult();; if (results != null && results.Items != null && results.Items.Count > 0) { records.AddRange(results.Items); // Add the next page records returned count = results.Items.Count; // Record the number of records returned in this page. if less than 100 then the loop will exit otherwise get the next page full } else { count = 0; } if (page != null) { page++; } if (onlypage.HasValue) { count = -1; } } if (records.Count > 0) { return(records); } } catch (Exception ex) { var er = ex.InnerException as Xero.NetStandard.OAuth2.Client.ApiException; throw new Xero.NetStandard.OAuth2.Client.ApiException(er.ErrorCode, er.Message, er.ErrorContent); } return(null); }
/// <summary> /// searches fixed asset By passing in the appropriate options, you can search for available fixed asset in the system /// </summary> /// <exception cref="Xero.NetStandard.OAuth2.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="xeroTenantId">Xero identifier for Tenant</param> /// <param name="status">Required when retrieving a collection of assets. See Asset Status Codes</param> /// <param name="page">Results are paged. This specifies which page of the results to return. The default page is 1. (optional)</param> /// <param name="pageSize">The number of records returned per page. By default the number of records returned is 10. (optional)</param> /// <param name="orderBy">Requests can be ordered by AssetType, AssetName, AssetNumber, PurchaseDate and PurchasePrice. If the asset status is DISPOSED it also allows DisposalDate and DisposalPrice. (optional)</param> /// <param name="sortDirection">ASC or DESC (optional)</param> /// <param name="filterBy">A string that can be used to filter the list to only return assets containing the text. Checks it against the AssetName, AssetNumber, Description and AssetTypeName fields. (optional)</param> /// <returns>Task of ApiResponse (Assets)</returns> public async System.Threading.Tasks.Task <Xero.NetStandard.OAuth2.Client.ApiResponse <Assets> > GetAssetsAsyncWithHttpInfo(string accessToken, string xeroTenantId, AssetStatusQueryParam status, int?page = null, int?pageSize = null, string orderBy = null, string sortDirection = null, string filterBy = null) { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new Xero.NetStandard.OAuth2.Client.ApiException(400, "Missing required parameter 'xeroTenantId' when calling AssetApi->GetAssets"); } // verify the required parameter 'status' is set if (status == null) { throw new Xero.NetStandard.OAuth2.Client.ApiException(400, "Missing required parameter 'status' when calling AssetApi->GetAssets"); } Xero.NetStandard.OAuth2.Client.RequestOptions requestOptions = new Xero.NetStandard.OAuth2.Client.RequestOptions(); String[] @contentTypes = new String[] { }; // to determine the Accept header String[] @accepts = new String[] { "application/json" }; foreach (var cType in @contentTypes) { requestOptions.HeaderParameters.Add("Content-Type", cType); } foreach (var accept in @accepts) { requestOptions.HeaderParameters.Add("Accept", accept); } if (status != null) { foreach (var kvp in Xero.NetStandard.OAuth2.Client.ClientUtils.ParameterToMultiMap("", "status", status)) { foreach (var value in kvp.Value) { requestOptions.QueryParameters.Add(kvp.Key, value); } } } if (page != null) { foreach (var kvp in Xero.NetStandard.OAuth2.Client.ClientUtils.ParameterToMultiMap("", "page", page)) { foreach (var value in kvp.Value) { requestOptions.QueryParameters.Add(kvp.Key, value); } } } if (pageSize != null) { foreach (var kvp in Xero.NetStandard.OAuth2.Client.ClientUtils.ParameterToMultiMap("", "pageSize", pageSize)) { foreach (var value in kvp.Value) { requestOptions.QueryParameters.Add(kvp.Key, value); } } } if (orderBy != null) { foreach (var kvp in Xero.NetStandard.OAuth2.Client.ClientUtils.ParameterToMultiMap("", "orderBy", orderBy)) { foreach (var value in kvp.Value) { requestOptions.QueryParameters.Add(kvp.Key, value); } } } if (sortDirection != null) { foreach (var kvp in Xero.NetStandard.OAuth2.Client.ClientUtils.ParameterToMultiMap("", "sortDirection", sortDirection)) { foreach (var value in kvp.Value) { requestOptions.QueryParameters.Add(kvp.Key, value); } } } if (filterBy != null) { foreach (var kvp in Xero.NetStandard.OAuth2.Client.ClientUtils.ParameterToMultiMap("", "filterBy", filterBy)) { foreach (var value in kvp.Value) { requestOptions.QueryParameters.Add(kvp.Key, value); } } } if (xeroTenantId != null) { requestOptions.HeaderParameters.Add("xero-tenant-id", Xero.NetStandard.OAuth2.Client.ClientUtils.ParameterToString(xeroTenantId)); // header parameter } // authentication (OAuth2) required // oauth required if (!String.IsNullOrEmpty(accessToken)) { requestOptions.HeaderParameters.Add("Authorization", "Bearer " + accessToken); } // make the HTTP request var response = await this.AsynchronousClient.GetAsync <Assets>("/Assets", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("GetAssets", response); if (exception != null) { throw exception; } } return(response); }
/// <summary> /// searches fixed asset By passing in the appropriate options, you can search for available fixed asset in the system /// </summary> /// <exception cref="Xero.NetStandard.OAuth2.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="xeroTenantId">Xero identifier for Tenant</param> /// <param name="status">Required when retrieving a collection of assets. See Asset Status Codes</param> /// <param name="page">Results are paged. This specifies which page of the results to return. The default page is 1. (optional)</param> /// <param name="pageSize">The number of records returned per page. By default the number of records returned is 10. (optional)</param> /// <param name="orderBy">Requests can be ordered by AssetType, AssetName, AssetNumber, PurchaseDate and PurchasePrice. If the asset status is DISPOSED it also allows DisposalDate and DisposalPrice. (optional)</param> /// <param name="sortDirection">ASC or DESC (optional)</param> /// <param name="filterBy">A string that can be used to filter the list to only return assets containing the text. Checks it against the AssetName, AssetNumber, Description and AssetTypeName fields. (optional)</param> /// <returns>Task of Assets</returns> public async System.Threading.Tasks.Task <Assets> GetAssetsAsync(string accessToken, string xeroTenantId, AssetStatusQueryParam status, int?page = null, int?pageSize = null, string orderBy = null, string sortDirection = null, string filterBy = null) { Xero.NetStandard.OAuth2.Client.ApiResponse <Assets> localVarResponse = await GetAssetsAsyncWithHttpInfo(accessToken, xeroTenantId, status, page, pageSize, orderBy, sortDirection, filterBy); return(localVarResponse.Data); }