ErplyAPI.NET is a .NET library for calling Erply REST API with Auth in .NET applications. It was built with simplicity in mind and using it should need as little code as possible.
Because this library was built according to my needs, not all requests and models are implemented. And those, which are implemented may not be perfect, because they were generated by my code generator and I haven't tested them all. Also model and requests comments are generated from Erply's docs and may also not be perfect.
using ErplyAPI;
using ErplyAPI.Products;
/* Erply is our main class, which handles all our requests.
* When creating this class, VerifyUser() will be called.
* All next request will use sessionKey gotten from this or
* make a new VerifyUser() request if key is about to expire.
*/
// Authenticate yourself
var erply = new Erply(505789, "", "");
// Config your request
var getProductsSettings = new GetProductsSettings()
{
Type = ProductType.PRODUCT,
Status = ProductStatus.ACTIVE
};
// Get all products with given config
var products = erply.FetchAll<Product>(getProductsSettings);
// Create new product
var newProduct = new Product()
{
Name = "Example product",
Type = ProductType.PRODUCT,
Price = 42.69f
};
// Create config for saving our new product
var saveProductSettings = new SaveProductSettings()
{
Product = newProduct
};
// Save our product into Erply
var productID = erply.SaveProduct(saveProductSettings);
// Let's delete our newly created product
erply.DeleteProduct(new DeleteProductSettings() { ProductID = productID });
// Create list of requests
var calls = new List<ErplyCall>();
for(int i = 0; i < 200; i++)
{
var product = new Product();
product.Name = i.ToString();
product.Price = i;
var call = new SaveProductSettings()
{
Product = product
};
calls.Add(call);
}
/* Infinite amount of calls can be done with this method.
* MakeBulkRequest() takes in a list and makes it into consumable pieces for Erply and
* makes as many bulk requests as needed to make all calls.
* Good thing to keep in mind is that we don't check each response for succes or failure,
* only individual bulk requests error codes are checked.
*/
// Let's save all our product into Erply
erply.MakeBulkRequest(calls);
Model or request I want isn't added
Because I don't have the time to go over all the models and requests, I haven't added them all. If you find that a model or request hasn't been added you can make a feature request by submitting a issue.
If it is timecritical you can make the model yourself and create a pull request.
Current calls and models have been generated by a script and generated code is also included.
Using generated code
Because generated code isn't perfect, adding it to project can take some adjustment, e.g adding [ErplyConverter(typeof(ListConverter))]
attributes, new classes and so on, but should include all available calls and their properties. If you want to add generated code, please check if all properties are present from Erply API docs and add needed attributes to properties. For example you can use Product model.
Rules
- All properties have to be Nullable
- When making save settings model, use base model as much as possible (E.g SaveProductSettings has Product as property and Product has
[ErplyConverter(typeof(ErplyConverter))]
as attribute)