pschelpdesk/FastBill/Api/Customers.cs
2024-11-19 20:16:45 +01:00

28 lines
906 B
C#

using FastBill.Api.Response;
using FastBill.Models;
using RestSharp;
using RestSharp.Authenticators;
using Customer = FastBill.Models.Customer;
namespace FastBill.Api;
public class Customers
{
async public Task<List<Customer>> SearchCustomer(Settings settings, string term)
{
var customers = new List<Customer>();
var client = new RestClient("https://my.fastbill.com/");
var request = new RestRequest("api/1.0/api.php"){
Authenticator = new HttpBasicAuthenticator(settings.EMail, settings.ApiKey)
};
request.AddJsonBody(new { SERVICE = "customer.get", FILTER = new { TERM = term } });
var response = await client.ExecuteAsync<SearchCustomer>(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return response.Data.Response.Customers;
}
return customers;
}
}