{
  "name": "Токен партнёра запрашивается один раз и используется во всех вызовах",
  "description": "Ошибка аргумента обнаруживается до запроса токена. Токен запрашивается при первом вызове со скоупами в заданном порядке и переиспользуется. Клиент без выбранного мерчанта не отправляет Loyal-Merchant — сервер отвечает 400 merchant_required (класс bad_request).",
  "client": {
    "api": "management",
    "credential": {
      "clientCredentials": {
        "clientId": "lc_test_4b9ac4f5d6cc6783a2044a5a",
        "clientSecret": "lcs_test__A75hCwHKWYA61AD1WKWOkjtKvU2hRnSKCx_YVFfVos",
        "scopes": ["programs", "merchants"]
      }
    },
    "baseUrl": "https://api.example.com"
  },
  "calls": [
    {"operation": "getMerchant", "args": {"merchant": ""}, "expect": {"error": {"class": "configuration"}}},
    {
      "operation": "getMerchant",
      "args": {"merchant": "01929c1e-0020-7020-8020-000000000020"},
      "expect": {
        "result": {
          "id": "01929c1e-0020-7020-8020-000000000020",
          "name": "Кофейня «Зерно»",
          "status": "active",
          "timezone": "Europe/Moscow",
          "country_code": "RU",
          "external_id": "crm-1",
          "created_at": "2026-10-01T09:00:00.000000Z"
        }
      }
    },
    {
      "operation": "listEventTypes",
      "args": {},
      "expect": {
        "result": {"data": [{"type": "member.enrolled", "version": 1}, {"type": "receipt.confirmed", "version": 1}]}
      }
    },
    {
      "operation": "listPrograms",
      "args": {},
      "expect": {
        "error": {
          "class": "bad_request",
          "status": 400,
          "code": "merchant_required",
          "requestId": "01929c20-0004-7000-8000-000000000004"
        }
      }
    }
  ],
  "exchanges": [
    {
      "request": {
        "method": "POST",
        "url": "https://api.example.com/api/management/v1/oauth/token",
        "headers": {
          "authorization": "Basic bGNfdGVzdF80YjlhYzRmNWQ2Y2M2NzgzYTIwNDRhNWE6bGNzX3Rlc3RfX0E3NWhDd0hLV1lBNjFBRDFXS1dPa2p0S3ZVMmhSblNLQ3hfWVZGZlZvcw==",
          "accept": "application/json",
          "content-type": "application/x-www-form-urlencoded",
          "idempotency-key": null,
          "loyal-merchant": null
        },
        "form": {"grant_type": "client_credentials", "scope": "programs merchants"}
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json",
          "X-Request-Id": "01929c20-0001-7000-8000-000000000001",
          "Loyal-Environment": "sandbox",
          "Cache-Control": "no-store",
          "Pragma": "no-cache"
        },
        "json": {
          "access_token": "lat_test_8NfzE9KomDFUk3lfJjBaLz0-9r7ns5Uo2tYUpmVlUcE",
          "token_type": "Bearer",
          "expires_in": 3600,
          "scope": "programs merchants"
        }
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "https://api.example.com/api/management/v1/merchants/01929c1e-0020-7020-8020-000000000020",
        "headers": {
          "authorization": "Bearer lat_test_8NfzE9KomDFUk3lfJjBaLz0-9r7ns5Uo2tYUpmVlUcE",
          "accept": "application/json",
          "content-type": null,
          "idempotency-key": null,
          "loyal-merchant": null
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json",
          "X-Request-Id": "01929c20-0002-7000-8000-000000000002",
          "Loyal-Environment": "sandbox"
        },
        "json": {
          "id": "01929c1e-0020-7020-8020-000000000020",
          "name": "Кофейня «Зерно»",
          "status": "active",
          "timezone": "Europe/Moscow",
          "country_code": "RU",
          "external_id": "crm-1",
          "created_at": "2026-10-01T09:00:00.000000Z"
        }
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "https://api.example.com/api/management/v1/event-types",
        "headers": {
          "authorization": "Bearer lat_test_8NfzE9KomDFUk3lfJjBaLz0-9r7ns5Uo2tYUpmVlUcE",
          "accept": "application/json",
          "content-type": null,
          "idempotency-key": null,
          "loyal-merchant": null
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json",
          "X-Request-Id": "01929c20-0003-7000-8000-000000000003",
          "Loyal-Environment": "sandbox"
        },
        "json": {"data": [{"type": "member.enrolled", "version": 1}, {"type": "receipt.confirmed", "version": 1}]}
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "https://api.example.com/api/management/v1/programs",
        "headers": {
          "authorization": "Bearer lat_test_8NfzE9KomDFUk3lfJjBaLz0-9r7ns5Uo2tYUpmVlUcE",
          "accept": "application/json",
          "content-type": null,
          "idempotency-key": null,
          "loyal-merchant": null
        }
      },
      "response": {
        "status": 400,
        "headers": {
          "Content-Type": "application/problem+json",
          "X-Request-Id": "01929c20-0004-7000-8000-000000000004",
          "Loyal-Environment": "sandbox"
        },
        "json": {
          "type": "urn:loyal:problem:merchant_required",
          "title": "This operation works on a merchant: pick it with the Loyal-Merchant header.",
          "status": 400,
          "code": "merchant_required",
          "request_id": "01929c20-0004-7000-8000-000000000004"
        }
      }
    }
  ],
  "sleeps": []
}
