2014-11-03 13:50:28 +03:00
|
|
|
RetailCRM REST API client for .NET
|
|
|
|
==================================
|
|
|
|
|
|
|
|
Java Client for [RetailCRM REST API](http://www.retailcrm.ru/docs/rest-api/index.html).
|
|
|
|
version: 3.0.0
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
------------
|
|
|
|
* [Newtonsoft.Json](http://james.newtonking.com/json)
|
|
|
|
|
|
|
|
Usage
|
|
|
|
------------
|
|
|
|
|
|
|
|
### Create API client class
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
api = new ApiClient("https://demo.retailcrm.ru", "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH");
|
|
|
|
}
|
|
|
|
catch (WebException e)
|
|
|
|
{
|
|
|
|
System.Console.WriteLine(e.ToString());
|
|
|
|
}
|
2014-11-03 13:50:28 +03:00
|
|
|
```
|
|
|
|
Constructor arguments are:
|
|
|
|
|
2014-11-03 14:24:10 +03:00
|
|
|
1. Your RetailCRM acount URL-address
|
2014-11-03 13:50:28 +03:00
|
|
|
2. Your site API Token
|
|
|
|
|
|
|
|
### Example: get order types list
|
|
|
|
|
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"},
|
|
|
|
{"createdAt", DateTime.Now.ToString("Y-m-d H:i:s")},
|
|
|
|
{"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>(){
|
|
|
|
{"text", "exampleing"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiResponse response = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
response = api.ordersEdit(order);
|
|
|
|
}
|
|
|
|
catch (WebException e)
|
|
|
|
{
|
|
|
|
System.Console.WriteLine(e.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.isSuccessful() && 201 == response["statusCosde"]) {
|
|
|
|
System.Console.WriteLine("Заказ успешно создан. ID заказа в retailCRM = " + response["id"]);
|
|
|
|
} else {
|
2015-02-02 14:39:46 +03:00
|
|
|
System.Console.WriteLine(
|
|
|
|
"Ошибка создания заказа: [Статус HTTP-ответа " + response["statusCosde"] + "] " + response["errorMsg"]
|
|
|
|
);
|
2014-11-03 13:50:28 +03:00
|
|
|
}
|
|
|
|
|
2015-02-02 14:39:46 +03:00
|
|
|
```
|