Skip to content
CheckcraftDownload
Practical workflow

REST API in 1C: HTTP services, OData and calling external APIs

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →

1C has two ways to expose data over REST and one way to consume someone else's API. Your own HTTP services give full control over URLs and responses. The standard OData interface is a ready automatic REST with no code. External APIs are called with HTTPConnection. Below is how they differ and how to test each.

Checkcraft ·

Get help with your first test →

Three ways to work with REST in 1C

An HTTP service is a configuration object where you define URLs, methods and the response format yourself. OData is the platform's automatic REST interface: enabled when publishing, it serves catalogs and documents without code. HTTPConnection is the built-in object for requests from 1C to any external REST API.

What to choose for an integration

If an external system needs to read data as is and fast, start with OData. If you need your own logic, input validation, a stable contract for a partner or JSON in your own format, write an HTTP service. If 1C itself pulls data from a service, marketplace or bank, use HTTPConnection.

API call diagram: method and URL, headers, body, status and response body, logs and database

How to test a 1C REST API

Test each address from outside, the same way the partner will call it: curl or an API client with the exchange account. Check not only status 200 but the response fields, the answer to invalid data and to missing rights. Run that set of requests after every configuration update.

HTTP service, OData and HTTPConnection side by side

HTTP serviceODataHTTPConnection
Direction1C serves data1C serves data1C pulls data
CodeHandlers in 1C languageNoneRequests in 1C language
Address/hs/root_url/.../odata/standard.odata/...Any external
FormatAny, usually JSONJSON or XMLAny
Response controlFullOnly object set and rightsFull
Layers of an API call check: status, headers, body, calculations, logs, database

Calling the 1C REST API with curl

# свой HTTP-сервис: корневой URL api, шаблон /orders/{id}
curl -u "Обмен:пароль" "http://erp.example.local/trade/hs/api/orders/5001"

# автоматический REST через OData: первые 5 контрагентов в JSON
curl -u "Обмен:пароль" "http://erp.example.local/trade/odata/standard.odata/Catalog_Контрагенты?\$format=json&\$top=5"

The first request goes to your HTTP service, the second to the automatic REST interface. Both need the database published on a web server and an account with rights.

Calling an external REST API from 1C

Соединение = Новый HTTPСоединение("api.example.com", 443, , , , 30,
    Новый ЗащищенноеСоединениеOpenSSL);
Запрос = Новый HTTPЗапрос("/v1/orders?status=new");
Запрос.Заголовки.Вставить("Authorization", "Bearer " + Токен);
Запрос.Заголовки.Вставить("Accept", "application/json");

Ответ = Соединение.Получить(Запрос);
Если Ответ.КодСостояния <> 200 Тогда
    ВызватьИсключение "API вернул " + Ответ.КодСостояния + ": " + Лев(Ответ.ПолучитьТелоКакСтроку(), 300);
КонецЕсли;

Чтение = Новый ЧтениеJSON;
Чтение.УстановитьСтроку(Ответ.ПолучитьТелоКакСтроку("UTF-8"));
Заказы = ПрочитатьJSON(Чтение, Истина);

Checking the status code before parsing JSON avoids cryptic read errors when the service returned an error page. See 1C HTTP request error.

Common errors

  • 404 on /hs/. HTTP services are not published or the root URL is wrong.
  • 401. No 1C account was sent or it lacks rights.
  • OData returns an empty list. The standard interface set is not configured.
  • JSON read error from an external API. An HTML page or a BOM arrived.

More on 1C

Section overview and all guides: 1C integration via API: options, architecture and examples.

Frequently asked questions

How do I build a REST API in 1C?

Create an HTTP service and publish it, or enable the standard OData interface, which works as automatic REST with no code.

What is the automatic REST service in 1C?

The standard OData interface at /odata/standard.odata/ after publishing and configuring the object set.

How do I call an external REST API from 1C?

With HTTPConnection and HTTPRequest: set the address, headers and auth, send, check the status and read the JSON.

Next step

Repeat this on your own API

Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.

Download FreeDownload and first run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

Start with the linked example and compare its result with your own test requirement.

Ask a person

Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

No account required. We will reply by email. This is a support request, not a newsletter subscription.