Print
Setting up API
Getting Started
To start using Developer API, you'll have to follow this steps:
- Create a
Client
. EachClient
contains information used by Cafebazaar to authenticate an API user. To create aClient
, go to your developer panel, click on the Developer API on the side menu to go to Developer API page. In this page click on the New Client button. - In the opened modal, enter your desired value for
Redirect URI
. This address specifies where should Cafebazaar send the response to your request forAuthentication Code
in the next steps. You can set this address to somewhere in your server so that cafebazaar redirect you to it or you can set it to any address and do the following steps manually. - Go to the following address: https://pardakht.cafebazaar.ir/devapi/v2/auth/authorize/?response_type=code&access_type=offline&redirect_uri=<REDIRECT_URI>&client_id=<CLIENT_ID> Note that you should replace <REDIRECT_URI> and <CLIENT_ID> with values from the
Client
you've created in the previous steps. - If your information are correct, you'll see a page demanding your authorization. Click on Authorize.
- Your browser will redirect you to the address you've entered as
Redirect URI
. TheAuthentication Code
is sent with this request as a GET query field with the name "code", which looks similiar toaffAKBEs80Yz1AjHXtoKHZnWj1UItfnKwp1b5FRg
. - By sending a POST requsest to:
https://pardakht.cafebazaar.ir/devapi/v2/auth/token/
With these fields:grant_type=authorization_code code=<the code from the previous step> client_id=<the client ID token from your defined Client in previous steps> client_secret=<the client secret from your defined Client> redirect_uri=<the redirect URI from your defined Client>
You will recieveaccess_token
andrefresh_token
.
A successful response will be JSON format and looks similiar to:{ "access_token": "GWObRK06KHLr8pCQzDXJ9hcDdSC3eV", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "yBC4br1l6OCNWnahJvreOchIZ9B6ze", "scope": "androidpublisher" }
In case of an error, you'll recieve a response with 40X status code, with a body of JSON object containing anerror
field which specifies the error. - Now that you have recieved your
access_token
, you can use the API by sending these kind of requests:https://pardakht.cafebazaar.ir/devapi/v2/api/<your desired function>?access_token=<access_token you've recieved>
You can also putaccess_token
inAuthorization
header of your request instead.
In case of an error, you'll recieve a response with 40X status code, with a body of JSON object containing anerror
field which specifies the error and anerror_description
field explaining the cause of error. - Each
access_token
is only valid for a short time. After youraccess_token
expired, you can get a new one from Cafebazaar using yourrefresh_token
. To do so, send a POST request to:https://pardakht.cafebazaar.ir/devapi/v2/auth/token/
With these fields:grant_type=refresh_token client_id=<the client ID token from your defined Client> client_secret=<the client secrey from your defined Client> refresh_token=<the refresh token from the previous steps>
A successful response will be JSON format and looks similiar to:{ "access_token": "uX5qC82EGWjkjjeyvTzTufHOM9HZfM", "token_type": "Bearer", "expires_in": 3600, "scope": "androidpublisher" }
In case of an error, you'll recieve a response with 40X status code, with a body of JSON object containing anerror
field which specifies the error.
Using this, your server can access Developer API continuously.
Was this content helpful?
Write your comment here...
If you have any comment on this content or any idea to make it better, use this form to send us your comment.
Publish Date: ۱۴۰۰-۰۳-۲۹ ۰۸:۱۹
Latest Update: ۱۴۰۰-۰۴-۱۴ ۰۶:۱۲