Wix API: How to get an access token and refresh the access token?

Wix API: How to get an access token and refresh the access token?

If you have a headache with an access token and the refresh token of Wix API, this article will help you understand easily from the very beginning. 

To make API calls in Wix API, you need to know what an access token and the refresh token are.

  • The access token is what applications use to make API calls on behalf of a user. The access token represents the authorization of a specific application to access specific parts of a users data. In Wix API, the access token is only valid for 5 minutes.
  • The refresh token is a unique token that can be used to get more access tokens. You can have short-lived access tokens without needing to collect credentials every time one expires.

Now, lets dive into this subject a little deeper. 

The process of getting an access token and refreshing the access token includes 4 steps:

  • 1: Create an app on the Wix developer website.
  • 2: Install the app and get the token.
  • 3: Get the code. 
  • 4: Get the access token and refresh the access token.

Step 1: Create an app on the Wix developer website.

To get the access token and the refresh token in Wix, you need to create an app first. 

Now, take step 1, create an app on the Wix developer website.

create an app in wix api
Wix API: How to get an access token and refresh the access token? 18
  • Next, you need to get your app ready by reading all usage information.
  • Besides, set up a market listing for your app.
  • Finally, submit your App for review: It means Wix will review your app before putting it in the App Market.
get your app ready in wix
Wix API: How to get an access token and refresh the access token? 19

Step 2: Install the app and get the token.

In this step, you have to set up permissions and Oauth.

With permissions, choose the scopes you need to access your users data. 

  • Go to permissions in the side menu (under Build Your App).
  • Click + Add Permissions.
set permissions for your app in wix
Wix API: How to get an access token and refresh the access token? 20
  • Choose a category, then select the permission scope
set permissions for your app in wix
Wix API: How to get an access token and refresh the access token? 21
  • Click Save.

Oauth is the thing used to set up data. 

  • In the Oauth, you need to add the redirect URL. During the OAuth flow, this is where youll collect the users token query parameter.
  • In the App URL field, enter a URL to direct users to when they first get to your app. 
set the Oauth in Wix
Wix API: How to get an access token and refresh the access token? 22

After that, move to the team member and click on generate link

generate link in Wix
Wix API: How to get an access token and refresh the access token? 23

Copy this link and paste it to the new tab.

After the link is loaded, you will see the invite to try the app. Click on Add to site, and select the site that you want to add the app to. After loading the token will appear on the URL.

wix api
Wix API: How to get an access token and refresh the access token? 24
an access token in wix
Wix API: How to get an access token and refresh the access token? 25

Remember to copy the token to use in the next step. 

the token of wix
Wix API: How to get an access token and refresh the access token? 26

Step 3: Get the code. 

After completing taking the token, you need to install the app in multiple steps below.

To install an app, you need to access this link:

<a href="https://www.wix.com/installer/install?token=...&appId=...&redirectUrl=....">https://www.wix.com/installer/install?token=...&appId=...&redirectUrl=....a>
Code language: HTML, XML (xml)

As you can see the link includes https://www.wix.com/installer/install?, token, appId, and the redirect URL.  So, you need to collect those parameters to access the link.

  • Token: Beehexa has shown in step 2
  • AppId: From the Wix Developer dashboard, go to Oauth. You can see the App Id in the default section. 
  • Redirect URL: From the Wix Developer dashboard, go to Oauth. You can see the redirect URL in the URL section. 

After collecting those parameters, we have this link:

https://www.wix.com/installer/install?token=71eed85511f7f8497d39c10b1ff8fb1dbe8060d474ab7c5bce028783316d58050d2dd948eb2a10383fef80cc2ab1ef0047b47e929064cc59b2f748790eb8075169f1a88d0344e864217eb31567650111380e3b2bd5e631f1c62e53ec14ccb6dbe1596c7b02a4df42c8febceb77c3519c4c05fd6faf31dba8d0b7d82b43d34e977c752c7a3fa2c4134f02e4634030d53ca047f76884cf778c76c7cd2657cf805f07c825cae46ba8c5ac5fad838b7c4ccaf3c51ac83c8066326c939ef1380774d17a02f1e88e9972a09d5f07862618232de47505d47fede3527a02b7596919053e&appId=eb6eb071-75fe-4275-8140-644066e3a40f&redirectUrl=https://example.com
Code language: JavaScript (javascript)

Now, we will access the link. After the link is loaded, we will get the code on the URL. Remember to copy the code to use in the next step.

the code in Wix
Wix API: How to get an access token and refresh the access token? 27

Step 4: Get the access token and refresh the access token using Postman. 

Get the access token.

First, we will get the access and the refresh tokens using Postman.

  • Log in to your Postman and create a new workspace.
  • Create a new POST with this URL:
https://www.wix.com/oauth/access
Code language: JavaScript (javascript)
get an access token in wix
Wix API: How to get an access token and refresh the access token? 28
  • In the body section, enter the code.

Payload: 

{ "grant_type": "authorization_code", "client_id": , "client_secret": , "code": }
Code language: JSON / JSON with Comments (json)
body_an access token in wix
Wix API: How to get an access token and refresh the access token? 29

Accordingly, you need to get the APP_ID, APP_SECRET, and the AUTH_CODE.

APP_ID and AUTH_CODE are directed in step 3.

Now we will get the APP_SECRET.

  • From the Wix Developer dashboard.
  • Go to Oauth, you can see the APP_SECRET in the default section. 

Body Params:

NAMETYPEDESCRIPTION
grant_typeStringValue must be set to authorization_code
client_idStringThe App ID as defined in the Wix Developers Center
client_secret StringThe Secret Key for your app as defined in your Wix Developers Center
codeStringThe authorization code received from us.
  • Then click SEND

Response:

The API will return the access token and the refresh token

{ "refresh_token": "OAUTH2.eyJraWQiOiJkZ0x3cjNRMCIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaWRcIjpcImU1YjA2NzRiLWZiYTYtNDc4Zi1iMTJlLTgyZTA2NzRjNjA4ZlwifSIsImlhdCI6MTY1MjQ5NTk3MywiZXhwIjoxNzE1NTY3OTczfQ.EPC883WBWq6boP9N1tsWQVmJ_ItFxFI-KdAIQywvo2o", "access_token": "OAUTH2.eyJraWQiOiJLaUp3NXZpeSIsImFsZyI6IlJTMjU2In0.eyJkYXRhIjoie1wiYXBwSWRcIjpcImViNmViMDcxLTc1ZmUtNDI3NS04MTQwLTY0NDA2NmUzYTQwZlwiLFwiaW5zdGFuY2VJZFwiOlwiYjNlZjdlZTItMzMzYy00ZjczLThhYmQtOTBjNzdkYzZkOTM0XCIsXCJzY29wZVwiOltcIlNJVEVfU0VUVElOR1MuVklFV1wiLFwiV0lYX0RFVkVMT1BFUlMuR0VUX0VESVRPUl9ERUVQX0xJTktcIixcIldJWF9ERVZFTE9QRVJTLlNFTkRfQklfRVZFTlRTXCIsXCJXSVhfREVWRUxPUEVSUy5BUFBfUFVSQ0hBU0VfSElTVE9SWVwiLFwiU0NPUEVfU0hBUkVfVVJMLk1BTkFHRVwiLFwiV0lYX0RFVkVMT1BFUlMuQ1JFQVRFX0NIRUNLT1VUXCIsXCJXSVhfREVWRUxPUEVSUy5NQU5BR0VfQVBQX0lOU1RBTkNFXCIsXCJERVZfQ0VOVEVSLlNJVEVfUEFZTUVOVF9NRVRIT0RcIl19IiwiaWF0IjoxNjUyNDk1OTczLCJleHAiOjE2NTI0OTYyNzN9.Lj4zzdto5lTpd606STswKm-BBTMB0rRGdx3kr6Oa2-Y2IrNPxhWb0MrG3rcbxg_fNpHOc3y8JBQshIxu4V36wUEOdgSH2iMez6rZ6qlBwafkirSQBYDVxpN96ZnPG6BWufax261UrA7nZ2v725lLAjCCHeMTte0nuTMbMX8Poxlo5eCsdc-vOwepbs-QuSKTVO89hIq0PKgodVIa4htX52YTpW2GZEEVm-k6Ju0Z7qWwlmhG9CpAJXOSatg6YU4IDpF3mqBvk68J8gubfQnoeGiBR8DcXm-ZXaSlqvDIpXhTXYakSVmph5Dx_ahuBLZQXC8151oVvl2gMhDPFv11uQ"}
Code language: JSON / JSON with Comments (json)
response_an access token in wix
Wix API: How to get an access token and refresh the access token? 30

Refresh the access token using Postman. 

Each time you call the APIs, you must request a new access token. Request new access and refresh tokens using the refresh token and your secret key.

Flowing these steps below for refreshing the access token

  • Log in to your Postman and create a new workspace.
  • Create a new POST with this URL:
https://www.wix.com/oauth/access
Code language: JavaScript (javascript)
refresh the access token in wix
Wix API: How to get an access token and refresh the access token? 31
  • In the body section, enter the code.

Payload:

{ "grant_type": "refresh_token", "client_id": , "client_secret": , "refresh_token": }
Code language: JSON / JSON with Comments (json)
body_refresh the access token in wix
Wix API: How to get an access token and refresh the access token? 32

Body Params:

NAMETYPEDESCIPTION
grant_type StringValue must be set to refresh_token
client_idStringThe App ID as defined in the Wix Developers Center
client_secretStringThe Secret Key for your app as defined in your Wix Developers Center
refresh_tokenStringThe refresh token issued with the access token.
  • Then click SEND

Response:

The API will return the new access token and the refresh token in order to request a new Access Token. 

{ "refresh_token": "OAUTH2.eyJraWQiOiJkZ0x3cjNRMCIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaWRcIjpcImU1YjA2NzRiLWZiYTYtNDc4Zi1iMTJlLTgyZTA2NzRjNjA4ZlwifSIsImlhdCI6M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qqg"}
Code language: JSON / JSON with Comments (json)
response_refresh the access token in wix
Wix API: How to get an access token and refresh the access token? 33

The above are all steps to get the access token and refresh the access token. In the next article, we will explore Wix rest API, and multiple ways to make the API calls. 

In case, you have any wonders about Wix, or you want to research Wix API integration, you can visit beehexa.com, we have tons of Wix integrated solutions for many types of business, such as Wix Amazon Integration, Wix Square Integration, Wix SAPB1 integration, or Wix Salesforce Integration. 

If you have any questions, let us know in the comment below or refer to our Wix api documentation.

These steps will be shown visually in the infographic below.

Wix API: How to get an access token and refresh the access token?
Wix API: How to get an access token and refresh the access token? 34

Or you can watch this video for more overview.

Wix API - How to get an access token and refresh the access token?

Hopefully, you can do it!