导入
商家 API
学习如何使用商家 API 检索关于 Square 商家账户的信息。
**商户 API** 用于获取 Square 商家账户的相关信息。假设我们开发一个使用 Square 处理支付的应用程序,商家在创建账户时会提供其相关信息。我们可以使用商户 API 获取商家账户信息,例如公司名称、国家和语言。

代码示例
1https://connect.squareupsandbox.com/v2/merchants
1import fetch from 'node-fetch'; 2 3const headerParameters = { 4 'Authorization': 'Bearer {{ACCESS_TOKEN}}', 5 'Content-Type': 'application/json' 6}; 7 8const url = new URL('https://connect.squareupsandbox.com/v2/merchants'); 9 10const options = { 11 method: 'GET', 12 headers: headerParameters 13}; 14 15async function invokeEndpoint() { 16 try { 17 const response = await fetch(url, options); 18 // 自定义函数用于打印 API 响应 19 printResponse(response); 20 } catch (error) { 21 console.log(`Error: ${err}`); 22 } 23} 24 25invokeEndpoint();
1import fetch from 'node-fetch'; 2 3const headerParameters = { 4 'Authorization': 'Bearer {{ACCESS_TOKEN}}', 5 'Content-Type': 'application/json' 6}; 7 8const url = new URL('https://connect.squareupsandbox.com/v2/merchants/{{MERCHANT_ID}}'); 9 10const options = { 11 method: 'GET', 12 headers: headerParameters, 13}; 14 15async function invokeEndpoint() { 16 try { 17 const response = await fetch(url, options); 18 // 自定义函数用于打印 API 响应 19 printResponse(response); 20 } catch (error) { 21 console.log(`Error: ${err}`); 22 } 23} 24 25invokeEndpoint();
| 字段 | 类型 | 描述 |
|---|---|---|
| id | 字符串 | 商户的唯一标识 ID。 |
| business_name | 字符串 | 商业实体的名称。 |
| country | 字符串 | 商户注册所在的国家。 |
| language_code | 字符串 | 商户使用的语言代码。 |
| currency | 字符串 | 商户交易使用的货币。 |
| status | 字符串 | 商户当前的状态。例如,功能完整的商户状态为 ACTIVE,功能受限的商户状态为 INACTIVE。 |
| main_location_id | 字符串 | 商户关联的主要门店 ID。 |
| owner_email | 字符串 | 商户所有者的电子邮件地址。 |