hendt / ebay-api

eBay Node API in TypeScript for Node and Browser with RESTful and Traditional APIs. This library aims to implement all available eBay apis.
https://hendt.gitbook.io/ebay-api
MIT License
153 stars 40 forks source link

Hi how to address that cannot use import #3

Closed Liu1140725529 closed 4 years ago

Liu1140725529 commented 4 years ago

I want to use this module in aws Lambda/cloud9, but I can't import it in my js file, only can use 'require'. I found many ways to transforms the two forms, but they all can't be used in Lambda this cloud server platform.

dantio commented 4 years ago

Hi, you can use it like this:

const eBayApi = require("@hendt/ebay-api");

const eBay = new eBayApi({
      appId: 'appId',
      certId: 'certId',
      devId: 'devId',
      sandbox: true,
      siteId: 77
    });
Liu1140725529 commented 4 years ago

Hi, Thanks for your reply and sorry for bothering you. I am trying this way, but there is some error log when use function.

The js code: var eBayApi = require("@hendt/ebay-api").default; const ebay = new eBayApi({ appId: '**-e0df72fe', certId: '-c3fb', devId: '63571', // Required for traditional trading API sandbox: true, siteId: eBayApi.SiteId.EBAY_DE, // see https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html ruName: '', // Required for authorization code grant authToken: '', }); exports.handler = (event) => { ebay.buy.browse.getItem('v1|651094235351').then(a => { console.log(a); }).catch(e => { console.log(e); }); };

The err log:

Error: Request failed with status code 400 at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15) at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12) at Unzip.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:236:11) at Unzip.emit (events.js:228:7) at endReadableNT (_stream_readable.js:1185:12) at processTicksAndRejections (internal/process/task_queues.js:81:21) { config: { url: 'https://api.sandbox.ebay.com/buy/browse/v1/item/v1%7C651094235351 https://api.sandbox.ebay.com/buy/browse/v1/item/v1%7C651094235351', method: 'get', params: { fieldgroups: undefined }, headers: { Accept: 'application/json, text/plain, /', 'Access-Control-Allow-Origin': '', 'Access-Control-Allow-Headers': 'X-Requested-With, Origin, Content-Type, X-Auth-Token', 'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE', 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'Accept-Encoding': 'application/gzip', .....................* And the aBey error explanation shows: [image: 图片.png] Regards, NAI

Daniil Tomilow notifications@github.com 于2020年3月10日周二 下午4:54写道:

Hi, you can use it like this: ` const eBayApi = require("@hendt/ebay-api").default;

const eBay = new eBayApi({ appId: 'appId', certId: 'certId', devId: 'devId', sandbox: true, siteId: 77 }); `

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hendt/ebay-api/issues/3?email_source=notifications&email_token=ANU4XLGA62G3JNS6FYJURS3RGX55JA5CNFSM4LESX7Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOKRGRY#issuecomment-596972359, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANU4XLBAHWLFSC4X7H2OOULRGX55JANCNFSM4LESX7QQ .

dantio commented 4 years ago

Please remove

      ruName: '***', // Required for authorization code grant
  authToken: '***',

and try again.

Liu1140725529 commented 4 years ago

Sorry, It still can't work. And I tried not to use Sandbox, failed responding to the same error message. Even deleted the siteId.

2020-03-16 23:43:04.202 EBayEBayNotFound: Request failed with status code 404 at EBayNotFound.EBayError [as constructor] (/var/task/node_modules/@hendt/ebay-api/lib/errors/index.js:25:47) at new EBayNotFound (/var/task/node_modules/@hendt/ebay-api/lib/errors/index.js:122:28) at Browse. (/var/task/node_modules/@hendt/ebay-api/lib/api/restful/index.js:234:27) at step (/var/task/node_modules/@hendt/ebay-api/lib/api/restful/index.js:44:23) at Object.next (/var/task/node_modules/@hendt/ebay-api/lib/api/restful/index.js:25:53) at /var/task/node_modules/@hendt/ebay-api/lib/api/restful/index.js:19:71 at new Promise () at __awaiter (/var/task/node_modules/@hendt/ebay-api/lib/api/restful/index.js:15:12) at Browse.Api.handleEBayError (/var/task/node_modules/@hendt/ebay-api/lib/api/restful/index.js:208:16) at Browse. (/var/task/node_modules/@hendt/ebay-api/lib/api/restful/index.js:174:51) { meta: { errors: [ [Object] ] }, name: 'EBayEBayNotFound' }

Daniil Tomilow notifications@github.com 于2020年3月11日周三 上午12:12写道:

Please remove

  ruName: '***', // Required for authorization code grant

authToken: '***',

and try again.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hendt/ebay-api/issues/3?email_source=notifications&email_token=ANU4XLDAUEGTFNVDUCCNKCLRGZRG5A5CNFSM4LESX7Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOMCJSY#issuecomment-597173451, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANU4XLEYFY6UVYVIQZ56N7LRGZRG5ANCNFSM4LESX7QQ .

dantio commented 4 years ago

The error message shows that the Item was not found.

e.g.

var eBayApi = require("@hendt/ebay-api");
const eBay = new eBayApi({
  appId: '******-e0df72fe',
  certId: '*****-c3fb',
  sandbox: false,
  siteId: eBayApi.SiteId.EBAY_US
});
exports.handler =  (event) => {
eBay.buy.browse.getItem('v1|173102231406|0').then(a => {
    console.log(a);
}).catch(e => {
    console.log(e.meta);
});
};
dantio commented 4 years ago

Hey, did it work? I updated the libarary so you don't have to use '.default' in require statement.

var eBayApi = require("@hendt/ebay-api");

should work fine

Liu1140725529 commented 4 years ago

Hey, That's very kind of you. Many of the functions worked perfectly if the authToken is deleted. But if some functions need authToken and I put it on, there will be an error (401/400) come out.

Daniil Tomilow notifications@github.com 于2020年3月20日周五 上午3:40写道:

Hey, did it work? I updated the libarary so you don't have to use '.default' in require statement.

var eBayApi = require("@hendt/ebay-api");

should work fine

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hendt/ebay-api/issues/3#issuecomment-601379984, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANU4XLGUNCHU5GSBVNZCDXLRIJYKJANCNFSM4LESX7QQ .

Liu1140725529 commented 4 years ago

like , function : eBay.buy.order.initiateCheckoutSession

Naijie Liu liu1140725529@gmail.com 于2020年3月20日周五 上午5:25写道:

Hey, That's very kind of you. Many of the functions worked perfectly if the authToken is deleted. But if some functions need authToken and I put it on, there will be an error (401/400) come out.

Daniil Tomilow notifications@github.com 于2020年3月20日周五 上午3:40写道:

Hey, did it work? I updated the libarary so you don't have to use '.default' in require statement.

var eBayApi = require("@hendt/ebay-api");

should work fine

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hendt/ebay-api/issues/3#issuecomment-601379984, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANU4XLGUNCHU5GSBVNZCDXLRIJYKJANCNFSM4LESX7QQ .

dantio commented 4 years ago

Thank you, I'll check!

dantio commented 4 years ago

I checked the docs for eBay.buy.order.initiateCheckoutSession on eBay. First of all, you have to use authorization code grant. You can check here the example. However, it will still not work I think.

Anyone with an eBay developer account can use the Buy APIs in the sandbox with the exception of the methods in the checkout_session resource (i.e., methods used for eBay member checkout). If you are approved for production use of the Buy APIs for a member checkout use case, you will be granted access to use the member checkout methods in the sandbox, too. We advise you to complete the production application process and get approval before you invest significantly in application development and testing. (here)

Liu1140725529 commented 4 years ago

Thanks for your help, i have finished the project.

Daniil Tomilow notifications@github.com 于2020年3月21日周六 上午12:16写道:

I checked the docs for eBay.buy.order.initiateCheckoutSession on eBay. First of all, you have to use authorization code grant https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html. You can check here https://github.com/hendt/ebay-api/blob/master/examples/restful/authFlow.ts the example. However, it will still not work I think.

Anyone with an eBay developer account can use the Buy APIs in the sandbox with the exception of the methods in the checkout_session resource (i.e., methods used for eBay member checkout). If you are approved for production use of the Buy APIs for a member checkout use case, you will be granted access to use the member checkout methods in the sandbox, too. We advise you to complete the production application process and get approval before you invest significantly in application development and testing. (here) https://developer.ebay.com/api-docs/buy/static/buy-requirements.html#Producti2

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hendt/ebay-api/issues/3#issuecomment-601785156, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANU4XLACRYWUFXKBGRYCZFTRIOJFZANCNFSM4LESX7QQ .