### Business API POST Request Example Source: https://dev.lava.ru/business-code-examples This example demonstrates how to make a POST request to the Lava.ru Business API, including generating a signature for authentication. ```APIDOC ## POST /business/ ### Description This endpoint is used to interact with the Lava.ru Business API. It requires a POST request with specific data and a generated signature for authentication. ### Method POST ### Endpoint https://api.lava.ru/business/ ### Parameters #### Query Parameters None #### Request Body - **data** (json) - Required - The payload for the API request, typically containing parameters for a query. ### Request Example ```php 'https://api.lava.ru/business/', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 5, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', C CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => array( 'Accept: application/json', 'Content-Type: application/json', 'Signature: ' . $signature ), )); $response = curl_exec($curl); curl_close($curl); // Process the $response ?> ``` ### Response #### Success Response (200) - **response** (json) - The API response payload. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Generate Signature using HMAC-SHA256 (Node.js) Source: https://dev.lava.ru/api-invoice-sign This Node.js example shows how to create a signature using HMAC-SHA256. It utilizes the built-in `crypto` module to sign the JSON string with the secret key, adhering to the recommended method. ```javascript const crypto = require('crypto'); function generateSignature(data, secretKey) { // For the recommended method, ensure the JSON string is generated without extra escaping // and in the correct order as specified in the request. const jsonString = JSON.stringify(data); const signature = crypto.createHmac('sha256', secretKey).update(jsonString).digest('hex'); return signature; } // Example usage: const data = { "comment":"test", "customFields":"test", "expire":300, "failUrl":"https://lava.ru", "hookUrl ":"https://lava.ru", "includeService":["card","sbp","qiwi"], "orderId":"6368d95a9f286", "shopId":"uuid", "successUrl":"https://lava.ru", "sum":1 }; const secretKey = 'a1a2a3'; const signature = generateSignature(data, secretKey); console.log(signature); ``` -------------------------------- ### Generate Signature and Request for Lava.ru Business API (PHP) Source: https://dev.lava.ru/business-code-examples This PHP code demonstrates how to create a JSON payload, generate an HMAC-SHA256 signature using a secret key, and send a POST request to the Lava.ru business API endpoint using cURL. It includes setting request headers like Content-Type and Signature. The response from the API is captured and then the cURL session is closed. ```php $data = [ //params for query ]; $secretKey = ''; $data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); $signature = hash_hmac('sha256', $data, $secretKey); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.lava.ru/business/', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 5, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => array( 'Accept: application/json', 'Content-Type: application/json', 'Signature: ' . $signature ), )); $response = curl_exec($curl); curl_close($curl); // Process $response here ``` -------------------------------- ### Business Cabinet - General Information Source: https://dev.lava.ru/info This section covers general requirements for interacting with the Business Cabinet API, including mandatory headers and the format for sending request data. ```APIDOC ## General Information ### Description This section outlines the general requirements for all API requests to the Business Cabinet. It is crucial to include the specified `Accept` and `Content-Type` headers for all requests. Additionally, all request data must be sent within the `data-raw` field. ### Headers - **Accept**: `application/json` (Required) - **Content-Type**: `application/json` (Required) ### Request Body Structure All request payloads must be enclosed within a `data-raw` field. ```json { "data-raw": { ...your request data... } } ``` ### Example Request (Conceptual) ```json { "data-raw": { "action": "getUserInfo", "parameters": { "userId": "12345" } } } ``` ### Example Response (Conceptual) ```json { "status": "success", "data": { "userInfo": { "name": "John Doe", "email": "john.doe@example.com" } } } ``` ``` -------------------------------- ### Generate Signature using HMAC-SHA256 (C#) Source: https://dev.lava.ru/api-invoice-sign This C# code snippet demonstrates generating a signature with HMAC-SHA256. It uses the `HMACSHA256` class from the `System.Security.Cryptography` namespace to sign the JSON string using the provided secret key. This implementation follows the recommended signature generation process. ```csharp using System; using System.Security.Cryptography; using System.Text; using Newtonsoft.Json; public class SignatureGenerator { public static string GenerateSignature(object data, string secretKey) { // For the recommended method, ensure the JSON string is generated without extra escaping // and in the correct order as specified in the request. string jsonString = JsonConvert.SerializeObject(data); using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey))) { byte[] hashBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(jsonString)); return BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); } } // Example usage: public static void Main(string[] args) { var data = new { comment = "test", customFields = "test", expire = 300, failUrl = "https://lava.ru", hookUrl = "https://lava.ru", includeService = new [] { "card", "sbp", "qiwi" }, orderId = "6368d95a9f286", shopId = "uuid", successUrl = "https://lava.ru", sum = 1 }; string secretKey = "a1a2a3"; string signature = GenerateSignature(data, secretKey); Console.WriteLine(signature); } } ``` -------------------------------- ### Generate Signature using HMAC-SHA256 (Python) Source: https://dev.lava.ru/api-invoice-sign This Python code snippet illustrates generating a signature with HMAC-SHA256. It uses the `hmac` and `hashlib` modules to sign the JSON string with a provided secret key. This method follows the recommended approach for signature generation. ```python import hmac import hashlib import json def generate_signature(data, secret_key): # Ensure data is a JSON string, sorted and without extra escaping for the recommended method json_string = json.dumps(data, separators=(',', ':')) signature = hmac.new(secret_key.encode('utf-8'), json_string.encode('utf-8'), hashlib.sha256).hexdigest() return signature # Example usage: data = {"comment":"test", "customFields":"test", "expire":300, "failUrl":"https://lava.ru", "hookUrl ":"https://lava.ru", "includeService":["card","sbp","qiwi"], "orderId":"6368d95a9f286", "shopId":"uuid", "successUrl":"https://lava.ru", "sum":1} secret_key = "a1a2a3" signature = generate_signature(data, secret_key) print(signature) ``` -------------------------------- ### Generate Signature using HMAC-SHA256 (PHP) Source: https://dev.lava.ru/api-invoice-sign This PHP code snippet demonstrates how to generate a signature using the HMAC-SHA256 algorithm. It takes a JSON-encoded data string and a secret key as input. This method aligns with the recommended signature generation approach. ```php $secretKey = “a1a2a3”; $signature = hash_hmac('sha256', json_encode($data), $secretKey) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.