导入
步骤 1:获取个人资料信息
让我们学习如何通过 API 调用获取配置文件 ID。
...
获取个人资料信息
代码示例
1{baseURL}/v1/profiles
1// 导入所需库 2const fetch = require('node-fetch'); 3 4// 定义 API 密钥 5const API_KEY = 'Bearer {{API_KEY}}'; 6 7// 定义接口地址 8const endpointUrl = 'https://api.sandbox.transferwise.tech/v1/profiles'; 9 10// 定义请求头参数 11const headerParameters = { 12 authorization: API_KEY, 13 'Content-Type': 'application/json', 14}; 15 16// 设置 API 请求选项 17const options = { 18 method: 'get', 19 headers: headerParameters, 20}; 21 22// 定义发起 API 请求的函数 23async function getProfileID() { 24 try { 25 const response = await fetch(endpointUrl, options); 26 27 // 输出响应结果 28 printResponse(response); 29 } catch (error) { 30 // 输出错误信息 31 printError(error); 32 } 33} 34 35// 调用函数发起 API 请求 36getProfileID();
在上述代码中:
- 第 5 行:我们定义了
API_KEY。 - 第 8 行:我们定义了用于获取个人资料
id的 URL。 - 第 11 至 14 行:我们定义了
headerParameters对象,包含授权信息和内容类型。 - 第 25 行:我们调用了
fetch函数发起请求。 - 第 36 行:我们执行了
getProfileID函数。
返回结果中包含两个具有不同 id 值的对象,一个是个人资料,另一个是企业资料。
响应字段说明
两个资料均包含 id、type 和 details 字段。以下是两个资料的部分响应字段:
个人资料字段
| 字段 | 类型 | 说明 |
|---|---|---|
| id | 整数 | 资料 ID |
| type | 字符串 | 类型为“个人” |
| details.firstName | 字符串 | 名字 |
| details.lastName | 字符串 | 姓氏 |
| details.dateOfBirth | 字符串 | 出生日期(格式:YYYY-MM-DD) |
| details.phoneNumber | 字符串 | 电话号码 |
| details.avatar | 字符串 | 头像图片链接 |
| details.occupation | 字符串 | 职业 |
| details.primaryAddress | 整数 | 地址对象的 ID |
企业资料字段
| 字段 | 类型 | 说明 |
|---|---|---|
| id | 整数 | 资料 ID |
| type | 字符串 | 类型为“企业” |
| details.name | 字符串 | 企业名称 |
| details.registrationNumber | 字符串 | 企业注册号 |
| details.companyType | 字符串 | 企业法律类型 |
| details.companyRole | 字符串 | 该人员在企业中的角色 |