NodeJS hendt/ebay-api / getOrders / 错误 - 权限不足,无法完成请求
NodeJS hendt/ebay-api / getOrders / Error - Insufficient permissions to fulfill the request
所以我正在使用 hendt/ebay-api library 但 getOrders 调用没有成功。
这是我在设置原始用户访问令牌时使用的身份验证范围...:
eBay.auth.oAuth2.setScope([
'https://api.ebay.com/oauth/api_scope',
'https://api.ebay.com/oauth/api_scope/sell.marketing.readonly',
'https://api.ebay.com/oauth/api_scope/sell.marketing',
'https://api.ebay.com/oauth/api_scope/sell.inventory.readonly',
'https://api.ebay.com/oauth/api_scope/sell.inventory',
'https://api.ebay.com/oauth/api_scope/sell.account',
'https://api.ebay.com/oauth/api_scope/sell.account.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
'https://api.ebay.com/oauth/api_scope/sell.analytics.readonly',
'https://api.ebay.com/oauth/api_scope/sell.finances',
'https://api.ebay.com/oauth/api_scope/sell.payment.dispute',
'https://api.ebay.com/oauth/api_scope/commerce.identity.readonly',
]);
这是我的代码(ExpressJS 后端控制器方法...):
exports.getOrders = async (req, res) => {
let _id = req.params.userId; // user's _id
let token = await refreshEbayToken(_id, eBay)
console.log(`token...`, token) // not an array! It's an object!
// set OAuth2 eBay credentials
eBay.auth.oAuth2.setCredentials(token.access_token);
try {
let result = await eBay.sell.fulfillment.getOrders({
filter: 'orderfulfillmentstatus:{NOT_STARTED|IN_PROGRESS}',
limit: 5
})
console.log(`Got a result...`, result)
res.json(result)
} catch (e) {
console.log(`Got an error in getOrders...`, e)
res.status(400).json( { error: e } )
}
}
这是我得到的错误:
{
"meta": {
"errors": [
{
"errorId": 1100,
"domain": "ACCESS",
"category": "REQUEST",
"message": "Access denied",
"longMessage": "Insufficient permissions to fulfill the request."
}
]
},
"name": "EBayAccessDenied"
}
即使是通过这些范围新生成的用户访问令牌也会出现此错误。
根据 the ebay docs on getOrders,这些是此调用所需的身份验证范围:
https://api.ebay.com/oauth/api_scope/sell.fulfillment
https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly
经过进一步调查,我发现我确实在响应中使用了这些范围(下面是从较大的 ebay 错误中抓取的范围的片段)...
...%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.fulfillment.readonly%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.fulfillment%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.analytics.readonly%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.finances%20...
如上所示,我显然使用了 sell.fulfillment
和 sell.fulfillment.readonly
范围,所以我不明白问题出在哪里。
您认为可能是什么问题?
所以我正在使用该库,但 getOrders 调用没有成功。
这是我在设置原始用户访问令牌时使用的身份验证范围
https://gist.github.com/mudassaralichouhan/d952b464b2907c7f833c87c05152eb76
我终于成功了。
这是我现在收到的示例:
{
"sales": [
{
"orderId": "xxxxxxxxx",
"legacyOrderId": "xxxxxxxxx-xxxxxxxxx",
"creationDate": "2022-03-09T23:10:36.000Z",
"lastModifiedDate": "2022-03-18T15:51:04.000Z",
"orderFulfillmentStatus": "FULFILLED",
"orderPaymentStatus": "PAID",
"sellerId": "xxxx",
"buyer": {
"username": "xxxxx",
"taxAddress": {
"stateOrProvince": "xx",
"postalCode": "xxxxxxxx",
"countryCode": "xx"
}
},
"pricingSummary": {
"priceSubtotal": {
"value": "xxxxx",
"currency": "USD"
},
"deliveryCost": {
"value": "0.0",
"currency": "USD"
},
"total": {
"value": "xxxxx",
"currency": "USD"
}
},
"cancelStatus": {
"cancelState": "NONE_REQUESTED",
"cancelRequests": []
},
"paymentSummary": {
"totalDueSeller": {
"value": "xxxxx",
"currency": "USD"
},
"refunds": [],
"payments": [
{
"paymentMethod": "EBAY",
"paymentReferenceId": "xxxxxx",
"paymentDate": "2022-03-09T23:15:33.109Z",
"amount": {
"value": "xxxxxxxx",
"currency": "USD"
},
"paymentStatus": "PAID"
}
]
},
"fulfillmentStartInstructions": [
{
"fulfillmentInstructionsType": "SHIP_TO",
"minEstimatedDeliveryDate": "2022-03-14T07:00:00.000Z",
"maxEstimatedDeliveryDate": "2022-03-19T07:00:00.000Z",
"ebaySupportedFulfillment": false,
"shippingStep": {
"shipTo": {
"fullName": "xxxxxxxxxx",
"contactAddress": {
"addressLine1": "xxxxxxxxxxx",
"city": "xxxxxxxxxx",
"stateOrProvince": "xx",
"postalCode": "xxxxxxxxx",
"countryCode": "US"
},
"primaryPhone": {
"phoneNumber": "xxxxxxxxxxxxx"
},
"email": "xxxxxxxxxxxx@members.ebay.com"
},
"shippingServiceCode": "ShippingMethodStandard"
}
}
],
"fulfillmentHrefs": [
"https://api.ebay.com/sell/fulfillment/v1/order/xxxxxxxxxxx/shipping_fulfillment/xxxxxxxxxx"
],
"lineItems": [
{
"lineItemId": "xxxxxxxxxx",
"legacyItemId": "xxxxxxxxxx",
"legacyVariationId": "xxxxxxxxxx",
"sku": "xxxxxxxxxx",
"title": "xxxxxxxxxx",
"lineItemCost": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"quantity": 1,
"soldFormat": "FIXED_PRICE",
"listingMarketplaceId": "EBAY_US",
"purchaseMarketplaceId": "EBAY_US",
"lineItemFulfillmentStatus": "FULFILLED",
"total": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"deliveryCost": {
"shippingCost": {
"value": "0.0",
"currency": "USD"
}
},
"appliedPromotions": [],
"taxes": [],
"ebayCollectAndRemitTaxes": [
{
"taxType": "STATE_SALES_TAX",
"amount": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"collectionMethod": "NET"
}
],
"properties": {
"buyerProtection": true
},
"lineItemFulfillmentInstructions": {
"minEstimatedDeliveryDate": "2022-03-14T07:00:00.000Z",
"maxEstimatedDeliveryDate": "2022-03-19T07:00:00.000Z",
"shipByDate": "2022-03-14T06:59:59.000Z",
"guaranteedDelivery": false
},
"itemLocation": {
"location": "xxxxxxxxxx",
"countryCode": "US",
"postalCode": "xxxxxxxxxx"
}
}
],
"ebayCollectAndRemitTax": true,
"salesRecordReference": "xxxxxxxxxx",
"totalFeeBasisAmount": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"totalMarketplaceFee": {
"value": "xxxxxxxxxx",
"currency": "USD"
}
}
]
}
这是我的示波器:
eBay.auth.oAuth2.setScope([
'https://api.ebay.com/oauth/api_scope',
'https://api.ebay.com/oauth/api_scope/sell.marketing.readonly',
'https://api.ebay.com/oauth/api_scope/sell.marketing',
'https://api.ebay.com/oauth/api_scope/sell.inventory.readonly',
'https://api.ebay.com/oauth/api_scope/sell.inventory',
'https://api.ebay.com/oauth/api_scope/sell.account',
'https://api.ebay.com/oauth/api_scope/sell.account.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
'https://api.ebay.com/oauth/api_scope/sell.analytics.readonly',
'https://api.ebay.com/oauth/api_scope/sell.finances',
'https://api.ebay.com/oauth/api_scope/sell.payment.dispute',
'https://api.ebay.com/oauth/api_scope/commerce.identity.readonly',
]);
这是正确的代码 (express.js)...
exports.getOrders = async (req, res) => { // https://developer.ebay.com/Devzone/XML/docs/Reference/eBay/GetOrders.html
let _id = req.params.userId; // user's _id
let a = {}
a._id = _id
a.userDoc = await User.findById( { _id: a._id } )
eBay.auth.oAuth2.setCredentials( a.userDoc.token[ 0 ] ) // set OAuth2 eBay credentials
try
{
a.result = await eBay.trading.getOrders({
filter: 'orderfulfillmentstatus:{NOT_STARTED|IN_PROGRESS}',
limit: 5
})
console.log(`Got a result...`, a.result)
} catch ( e ) {
}
}
我发送 mongodb 用户 _id
作为请求参数并使用它来提取他们的用户令牌,该令牌被传递到 eBay.auth.oAuth2.setCredentials( a.userDoc.token[ 0 ] )
并允许实际进行调用... eBay.trading.getOrders
我希望这对那里的人有所帮助。我记得几个月都无法打这个电话。
所以我正在使用 hendt/ebay-api library 但 getOrders 调用没有成功。
这是我在设置原始用户访问令牌时使用的身份验证范围...:
eBay.auth.oAuth2.setScope([
'https://api.ebay.com/oauth/api_scope',
'https://api.ebay.com/oauth/api_scope/sell.marketing.readonly',
'https://api.ebay.com/oauth/api_scope/sell.marketing',
'https://api.ebay.com/oauth/api_scope/sell.inventory.readonly',
'https://api.ebay.com/oauth/api_scope/sell.inventory',
'https://api.ebay.com/oauth/api_scope/sell.account',
'https://api.ebay.com/oauth/api_scope/sell.account.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
'https://api.ebay.com/oauth/api_scope/sell.analytics.readonly',
'https://api.ebay.com/oauth/api_scope/sell.finances',
'https://api.ebay.com/oauth/api_scope/sell.payment.dispute',
'https://api.ebay.com/oauth/api_scope/commerce.identity.readonly',
]);
这是我的代码(ExpressJS 后端控制器方法...):
exports.getOrders = async (req, res) => {
let _id = req.params.userId; // user's _id
let token = await refreshEbayToken(_id, eBay)
console.log(`token...`, token) // not an array! It's an object!
// set OAuth2 eBay credentials
eBay.auth.oAuth2.setCredentials(token.access_token);
try {
let result = await eBay.sell.fulfillment.getOrders({
filter: 'orderfulfillmentstatus:{NOT_STARTED|IN_PROGRESS}',
limit: 5
})
console.log(`Got a result...`, result)
res.json(result)
} catch (e) {
console.log(`Got an error in getOrders...`, e)
res.status(400).json( { error: e } )
}
}
这是我得到的错误:
{
"meta": {
"errors": [
{
"errorId": 1100,
"domain": "ACCESS",
"category": "REQUEST",
"message": "Access denied",
"longMessage": "Insufficient permissions to fulfill the request."
}
]
},
"name": "EBayAccessDenied"
}
即使是通过这些范围新生成的用户访问令牌也会出现此错误。
根据 the ebay docs on getOrders,这些是此调用所需的身份验证范围:
https://api.ebay.com/oauth/api_scope/sell.fulfillment
https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly
经过进一步调查,我发现我确实在响应中使用了这些范围(下面是从较大的 ebay 错误中抓取的范围的片段)...
...%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.fulfillment.readonly%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.fulfillment%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.analytics.readonly%20https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.finances%20...
如上所示,我显然使用了 sell.fulfillment
和 sell.fulfillment.readonly
范围,所以我不明白问题出在哪里。
您认为可能是什么问题?
所以我正在使用该库,但 getOrders 调用没有成功。
这是我在设置原始用户访问令牌时使用的身份验证范围
https://gist.github.com/mudassaralichouhan/d952b464b2907c7f833c87c05152eb76
我终于成功了。
这是我现在收到的示例:
{
"sales": [
{
"orderId": "xxxxxxxxx",
"legacyOrderId": "xxxxxxxxx-xxxxxxxxx",
"creationDate": "2022-03-09T23:10:36.000Z",
"lastModifiedDate": "2022-03-18T15:51:04.000Z",
"orderFulfillmentStatus": "FULFILLED",
"orderPaymentStatus": "PAID",
"sellerId": "xxxx",
"buyer": {
"username": "xxxxx",
"taxAddress": {
"stateOrProvince": "xx",
"postalCode": "xxxxxxxx",
"countryCode": "xx"
}
},
"pricingSummary": {
"priceSubtotal": {
"value": "xxxxx",
"currency": "USD"
},
"deliveryCost": {
"value": "0.0",
"currency": "USD"
},
"total": {
"value": "xxxxx",
"currency": "USD"
}
},
"cancelStatus": {
"cancelState": "NONE_REQUESTED",
"cancelRequests": []
},
"paymentSummary": {
"totalDueSeller": {
"value": "xxxxx",
"currency": "USD"
},
"refunds": [],
"payments": [
{
"paymentMethod": "EBAY",
"paymentReferenceId": "xxxxxx",
"paymentDate": "2022-03-09T23:15:33.109Z",
"amount": {
"value": "xxxxxxxx",
"currency": "USD"
},
"paymentStatus": "PAID"
}
]
},
"fulfillmentStartInstructions": [
{
"fulfillmentInstructionsType": "SHIP_TO",
"minEstimatedDeliveryDate": "2022-03-14T07:00:00.000Z",
"maxEstimatedDeliveryDate": "2022-03-19T07:00:00.000Z",
"ebaySupportedFulfillment": false,
"shippingStep": {
"shipTo": {
"fullName": "xxxxxxxxxx",
"contactAddress": {
"addressLine1": "xxxxxxxxxxx",
"city": "xxxxxxxxxx",
"stateOrProvince": "xx",
"postalCode": "xxxxxxxxx",
"countryCode": "US"
},
"primaryPhone": {
"phoneNumber": "xxxxxxxxxxxxx"
},
"email": "xxxxxxxxxxxx@members.ebay.com"
},
"shippingServiceCode": "ShippingMethodStandard"
}
}
],
"fulfillmentHrefs": [
"https://api.ebay.com/sell/fulfillment/v1/order/xxxxxxxxxxx/shipping_fulfillment/xxxxxxxxxx"
],
"lineItems": [
{
"lineItemId": "xxxxxxxxxx",
"legacyItemId": "xxxxxxxxxx",
"legacyVariationId": "xxxxxxxxxx",
"sku": "xxxxxxxxxx",
"title": "xxxxxxxxxx",
"lineItemCost": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"quantity": 1,
"soldFormat": "FIXED_PRICE",
"listingMarketplaceId": "EBAY_US",
"purchaseMarketplaceId": "EBAY_US",
"lineItemFulfillmentStatus": "FULFILLED",
"total": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"deliveryCost": {
"shippingCost": {
"value": "0.0",
"currency": "USD"
}
},
"appliedPromotions": [],
"taxes": [],
"ebayCollectAndRemitTaxes": [
{
"taxType": "STATE_SALES_TAX",
"amount": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"collectionMethod": "NET"
}
],
"properties": {
"buyerProtection": true
},
"lineItemFulfillmentInstructions": {
"minEstimatedDeliveryDate": "2022-03-14T07:00:00.000Z",
"maxEstimatedDeliveryDate": "2022-03-19T07:00:00.000Z",
"shipByDate": "2022-03-14T06:59:59.000Z",
"guaranteedDelivery": false
},
"itemLocation": {
"location": "xxxxxxxxxx",
"countryCode": "US",
"postalCode": "xxxxxxxxxx"
}
}
],
"ebayCollectAndRemitTax": true,
"salesRecordReference": "xxxxxxxxxx",
"totalFeeBasisAmount": {
"value": "xxxxxxxxxx",
"currency": "USD"
},
"totalMarketplaceFee": {
"value": "xxxxxxxxxx",
"currency": "USD"
}
}
]
}
这是我的示波器:
eBay.auth.oAuth2.setScope([
'https://api.ebay.com/oauth/api_scope',
'https://api.ebay.com/oauth/api_scope/sell.marketing.readonly',
'https://api.ebay.com/oauth/api_scope/sell.marketing',
'https://api.ebay.com/oauth/api_scope/sell.inventory.readonly',
'https://api.ebay.com/oauth/api_scope/sell.inventory',
'https://api.ebay.com/oauth/api_scope/sell.account',
'https://api.ebay.com/oauth/api_scope/sell.account.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly',
'https://api.ebay.com/oauth/api_scope/sell.fulfillment',
'https://api.ebay.com/oauth/api_scope/sell.analytics.readonly',
'https://api.ebay.com/oauth/api_scope/sell.finances',
'https://api.ebay.com/oauth/api_scope/sell.payment.dispute',
'https://api.ebay.com/oauth/api_scope/commerce.identity.readonly',
]);
这是正确的代码 (express.js)...
exports.getOrders = async (req, res) => { // https://developer.ebay.com/Devzone/XML/docs/Reference/eBay/GetOrders.html
let _id = req.params.userId; // user's _id
let a = {}
a._id = _id
a.userDoc = await User.findById( { _id: a._id } )
eBay.auth.oAuth2.setCredentials( a.userDoc.token[ 0 ] ) // set OAuth2 eBay credentials
try
{
a.result = await eBay.trading.getOrders({
filter: 'orderfulfillmentstatus:{NOT_STARTED|IN_PROGRESS}',
limit: 5
})
console.log(`Got a result...`, a.result)
} catch ( e ) {
}
}
我发送 mongodb 用户 _id
作为请求参数并使用它来提取他们的用户令牌,该令牌被传递到 eBay.auth.oAuth2.setCredentials( a.userDoc.token[ 0 ] )
并允许实际进行调用... eBay.trading.getOrders
我希望这对那里的人有所帮助。我记得几个月都无法打这个电话。