【问题标题】:NodeJS hendt/ebay-api / getOrders / Error - Insufficient permissions to fulfill the requestNodeJS hendt/ebay-api / getOrders / 错误 - 权限不足,无法完成请求
【发布时间】:2022-04-19 05:54:22
【问题描述】:

所以我正在使用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 错误中抓取的范围的 sn-p)...

...%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.fulfillmentsell.fulfillment.readonly 范围,所以我不明白是什么问题。

您认为可能是什么问题?

【问题讨论】:

    标签: javascript node.js access-token ebay-api


    【解决方案1】:

    所以我正在使用该库,但 getOrders 调用没有成功。

    这是我在设置原始用户访问令牌时使用的身份验证范围

    https://gist.github.com/mudassaralichouhan/d952b464b2907c7f833c87c05152eb76

    【讨论】:

    • 我看了看,您似乎只使用了一个范围(除非我弄错了):https://api.ebay.com/oauth/api_scope。你需要投入更多。看我的帖子。
    【解决方案2】:

    我终于搞定了。

    这是我现在收到的一个例子:

    {
        "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

    我希望这对那里的人有所帮助。我记得好几个月都不能打这个电话。

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-11-03
      • 2018-01-24
      • 2016-10-19
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多