使用VBA调用FedEx Ship API遇无效JWT问题(已解决:授权链接错误)
已解决!授权时使用了错误的链接,正确的沙箱环境授权链接为:https://apis-sandbox.fedex.com/oauth/token
我用VBA调用FedEx Ship API时,一直收到错误响应:"The given JWT is invalid. Please modify your request and try again."
JSON请求体
{ "labelResponseOptions": "URL_ONLY", "requestedShipment": { "shipper": { "contact": { "personName": "Nick", "phoneNumber": 3155555555, "companyName": "company" }, "address": { "streetLines": [ "34 road dr" ], "city": "saint charles", "stateOrProvinceCode": "MO", "postalCode": 63301, "countryCode": "US" } }, "recipients": [ { "contact": { "personName": "Nick", "phoneNumber": 3155555555, "companyName": "company" }, "address": { "streetLines": [ "4469 Road" ], "city": "BATON ROUGE", "stateOrProvinceCode": "LA", "postalCode": 70808, "countryCode": "US" } } ], "shipDatestamp": "2023-06-02", "serviceType": "STANDARD_OVERNIGHT", "packagingType": "FEDEX_BOX", "pickupType": "USE_SCHEDULED_PICKUP", "blockInsightVisibility": false, "shippingChargesPayment": { "paymentType": "SENDER" }, "labelSpecification": { "imageType": "PDF", "labelStockType": "PAPER_85X11_TOP_HALF_LABEL" }, "requestedPackageLineItems": [ { "weight": { "value": 4, "units": "LB" } } ] }, "accountNumber": { "value": "740561073" } }
请求头VBA代码
Dim xmlHttp As Object Set xmlHttp = CreateObject("MSXML2.XMLHTTP") xmlHttp.Open "POST", url, False xmlHttp.SetRequestHeader "Authorization", "Bearer " & accessToken xmlHttp.SetRequestHeader "Content-Type", "application/json" xmlHttp.SetRequestHeader "Accept", "application/json"
我能成功获取到accessToken,对比官方示例后没发现格式问题。请求的API地址为:https://apis-sandbox.fedex.com/ship/v1/shipments
收到的完整响应:
{"transactionId": "20479caf-d3d9-4a26-819c-d43f7e91c799","errors":[{"code":"BAD.REQUEST.ERROR","message":"The given JWT is invalid. Please modify your request and try again."}]}
现在怀疑授权环节存在问题:官方示例中的token scope为"cxs",但我获取到的token scope是"oob",而且无论输入什么凭证都能拿到token。
获取到的token内容:
{ "access_token":"826deebc-0788-4bda-995c-e1cb5b588a51", "token_type":"Bearer", "expires_in":3600, "scope":"oob", "resource": ["https://apis.fedex.com/*"] }
内容的提问来源于stack exchange,提问作者NTaylor
相关产品推荐
相关产品推荐

