您有一个公司名称或搜索词,需要将公司数据添加到应用中,但不想自行构建查询功能。本指南将介绍如何按名称调用 LiveMint API、如何在 Python 中读取返回的公司资料字段,以及如何处理文档中请求示例与响应示例之间的差异。
API 返回的内容
LiveMint API 的“按名称获取公司数据”端点可根据名称检索公司的详细财务数据。它支持完整名称、简称以及 LiveMint 搜索支持的搜索词。
已发布的响应示例包含公司名称、行业、公司简介、标识符、高管、交易所代码,以及包含财务指标的同行公司列表。这些字段可用于公司资料页面、研究工作流,以及为公司名称补充结构化信息的内部工具。
搜索词不一定是唯一标识符。在将结果关联到内部公司记录之前,请检查返回的公司名称以及应用所需的任何标识符。
在 Zyla API Hub 上开始使用
在 Zyla API Hub 上打开 LiveMint API 页面;如有需要,请创建免费账户,并在可用时选择“订阅”或“开始免费试用”。该页面可用于开始首个 API 的 7 天试用或 50 次请求选项;请查看 API 页面,了解当前的访问选项和定价。
获取 API 密钥,并将其作为 bearer token 放入 Authorization 标头中。Zyla 采用订阅和配额模式,而非按调用付费。请将密钥保存在服务器或其他安全环境中,不要将其嵌入浏览器代码。
按名称请求公司数据
可用端点为按名称获取公司数据。它接受发送到以下地址的 GET 请求:
https://zylalabs.com/api/4204/livemint-api/5100/get-company-data-by-name
必需的查询参数是 name,其值为公司名称或受支持的搜索词字符串。以下已发布的请求会搜索 TCS。运行前,请将 YOUR_API_KEY 替换为您的 Zyla API 密钥。
curl -s -X GET "https://zylalabs.com/api/4204/livemint-api/5100/get-company-data-by-name?name=TCS" \
-H "Authorization: Bearer YOUR_API_KEY"
在 Python 中调用同一端点
此示例使用 Python 标准库,检查 HTTP 或网络错误,并读取已发布响应中显示的公司和资料字段。它还会处理资料缺失的情况,不会假定每个字段都存在。
import json
import os
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
url = "https://zylalabs.com/api/4204/livemint-api/5100/get-company-data-by-name?name=TCS"
api_key = os.environ["ZYLA_API_KEY"]
request = Request(
url,
headers={"Authorization": f"Bearer {api_key}"},
method="GET",
)
try:
with urlopen(request, timeout=30) as response:
data = json.load(response)
except HTTPError as error:
raise SystemExit(f"Request failed with HTTP status {error.code}")
except URLError as error:
raise SystemExit(f"Network request failed: {error.reason}")
except json.JSONDecodeError:
raise SystemExit("The response was not valid JSON")
if not isinstance(data, dict):
raise SystemExit("Expected a JSON object")
profile = data.get("companyProfile")
if not isinstance(profile, dict):
profile = {}
print("Company:", data.get("companyName"))
print("Industry:", data.get("industry"))
print("Description:", profile.get("companyDescription"))
print("Identifier:", profile.get("isInId"))
print("BSE code:", profile.get("exchangeCodeBse"))
print("NSE code:", profile.get("exchangeCodeNse"))
运行脚本前,请将环境变量 ZYLA_API_KEY 设置为您的密钥。此示例会打印字段,而不是假定匹配结果正确:您的应用应验证返回的公司是否为用户所指的公司。
阅读已发布的响应示例
以下是已发布的响应摘录。它显示的是 Zomato,而上文已发布的请求搜索的是 TCS;不要将此摘录视为该请求的预期结果。该摘录也经过了截断,因此并非可直接解析的完整 JSON 文档。
{"companyName":"Zomato","industry":"Computer Services","companyProfile":{"companyDescription":"Zomato Limited operates as an Internet portal, which helps in connecting the users, restaurant partners/ third-party merchants and the delivery partners. The Company also provides a platform to restaurant partners/brands to advertise themselves to the target audience in India and abroad and supplies ingredients to restaurant partners. The Company’s India food ordering and delivery segment consists of an online marketplace platform through which the Company facilitates the listing and online ordering of food items and the delivery of these food items by connecting end users, restaurant partners and independent delivery partners. Its hyperpure supplies (B2B business) segment offers farm-to-fork supplies for restaurants in India. Its quick commerce segment consists of an online marketplace platform (Marketplace), which enables listing of items sold on the Marketplace by the sellers. The Company’s going-out segment is a combination of its dining-out and entertainment ticketing business.","mgIndustry":"Computer Services","isInId":"INE758T01015","officers":{"officer":[{"rank":1,"since":"01/18/2010","firstName":"Deepinder","mI":null,"lastName":"Goyal","age":"41","title":{"startYear":"2021","startMonth":"3","startDay":"24","iD1":"CEO","abbr1":"CEO","iD2":"FDR","abbr2":"Fndr.","Value":"Chief Executive Officer, Founder, Managing Director, Executive Director"}},{"rank":2,"since":"11/09/2020","firstName":"Akshant","mI":null,"lastName":"Goyal","age":null,"title":{"startYear":"2020","startMonth":"11","startDay":"9","iD1":"CFO","abbr1":"CFO","iD2":"","abbr2":"","Value":"Chief Financial Officer"}},{"rank":3,"since":"01/21/2019","firstName":"Sandhya","mI":null,"lastName":"Sethia","age":null,"title":{"startYear":"2022","startMonth":"3","startDay":"","iD1":"CCO","abbr1":"Chief Comp.","iD2":"SEC","abbr2":"Secy.","Value":"Company Secretary and Compliance Officer"}}]},"exchangeCodeBse":"543320","exchangeCodeNse":"ZOMATO","peerCompanyList":[{"tickerId":"S0003105","companyName":"Wipro","priceToBookValueRatio":3.87,"priceToEarningsValueRatio":24.88,"marketCap":276762.16,"price":264.3,"percentChange":-1.53,"netChange":-4.1,"returnOnAverageEquity5YearAverage":17.18,"returnOnAverageEquityTrailing12Month":15.66,"ltDebtPerEquityMostRecentFiscalYear":10.17,"netProfitMargin5YearAverage":14.48,"netProfitMarginPercentTrailing12Month":14.06,"dividendYieldIndicatedAnnualDividend":2.16,"totalSharesO…
对于资料页面,可先使用 companyName、industry 和 companyProfile.companyDescription。示例还将 isInId 和交易所代码放在 companyProfile 中;使用这些字段帮助用户在保存匹配结果前确认公司。
示例中的 officers.officer 数组包含姓名和职务,而 peerCompanyList 包含同行公司名称和指标。部分高管字段的值为 null 或空字符串,因此应将其显示为不可用,而不要假定每条记录都完整。
该摘录未说明同行指标的单位、货币或更新时间戳。在为这些数字标注单位或将其视为当前市场数据之前,请查看 API 页面。同样,应根据新鲜度需求选择应用端缓存时长,而不要假定存在已记录的刷新间隔。
实际用途和 AI 智能体访问
公司研究工具可以接受名称、检索资料,并将简介与返回的标识符和交易所代码一同显示。分析师随后可以确认匹配结果,再将其添加到研究记录中。
内部数据补全工作流可以使用同一查询功能,为用户输入的公司填充审核页面。请将原始搜索词与返回的公司名称分开保存:简称可能需要人工审核,才能将结果关联到现有记录。
对于 AI 智能体,请使用 https://mcp.zylalabs.com/mcp?apikey=YOUR_API_KEY 配置兼容客户端。Zyla 的 MCP 端点可与 Claude Code、Cursor、Windsurf 及其他兼容 MCP 的客户端配合使用。使用客户端提供的工具请求公司查询,并让智能体在使用结果前检查返回的名称。
常见问题
我可以使用公司简称进行搜索吗?
可以。该端点支持完整名称、简称以及 LiveMint 搜索支持的搜索词。如果搜索词可能匹配多家公司,请检查返回的名称和标识符。
调用该端点需要什么?
发送带有所需 name 查询参数的 GET 请求,并添加 Authorization: Bearer YOUR_API_KEY 标头。发出请求前,请在 API 页面订阅或开始可用的试用。
为什么响应示例显示的公司与请求中的不同?
已发布的请求使用 TCS,而已发布的响应摘录显示的是 Zomato。请将该摘录用于了解示例字段,而不要将其视为请求必然返回该公司的说明。
我可以将已发布的响应摘录解析为 JSON 吗?
不可以。该摘录在同行公司数据中途结束。请解析请求返回的完整响应,并在应用中处理缺失值或 null 值。
准备好集成公司名称查询了吗?创建免费的 Zyla 账户,获取 API 密钥,然后开始 LiveMint API 的 7 天试用。请查看页面,了解当前访问选项、定价和配额详情。
官方 API 响应
{"companyName":"Zomato","industry":"Computer Services","companyProfile":{"companyDescription":"Zomato Limited operates as an Internet portal, which helps in connecting the users, restaurant partners/ third-party merchants and the delivery partners. The Company also provides a platform to restaurant partners/brands to advertise themselves to the target audience in India and abroad and supplies ingredients to restaurant partners. The Company’s India food ordering and delivery segment consists of an online marketplace platform through which the Company facilitates the listing and online ordering of food items and the delivery of these food items by connecting end users, restaurant partners and independent delivery partners. Its hyperpure supplies (B2B business) segment offers farm-to-fork supplies for restaurants in India. Its quick commerce segment consists of an online marketplace platform (Marketplace), which enables listing of items sold on the Marketplace by the sellers. The Company’s going-out segment is a combination of its dining-out and entertainment ticketing business.","mgIndustry":"Computer Services","isInId":"INE758T01015","officers":{"officer":[{"rank":1,"since":"01/18/2010","firstName":"Deepinder","mI":null,"lastName":"Goyal","age":"41","title":{"startYear":"2021","startMonth":"3","startDay":"24","iD1":"CEO","abbr1":"CEO","iD2":"FDR","abbr2":"Fndr.","Value":"Chief Executive Officer, Founder, Managing Director, Executive Director"}},{"rank":2,"since":"11/09/2020","firstName":"Akshant","mI":null,"lastName":"Goyal","age":null,"title":{"startYear":"2020","startMonth":"11","startDay":"9","iD1":"CFO","abbr1":"CFO","iD2":"","abbr2":"","Value":"Chief Financial Officer"}},{"rank":3,"since":"01/21/2019","firstName":"Sandhya","mI":null,"lastName":"Sethia","age":null,"title":{"startYear":"2022","startMonth":"3","startDay":"","iD1":"CCO","abbr1":"Chief Comp.","iD2":"SEC","abbr2":"Secy.","Value":"Company Secretary and Compliance Officer"}}]},"exchangeCodeBse":"543320","exchangeCodeNse":"ZOMATO","peerCompanyList":[{"tickerId":"S0003105","companyName":"Wipro","priceToBookValueRatio":3.87,"priceToEarningsValueRatio":24.88,"marketCap":276762.16,"price":264.3,"percentChange":-1.53,"netChange":-4.1,"returnOnAverageEquity5YearAverage":17.18,"returnOnAverageEquityTrailing12Month":15.66,"ltDebtPerEquityMostRecentFiscalYear":10.17,"netProfitMargin5YearAverage":14.48,"netProfitMarginPercentTrailing12Month":14.06,"dividendYieldIndicatedAnnualDividend":2.16,"totalSharesO…
官方 API 响应
{"companyName":"Zomato","industry":"Computer Services","companyProfile":{"companyDescription":"Zomato Limited operates as an Internet portal, which helps in connecting the users, restaurant partners/ third-party merchants and the delivery partners. The Company also provides a platform to restaurant partners/brands to advertise themselves to the target audience in India and abroad and supplies ingredients to restaurant partners. The Company’s India food ordering and delivery segment consists of an online marketplace platform through which the Company facilitates the listing and online ordering of food items and the delivery of these food items by connecting end users, restaurant partners and independent delivery partners. Its hyperpure supplies (B2B business) segment offers farm-to-fork supplies for restaurants in India. Its quick commerce segment consists of an online marketplace platform (Marketplace), which enables listing of items sold on the Marketplace by the sellers. The Company’s going-out segment is a combination of its dining-out and entertainment ticketing business.","mgIndustry":"Computer Services","isInId":"INE758T01015","officers":{"officer":[{"rank":1,"since":"01/18/2010","firstName":"Deepinder","mI":null,"lastName":"Goyal","age":"41","title":{"startYear":"2021","startMonth":"3","startDay":"24","iD1":"CEO","abbr1":"CEO","iD2":"FDR","abbr2":"Fndr.","Value":"Chief Executive Officer, Founder, Managing Director, Executive Director"}},{"rank":2,"since":"11/09/2020","firstName":"Akshant","mI":null,"lastName":"Goyal","age":null,"title":{"startYear":"2020","startMonth":"11","startDay":"9","iD1":"CFO","abbr1":"CFO","iD2":"","abbr2":"","Value":"Chief Financial Officer"}},{"rank":3,"since":"01/21/2019","firstName":"Sandhya","mI":null,"lastName":"Sethia","age":null,"title":{"startYear":"2022","startMonth":"3","startDay":"","iD1":"CCO","abbr1":"Chief Comp.","iD2":"SEC","abbr2":"Secy.","Value":"Company Secretary and Compliance Officer"}}]},"exchangeCodeBse":"543320","exchangeCodeNse":"ZOMATO","peerCompanyList":[{"tickerId":"S0003105","companyName":"Wipro","priceToBookValueRatio":3.87,"priceToEarningsValueRatio":24.88,"marketCap":276762.16,"price":264.3,"percentChange":-1.53,"netChange":-4.1,"returnOnAverageEquity5YearAverage":17.18,"returnOnAverageEquityTrailing12Month":15.66,"ltDebtPerEquityMostRecentFiscalYear":10.17,"netProfitMargin5YearAverage":14.48,"netProfitMarginPercentTrailing12Month":14.06,"dividendYieldIndicatedAnnualDividend":2.16,"totalSharesO…