Comments (7)
I see the error. I was using .refreshToken()
when I should have been using .refreshClientToken()
.
After making the change, I got a successful newly generated access_token
from eBay.
from ebay-api.
It's eBay.buy.browse.getItem()
, you missed buy
.
The token is refreshed automatically if the refresh_token
is also set. Instead of storing the access_token
you have to store the WHOLE token that looks like this:
{
access_token: 'accessToken',
refresh_token_expires_in: 0,
refresh_token: 'refresh_token', // this is required to refresh the token
token_type: 'token_type',
expires_in: 7200
}
Why are you calling result.json()
? The result is already in Json.
Actually you don't even need the Access Token for getItem. Checkout the example here https://hendt.github.io/ebay-api/ maybe it will help you.
from ebay-api.
Ok and where does the refresh_token
get set? During the literal first authorization call?
I will need to know how to do it correctly for other calls. Thank you for guidance on getItem.
from ebay-api.
Exactly. const token = await eBay.àuth.oAuth2.getToken(code);
will return the whole token and you need to store it.
Than you can use something like
let { token } = await User.findById({_id: user});
eBay.auth.oAuth2.setCredentials(token);
from ebay-api.
Do you mean like this?
let { token } = await User.findById({_id: user})
let { access_token } = token
eBay.auth.oAuth2.setCredentials(access_token)
from ebay-api.
My bad, I fixed my code should be eBay.auth.oAuth2.setCredentials(token);
And the token
has the following structure:
{
access_token: 'accessToken',
refresh_token_expires_in: 0,
refresh_token: 'refresh_token', // this is required to refresh the token
token_type: 'token_type',
expires_in: 7200
}
from ebay-api.
I still have been unable to get this right. I'm trying to refresh a User token. After making changes which attempt to trigger refresh token to be generated, it is giving me an error TypeError: Cannot read property 'refreshToken' of undefined
.
Here is my code (expressjs controller method):
exports.refreshEbayToken = async (req, res) => {
let {
token // this is the token as we discussed previously (contains access_code, refresh_code, etc.)
} = req.body
try {
eBay.auth.oAuth2.setCredentials(token) // sets the token with expired token
let post = {
RequesterCredentials: {
eBayAuthToken: token[0].access_token
},
Item: {
Title: `Harry Potter and the Philosopher's Stone`,
Description: {
__cdata: `<div>This is the first book in the Harry Potter series. In excellent condition!</div>`
},
PrimaryCategory: {
CategoryID: "377"
},
StartPrice: 30,
CategoryMappingAllowed: true,
Country: "US",
Currency: "USD",
ConditionID: 1000,
ItemSpecifics: {
NameValueList: [
{
name: "Pages",
value: "482"
},
{
name: "Ages",
value: "10-20"
}
]
},
DispatchTimeMax: 3,
ListingDuration: "GTC",
ListingType: "FixedPriceItem",
PictureDetails: {
PictureURL : [
{ PictureURL: `https://mypicserver.com/myphoto.jpg` }
]
},
PostalCode: "90025",
Quantity: "1",
SellerProfiles: {
SellerShippingProfile: {
ShippingProfileID: `82379234987`,
ShippingProfileName: `myShipping`
},
SellerReturnProfile: {
ReturnProfileID: `82379234988`,
ReturnProfileName: `myReturns`
},
SellerPaymentProfile: {
PaymentProfileID: `82379234989`,
PaymentProfileName: `myPayments`
},
},
}
}
let result = await eBay.trading.AddFixedPriceItem(post) // attempts to post, expected to throw error
console.log(`result: `, result)
} catch(e) { // due to error, this catch is now triggered...
console.log(e)
console.log(`Attempting to refresh token...`);
try {
let newToken = await eBay.OAuth2.refreshToken() // Isn't this correct?
console.log(`newToken: `, newToken)
res.json(newToken)
} catch(error){
console.log(error)
}
}
}
Here is the relevant output I'm getting (I excluded the expected failed initial warning where ebay rejects the listing):
Attempting to refresh token...
TypeError: Cannot read property 'refreshToken' of undefined
at exports.refreshEbayToken (C:\Users\User\project\backend\controllers\ebay.js:1080:42)
at process._tickCallback (internal/process/next_tick.js:68:7)
POST /api/ebay/refreshebaytoken - - ms - -
What am I doing wrong? I am trying to list items to multiple accounts and each call requires user access token.
from ebay-api.
Related Issues (20)
- How to get rlogid from getInventoryItem call in Inventory API HOT 5
- Unable to filter using sell.fulfillment.getOrders
- GetSellerDashboard constantly returns error HOT 1
- Access token is not being refreshed by 403s on inventory item endpoint HOT 1
- Switching from axios to unjs/ofetch HOT 1
- Unable to compile ebay-api in react project HOT 1
- "could not be found or is not available in the system for the marketplace EBAY_AU" HOT 1
- listingStartDate not on type EbayOfferDetailsWithId HOT 6
- aspects in InventoryItem is now just a string HOT 12
- Adding default error handler logic HOT 5
- description: 'There was a problem with an eBay internal system or process. Contact eBay developer support for assistance', HOT 7
- getItemConditionPolicies filter is not working HOT 4
- get listing policies of sku in an inventory items HOT 1
- Call to `/oauth2/token` should allow a `redirect_uri` to be passed as a urlencoded key HOT 1
- Media API HOT 6
- [Media API] CreateVideo HOT 5
- Auth token not refreshed HOT 6
- Metric enum missing some HOT 1
- Creating FixedPriceItem with ConditionDescriptors responds with error HOT 3
- Unable to set 'refresh_token' value HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ebay-api.