/
Fynd Authorization

Fynd Authorization

 

 

  • Generate Auth Token: For each location, there will be unique credentials details to generate Auth Token:

GET '{{oms_host}}/api/v1/{{aggregator}}/shipment/authToken?username={{x-integration-id}}&password= {{x-integration-token}}

token is valid for 1 hour

oms_host:

  • X1 (Sandbox): https://api.fyndx1.de/hogwarts

  • production: https://api.fynd.com/hogwarts

INPUT Fields:

  1. aggregator - This is a UAT environment, bydefault E-ShopBox.

  2. x-integration-id - Will be shared by Fynd team.

  3. x-integration-token - Will be shared by Fynd team.

 

STEPS :

Step1. Find all the connections corresponding to the integration type of “Fynd“ at regular intervals using cron.

Query Used:

SELECT `connectionId` FROM `channels` WHERE `integrationType` = :integrationType;

Step2. For each active connection( if isActive =”active”) if the difference between the ‘expiry’ and the ‘last cron run time’ is less than or equal to 30 min then push it into the task queue.

Note:

  • Here expiry-> accessTokenExpiryAt is a unique time at which the particular connection ID is being created the first time.

  • cron run time-> the current time at which the query has been created.

  • So, out of 10 connections let say for 6 connections if (accessTokenExpiryAt- cron run time) <= 30 min (+ve value), then the 6 connections will be pushed to task queue. remaining connections will be ignored.

Query Used:

SELECT `id`,`accessTokenExpiryAt`,`inputFields` FROM `ie_appinstall_connection` WHERE `id` IN :connectionIdList AND `isActive`="active";

Step3: Listener will listen from the taskQueue and call the CreateTokenAPI one at a time.

Step4: Fynd will provide an API key that will be ‘authToken’.

Note:

  • API key: For every new integration, Fynd creates a session key that is nothing but authToken.

  • This API key is used to send the inventory of all the locations(stores) for a seller.

API key generation curl:

curl --location -g --request GET 'https://api.fyndx1.de/{{oms_host}}/api/v1/{{aggregator}}/shipment/authToken?username={{x-integration-id}}&password={{x-integration-token}}'

Parameters Used During Generation of Access Token:

key/ Intro

value

Mandetory

key/ Intro

value

Mandetory

path provided by fynd team

oms _host

Y

Eshopbox (This is a UAT environment)

aggregator

Y

username

x-integration-id

Y

password

x-integration-token

Y

Response:

{
"status": "SUCCESS",
"accessToken": "NjA4MTAzODFhMzk1ZTE3NjNiMDlhYWVlLjdhY0JER2NXdS4zODQ="
}

 

Step5. Update the accessToken and its info in the database. and Save AccessTokenExpiryAt, AccessTokenGeneratedOn along with accessToken in DataBase.

Query Used:

UPDATE `ie_appinstall_connection` SET `accessToken` = :new_access_token, `accessTokenExpiryAt` = :new_expiry_time, `accessTokenGeneratedOn` = :current_time WHERE `ie_appinstall_connection`.`id` = :connection_id;

 

Step 6: Make a cron where (accessTokenExpiryAt-current_time)<10 min

  1. fetch list of connections where ((accessTokenExpiryAt- currentTime )<10 min) for all the active connectionId's whose integrationType=”15” (For fynd integrationType is “15”.

SELECT ie_appinstall_connection.id, ie_appinstall_connection.refreshToken, ie_appinstall_connection.state, ie_appinstall_connection.authorizationCode, ie_appinstall_connection.accessTokenGeneratedOn, ie_appinstall_connection.accessTokenExpiryAt, ie_appinstall_connection.isActive, ie_appinstall_connection.inputFields FROM ie_appinstall_connection WHERE ie_appinstall_connection.isActive='active' AND ie_appinstall_connection.id=id: AND ie_appinstall_connection.accessTokenExpiryAt <= (NOW() + INTERVAL 10 MINUTE)

 

2. Push all connections to Taskqueue

3. Fetch Existing Connection Details from DataBase using ConnectionID

SELECT `id`,'account_id','channel_id','additionalDetails' FROM `channels` WHERE `ConnectionId` = :ConnectionId

4. Call Fynd Refresh Token API

url- http://{}/api/fynd/refresh/connection

5. Update new Details in Data Base

UPDATE INTO 'channel' SET `:id`,':account_id',':channel_id',':additionalDetails' WHERE 'connectionId'=:connectionId

7. Clear existing Cache

8. create new Cache and push new connectionDetail from DataBase to Cache Memory

9. create new access token corresponding to connectionId .

SELECT ie_appinstall_connection.accessToken FROM ie_appinstall_connection WHERE ie_appinstall_connection.id =:connectionId

response: Once the accessToken is generated store it into the Cache Memory in the format given below.

{ "connectionAccessToken_{{connectionId}}":"{{ACCESS TOKEN}}" }

 

Related content