2016-03-14 23:18:43 +03:00
|
|
|
.NET client for retailCRM API
|
2015-02-02 14:46:14 +03:00
|
|
|
=============================
|
2014-11-03 13:50:28 +03:00
|
|
|
|
2016-03-14 23:18:43 +03:00
|
|
|
.NET client for [RetailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion3).
|
2014-11-03 13:50:28 +03:00
|
|
|
|
2016-03-14 23:17:48 +03:00
|
|
|
Requirements
|
2015-02-02 14:46:14 +03:00
|
|
|
-----------------------
|
2014-11-03 13:50:28 +03:00
|
|
|
* [Newtonsoft.Json](http://james.newtonking.com/json)
|
|
|
|
|
2016-03-14 23:17:48 +03:00
|
|
|
Install with NuGet
|
2015-07-23 13:37:17 +03:00
|
|
|
---------------------
|
|
|
|
|
2016-03-14 23:17:48 +03:00
|
|
|
Install [NuGet](http://docs.nuget.org/consume/installing-nuget).
|
2015-07-23 13:37:17 +03:00
|
|
|
|
2016-03-14 23:17:48 +03:00
|
|
|
Run this command into [Package Manager Console](http://docs.nuget.org/docs/start-here/using-the-package-manager-console)
|
2015-07-23 13:37:17 +03:00
|
|
|
``` bash
|
|
|
|
PM> Install-Package RetailCRM.ApiClient
|
|
|
|
```
|
|
|
|
|
2016-03-14 23:17:48 +03:00
|
|
|
Usage
|
2015-02-02 14:46:14 +03:00
|
|
|
---------------------
|
2014-11-03 13:50:28 +03:00
|
|
|
|
2016-03-14 23:17:48 +03:00
|
|
|
### Get order
|
2014-11-03 13:50:28 +03:00
|
|
|
|
2014-11-03 13:52:08 +03:00
|
|
|
``` csharp
|
2014-11-03 13:50:28 +03:00
|
|
|
using RetailCrm;
|
2015-02-02 14:39:46 +03:00
|
|
|
using RetailCrm.Response;
|
2014-11-03 13:50:28 +03:00
|
|
|
...
|
2015-02-02 14:39:46 +03:00
|
|
|
ApiClient api;
|
|
|
|
try
|
|
|
|
{
|
2015-02-02 14:46:14 +03:00
|
|
|
api = new ApiClient(
|
2016-03-14 23:17:48 +03:00
|
|
|
"https://demo.retailcrm.pro",
|
2015-02-02 14:46:14 +03:00
|
|
|
"T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH"
|
|
|
|
);
|
2015-02-02 14:39:46 +03:00
|
|
|
}
|
|
|
|
catch (WebException e)
|
|
|
|
{
|
|
|
|
System.Console.WriteLine(e.ToString());
|
|
|
|
}
|
2014-11-03 13:50:28 +03:00
|
|
|
|
2015-02-02 14:46:14 +03:00
|
|
|
ApiResponse response = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
response = api.ordersGet("M-2342");
|
|
|
|
}
|
|
|
|
catch (WebException e)
|
|
|
|
{
|
|
|
|
System.Console.WriteLine(e.ToString());
|
|
|
|
}
|
2014-11-03 13:50:28 +03:00
|
|
|
|
2015-02-02 14:46:14 +03:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
System.Console.WriteLine(response["totalSumm"]);
|
|
|
|
} else {
|
|
|
|
System.Console.WriteLine(
|
2016-03-14 23:17:48 +03:00
|
|
|
"Error: [HTTP-code " +
|
2016-11-28 20:58:08 +03:00
|
|
|
response["statusCode"] + "] " +
|
2015-02-02 14:46:14 +03:00
|
|
|
response["errorMsg"]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
2016-03-14 23:17:48 +03:00
|
|
|
### Create order
|
2014-11-03 13:50:28 +03:00
|
|
|
|
2014-11-03 13:52:08 +03:00
|
|
|
``` csharp
|
2015-02-02 14:39:46 +03:00
|
|
|
using RetailCrm;
|
|
|
|
using RetailCrm.Response;
|
|
|
|
...
|
2015-02-02 14:36:40 +03:00
|
|
|
ApiClient api;
|
2014-11-03 13:50:28 +03:00
|
|
|
string url, key;
|
2015-02-02 14:36:40 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
api = new ApiClient(url, key);
|
|
|
|
}
|
|
|
|
catch (WebException e)
|
|
|
|
{
|
|
|
|
System.Console.WriteLine(e.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary<string, object> tmpOrder = new Dictionary<string, object>(){
|
|
|
|
{"number", "example"},
|
|
|
|
{"externalId", "example"},
|
2016-02-04 12:37:40 +03:00
|
|
|
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
2015-02-02 14:36:40 +03:00
|
|
|
{"discount", 50},
|
|
|
|
{"phone", "89263832233"},
|
2015-02-02 14:39:46 +03:00
|
|
|
{"email", "example@gmail.com"},
|
2015-02-02 14:36:40 +03:00
|
|
|
{"customerComment", "example"},
|
|
|
|
{"customFields", new Dictionary<string, object>(){
|
|
|
|
{"reciever_phone", "example"},
|
|
|
|
{"reciever_name", "example"},
|
|
|
|
{"ext_number", "example"}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{"contragentType", "individual"},
|
|
|
|
{"orderType", "eshop-individual"},
|
|
|
|
{"orderMethod", "app"},
|
|
|
|
{"customerId", "555"},
|
|
|
|
{"managerId", 8},
|
|
|
|
{"items", new Dictionary<string, object>(){
|
|
|
|
{"0", new Dictionary<string, object>(){
|
|
|
|
{"initialPrice", 100},
|
|
|
|
{"quantity", 1},
|
|
|
|
{"productId", 55},
|
|
|
|
{"productName", "example"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{"delivery", new Dictionary<string, object>(){
|
|
|
|
{"code", "courier"},
|
|
|
|
{"date", DateTime.Now.ToString("Y-m-d")},
|
|
|
|
{"address", new Dictionary<string, object>(){
|
2016-03-14 23:17:48 +03:00
|
|
|
{"text", "example"}
|
2015-02-02 14:36:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiResponse response = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
response = api.ordersEdit(order);
|
|
|
|
}
|
|
|
|
catch (WebException e)
|
|
|
|
{
|
|
|
|
System.Console.WriteLine(e.ToString());
|
|
|
|
}
|
|
|
|
|
2016-11-28 20:58:08 +03:00
|
|
|
if (response.isSuccessful() && 201 == response["statusCode"]) {
|
2015-02-02 14:46:14 +03:00
|
|
|
System.Console.WriteLine(
|
2016-03-14 23:17:48 +03:00
|
|
|
"Order created. Order ID is " + response["id"]
|
2015-02-02 14:46:14 +03:00
|
|
|
);
|
2015-02-02 14:36:40 +03:00
|
|
|
} else {
|
2015-02-02 14:39:46 +03:00
|
|
|
System.Console.WriteLine(
|
2016-03-14 23:17:48 +03:00
|
|
|
"Error: [HTTP-code " +
|
|
|
|
response["statusCode"] + "] " +
|
2015-02-02 14:46:14 +03:00
|
|
|
response["errorMsg"]
|
2015-02-02 14:39:46 +03:00
|
|
|
);
|
2014-11-03 13:50:28 +03:00
|
|
|
}
|
|
|
|
|
2015-02-02 14:39:46 +03:00
|
|
|
```
|