/// <summary>
        /// Retrieve ledger entries Retrieves a group of ledger entries from the account based on a query object.  If no parameters are specified, the API call will fail with a bad request error.  Always specify some parameters to limit the scope of the ledgers returned to ones you are truly interested in.  You will need to make multiple API calls in order to retrieve the entire result set since this API performs result set pagination.
        /// </summary>
        /// <exception cref="com.ultracart.admin.v2.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="ledgerQuery">Ledger query</param>
        /// <param name="limit">The maximum number of records to return on this one API call. (Maximum 200) (optional, default to 100)</param>
        /// <param name="offset">Pagination of the record set.  Offset is a zero based index. (optional, default to 0)</param>
        /// <param name="expand">The object expansion to perform on the result.  Only option is link. (optional)</param>
        /// <returns>Task of AffiliateLedgersResponse</returns>
        public async System.Threading.Tasks.Task <AffiliateLedgersResponse> GetLedgersByQueryAsync(AffiliateLedgerQuery ledgerQuery, int?limit = null, int?offset = null, string expand = null)
        {
            ApiResponse <AffiliateLedgersResponse> localVarResponse = await GetLedgersByQueryAsyncWithHttpInfo(ledgerQuery, limit, offset, expand);

            return(localVarResponse.Data);
        }
        /// <summary>
        /// Retrieve ledger entries Retrieves a group of ledger entries from the account based on a query object.  If no parameters are specified, the API call will fail with a bad request error.  Always specify some parameters to limit the scope of the ledgers returned to ones you are truly interested in.  You will need to make multiple API calls in order to retrieve the entire result set since this API performs result set pagination.
        /// </summary>
        /// <exception cref="com.ultracart.admin.v2.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="ledgerQuery">Ledger query</param>
        /// <param name="limit">The maximum number of records to return on this one API call. (Maximum 200) (optional, default to 100)</param>
        /// <param name="offset">Pagination of the record set.  Offset is a zero based index. (optional, default to 0)</param>
        /// <param name="expand">The object expansion to perform on the result.  Only option is link. (optional)</param>
        /// <returns>Task of ApiResponse (AffiliateLedgersResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <AffiliateLedgersResponse> > GetLedgersByQueryAsyncWithHttpInfo(AffiliateLedgerQuery ledgerQuery, int?limit = null, int?offset = null, string expand = null)
        {
            // verify the required parameter 'ledgerQuery' is set
            if (ledgerQuery == null)
            {
                throw new ApiException(400, "Missing required parameter 'ledgerQuery' when calling AffiliateApi->GetLedgersByQuery");
            }

            var    localVarPath         = "/affiliate/ledgers/query";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (limit != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("", "_limit", limit));                // query parameter
            }
            if (offset != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("", "_offset", offset));                 // query parameter
            }
            if (expand != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("", "_expand", expand));                 // query parameter
            }
            if (ledgerQuery != null && ledgerQuery.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(ledgerQuery); // http body (model) parameter
            }
            else
            {
                localVarPostBody = ledgerQuery; // byte array
            }

            // authentication (ultraCartOauth) required
            // oauth required
            if (!String.IsNullOrEmpty(this.Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + this.Configuration.AccessToken;
            }
            // authentication (ultraCartSimpleApiKey) required
            if (!String.IsNullOrEmpty(this.Configuration.GetApiKeyWithPrefix("x-ultracart-simple-key")))
            {
                localVarHeaderParams["x-ultracart-simple-key"] = this.Configuration.GetApiKeyWithPrefix("x-ultracart-simple-key");
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("GetLedgersByQuery", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <AffiliateLedgersResponse>(localVarStatusCode,
                                                              localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                              (AffiliateLedgersResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(AffiliateLedgersResponse))));
        }
        /// <summary>
        /// Retrieve ledger entries Retrieves a group of ledger entries from the account based on a query object.  If no parameters are specified, the API call will fail with a bad request error.  Always specify some parameters to limit the scope of the ledgers returned to ones you are truly interested in.  You will need to make multiple API calls in order to retrieve the entire result set since this API performs result set pagination.
        /// </summary>
        /// <exception cref="com.ultracart.admin.v2.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="ledgerQuery">Ledger query</param>
        /// <param name="limit">The maximum number of records to return on this one API call. (Maximum 200) (optional, default to 100)</param>
        /// <param name="offset">Pagination of the record set.  Offset is a zero based index. (optional, default to 0)</param>
        /// <param name="expand">The object expansion to perform on the result.  Only option is link. (optional)</param>
        /// <returns>AffiliateLedgersResponse</returns>
        public AffiliateLedgersResponse GetLedgersByQuery(AffiliateLedgerQuery ledgerQuery, int?limit = null, int?offset = null, string expand = null)
        {
            ApiResponse <AffiliateLedgersResponse> localVarResponse = GetLedgersByQueryWithHttpInfo(ledgerQuery, limit, offset, expand);

            return(localVarResponse.Data);
        }