4

A am just beginning to familiarize myself with the eBay RESTFUL API, forgive me this basic question, but I found no answer yet.

I have an eBay account since many years ago. I registered a developer account (same eMail address) recently, and I got the Tokens for Sandbox and Production. I have successfully used public APIs like list items, search items, and such, to verify the tokens, by querying some items in eBay.

How do I preceed from here to access data specific to my eBay account, like, for instance, the list of purchases and sales? Somehow I need to connect my app to my live eBay account, I guess, and give my app permissions to read data, but I could not find any matching setting in my eBay account settings nor in the API calls.

Please guide me through the next step: how do I give my app the required permissions, and how do I build a simple read-only query to query, for instance, the items I have purchased.

I think this question does not depend on any programming language, feel free to use any programming language you like.

Many Thanx!

Nimral
  • 657
  • 8
  • 25
  • Does this answer your question? https://developer.ebay.com/api-docs/static/oauth-consent-request.html – Morph21 Mar 30 '22 at 08:21
  • I'm having similar issues - the documentation is long, rambling and unfocussed and I now have both a developer and seller account set up using the same email - but can't work out how to link the two. – Adam B Mar 31 '22 at 06:51
  • @Szprota21: this does indeed look promising! Unfortunately there is quite a bit of information and a lot of links to follow, I haven't jet reached the ends of all those paths, it will take me a while until I have stitched together all the details to successd. But again, it looks like a very good place to start reading. – Nimral Mar 31 '22 at 11:55
  • @Nimral check my answer – Morph21 Apr 01 '22 at 07:38

1 Answers1

3

Ok so if we are talking only about Authorization token and calling seller api like orders (in ebay it's called fullfilments i believe).

We need to start with creating User Token.

You can create one here: enter image description here

Then you need to add ebay redirect URL:

enter image description here

I don't know much about Auth'n'Auth so I will talk only about OAuth

After adding new redirect URL you should add url address for authorization success and failure. You will be redirected there after authorization.

Now we can test if generation of token works.

For this example i did set my redirect url like that:

enter image description here

We need to click "Test Sign-in" (set radio button to OAuth before) You should be redirected to website:

enter image description here

You need to sign in with account which have access to sandbox.ebay.com or ebay.com (depends if you are on sandbox or production environment)

After logging in I don't remember if there will be another window with confirmation of App scopes to confirm (I already done it before). But if that is the case just click confirm button.

Now you should be redirected to https://localhost.com which we did set up as our success redirect url

Url should look like that

https://localhost.com/?code=v%5E1.1%0VeMTI%3D%3D&expires_in=299

That code parameter is much longer btw. And you can see that it's url encoded so you need to decode it before using

And now you are almost at home :D

You have 300 seconds to call a POST request to authorize with that code parameter.

POST https://api.sandbox.ebay.com/identity/v1/oauth2/token

Header required

Remember first screen shot?

You need to go there and get your App ID, Cert ID then concatenate it with ":" then encode it to Base64 and add before that value "Basic " keyword.

In pseudo code it should looks like that:

Authorization:Basic Base64.encode(AppID + ":" + CertID)

Body required

format of Body needs to be "x-www-form-urlencoded" (key:value format basically)

here you need

grant_type:authorization_code

code:{code}

redirect_uri:{redirect_name}

{code} - is value from success authorization url {redirect_name} - you can find it on screen below marked with red circle

enter image description here

If you did everything right you should get response from ebay

{
    "access_token": "v^1.1#i^1#r^0VbbxW1wjv4HZGAAA",
    "expires_in": 7200,
    "refresh_token": "v^1.1#i^1#f^0#r^FDQ=",
    "refresh_token_expires_in": 47304000,
    "token_type": "User Access Token"
}

You should save that data, access_token is used for accessing data, refresh_token is used to refresh access_token.

Example request with authToken

GET https://api.sandbox.ebay.com/sell/fulfillment/v1/order?filter=creationdate:[2022-03-31T08:25:43.511Z..]

You need Authroization header:
Authorization:Bearer v^1.1#i^1#r^0VbbxW1wjv4HZGAAA

That's it I guess. To implement that into your app you need to be able to generate the first url which you are redirected to after clicking "Test Sign-in" and that's basically it.

Btw you refresh token like that

POST https://api.sandbox.ebay.com/identity/v1/oauth2/token

Body x-www-form-urlencoded

grant_type:refresh_token

refresh_token:v^1.1#i^1#f^0#r^FDQ=

Header Authorization:Basic Base64.encode(AppID + ":" + CertID)

I hope that will help someone. :)

Morph21
  • 1,111
  • 6
  • 18