使用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();

最新更新