api-client-dotnet/README.md

75 lines
2.0 KiB
Markdown
Raw Permalink Normal View History

[![AppVeyor](https://img.shields.io/appveyor/build/gwinn/api-client-dotnet?logo=appveyor&logoColor=white)](https://ci.appveyor.com/project/gwinn/api-client-dotnet)
[![NuGet](https://img.shields.io/nuget/v/Retailcrm.SDK.svg?logo=nuget&logoColor=white)](https://www.nuget.org/packages/Retailcrm.SDK/)
2020-02-20 00:12:18 +03:00
2014-11-03 13:50:28 +03:00
# RetailCRM API C# client
This is C# RetailCRM API client. This library allows to use all available API versions.
## Install
2015-07-23 13:37:17 +03:00
``` bash
PM> Install-Package Retailcrm.SDK
2015-07-23 13:37:17 +03:00
```
## Usage
2014-11-03 13:50:28 +03:00
### Get order
2014-11-03 13:50:28 +03:00
2014-11-03 13:52:08 +03:00
``` csharp
using System.Diagnostics;
using Retailcrm;
using Retailcrm.Versions.V5;
2014-11-03 13:50:28 +03:00
...
Client api = new Client("https://demo.retailcrm.pro", "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH");
Response response = api.OrdersGet("12345", "externalId");
2014-11-03 13:50:28 +03:00
2019-07-27 22:18:09 +03:00
if (response.IsSuccessful()) {
Debug.WriteLine(response.GetRawResponse());
2015-02-02 14:46:14 +03:00
} else {
Debug.WriteLine($"Ошибка: [Статус HTTP-ответа {response.GetStatusCode().ToString()}]");
2015-02-02 14:46:14 +03:00
}
```
### Create order
2014-11-03 13:50:28 +03:00
2014-11-03 13:52:08 +03:00
``` csharp
using System.Diagnostics;
using Retailcrm;
using Retailcrm.Versions.V4;
2015-02-02 14:39:46 +03:00
...
2015-02-02 14:36:40 +03:00
Client api = new Client("https://demo.retailcrm.pro", "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH");
Response response = api.OrdersCreate(new Dictionary<string, object>
2015-02-02 14:36:40 +03:00
{
{"externalId", "12345"},
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
{"lastName", "Doe"},
{"firstName", "John"},
{"email", "john@example.com"},
{"phone", "+79999999999"},
{"items", new List<object> {
new Dictionary<string, object> {
{"initialPrice", 100},
{"quantity", 1},
{"productId", 55},
{"productName", "example"}
},
new Dictionary<string, object> {
{"initialPrice", 200},
{"quantity", 2},
{"productId", 14},
{"productName", "example too"}
}
}}
});
2015-02-02 14:36:40 +03:00
2019-07-27 22:18:09 +03:00
if (response.IsSuccessful()) {
Debug.WriteLine(response.GetResponse()["externalId"].ToString());
2015-02-02 14:36:40 +03:00
} else {
Debug.WriteLine($"Error: [HTTP status code {response.GetStatusCode().ToString()}]");
2014-11-03 13:50:28 +03:00
}
2015-02-02 14:39:46 +03:00
```