javascript - 使用 Netsuite Rest API 通过电话号码查询客户
问题描述
我正在尝试创建对 NetSuite REST API 的请求,在我的特定用例中,最容易获得的信息来源是客户编号。
我有一个axios
助手设置来发出请求。想知道是否有人可以帮助我......这就是我到目前为止所拥有的。
await ns.get('customer?q=phone')
.then((res) => {
console.log(res)
console.log('success')
})
.catch((err) => {
console.log(err);
console.log('error')
})
现在不幸的是,这不起作用。有任何想法吗?
谢谢你的时间!
编辑:找到我的解决方案!
await ns.get('customer?q=phone IS <Customer Number Here>')
.then((res) => {
console.log('success')
let custID = res.data.items[0].id
console.log(custID);
await ns.get(`customer/${custID}`)
.then((res) => {
console.log(res);
})
})
.catch((err) => {
console.log(err);
console.log('error')
})
此代码返回一个非常大的对象。打开 response.data.items 给了我客户的 ID。然后用这个 id 提出一个新的请求给了我我需要的信息。
解决方案
第一个解决方案:删除await
关键字。
ns.get('customer?q=phone')
.then((res) => {
console.log(res)
console.log('success')
})
.catch((err) => {
console.log(err);
console.log('error')
})
否则,您必须定义async
才能await
像这样使用
var getData = () => new Promise(resolve => resolve("Your data"));
async function run(){
try{
var res = await getData();// ns.get('customer?q=phone')
console.log(res);
console.log('success');
}catch(err) {
console.log(err);
console.log('error')
}
}
run();
推荐阅读
- php - 尝试更新重复列的行时的 MySQL PHP 语法
- tfs - 您可以将迭代映射到 TFS 板上的列吗?
- swift - 将数据从 NSViewController 传递到 NSSplitViewController 中的另一个 NSViewController?
- java - 使用函数接口抽象公共代码的问题
- javascript - 如果属性值为 false,则保留扩展样式组件的默认值
- ios - OpentTok (iOS) 如何订阅 hasAudio 流的变化
- c - C、链表中的Segmentation Fault
- android - 有意图地传递原始相机字节数组
- javascript - 为什么我的路线返回 404 错误 Laravel?
- c# - 当实例化的游戏对象被销毁时,它不再产生克隆