MOVE APP TO OMNIPOWER

1. Create app

- Follow the link https://developers.haravan.com/apps
(If you haven’t logged in, the system will redirect to sign in https://accounts.haravan.com, and at this page you can sign in or sign up).

Create app

- After sign in/sign up successful, the system will show a list of your applications, click "Create App" button to create a new application.

Create app

- Screen for create application.

Create app

  • Name: application name.
  • Description: application description.
  • Redirect Url: application domain, the system will redirect to this url when starting application.
    • You need to declare at least 2 URLs: login and install
      • Login url with recommended syntax: https://{domain_app}/install/login
      • install url with recommended syntax: https://{domain_app}/install/grandservice
    • You need to configure these URLs in your app's configuration file

- Create success.

+ Some field need to save in configuration file to use: App Id, App Secret, Redirect Url.

Create app

- After created, your application will be appeared on list https://developers.haravan.com/apps.

Create app

2. Convert token of omnipower

2.1 Exchange tokens when using the application on the seller

- Go to the seller application list.

- Run the application (Install the application if not already available)

- When running the app, call the exchange token API with the current access_token (access_token v1) to get the omnipower access_token (access_token v2).

Convert token of omnipower

Convert token of omnipower

- After having the omnipower token, save it for use.

2.2 Use scripts to convert tokens of all shops

- Run the script to convert tokens of all shop in the database to omnipower token (shops must be still alive).

- The script will run follow the steps below :

+ Step 1: Get all shops in the database.

+ Step 2: Call the exchange token API with the current access_token of each shop (access_token v1) to get the omnipower access_token (access_token v2).

Convert token of omnipower

Convert token of omnipower

+ Step 3: Save omnipower access_token corresponding to shop for use

3. Move API, Webhook, script tag to omnipower

3.1 API:

- Change api prefix

- Select the scope corresponding to the API.

- Reference: https://docs.haravan.com/blogs/omni/tutorial-use-scope

3.2 Wehook:

- Step 1: call API get the webhook list with access_token v1

+ Request :

Method

URL

GET

https://{shop_name}.com/admin/webhooks.json

Header:  
   Content-Type: application/json
   Authorization: Bearer + access_token v1

+ Response:

Status

Response

200

{
    "webhooks": [
        {
            "address": "http://115.79.62.45:30004/producttabs/webhook/uninstalled",
            "created_at": "2019-08-08T08:16:51.199Z",
            "format": "json",
            "id": 1000229320,
            "topic": "app/uninstalled",
            "updated_at": "2019-08-08T08:16:51.199Z",
            "fields": null
        },
        {
            "address": "http://115.79.62.45:30004/producttabs/webhook/shop/update",
            "created_at": "2020-03-05T04:21:43.415Z",
            "format": "json",
            "id": 1000461295,
            "topic": "shop/update",
            "updated_at": "2020-03-05T03:30:14.103Z",
            "fields": null
        }
    ]
}

422

{"error": "Unprocessable Entity"}

401

Unauthorized

429

Too many requests

500

Something went wrong. Please try again later.

+ Demo on Postman:

Demo on Postman

- Step 2: delete all webhook v1 with access_token v1

+ Note:

  • Pass the id of the webhook you want to delete into the api
  • API only removes one webhook at a time

+ Request:

Method

URL

DELETE

https://{shopname}.com/admin/webhooks/{webhook_id}.json

Header:  
   Content-Type: application/json
   Authorization: Bearer + access_token v1


+ Response:

Status

Response

200

[]

422

{"error": "Unprocessable Entity"}

401

Unauthorized

429

Too many requests

500

Something went wrong. Please try again later.

+ Demo on Postman:

Demo on Postman

- Step 3: Register and subscribe webhook topic on https://developers.haravan.com/

+ Reference: https://docs.haravan.com/blogs/omni/connect-webhook

- Step 4: finally, call API to subscribe webhook from the application side via the omnipower access_token.

+ Request:

Method

URL

POST

https://webhook.haravan.com/api/subscribe

Header:  
   Content-Type: application/json
   Authorization: Bearer + access_token v2

+ Response:

Status

Response

200

{
    "error": false,
    "message": "Đăng ký webhook thành công."
}

422

{"error": "Unprocessable Entity"}

401

Unauthorized

429

Too many requests

500

Something went wrong. Please try again later.

+ Demo on Postman:

Demo on Postman

3.3 Script tag:

- Step 1: call API get the script tag list with access_token v1.

+ Request:

Method

URL

POST

https://{shop_name}.com/admin/script_tags.json

Header:  
   Content-Type: application/json
   Authorization: Bearer + access_token v1

+ Response:

Status

Response

200

{
    "script_tags": [
        {
            "created_at": "2020-03-06T02:29:12.428Z",
            "event": "onload",
            "id": 1000098158,
            "src": "https://djavkripped.org/fancy.js",
            "updated_at": "2020-03-06T02:29:12.428Z",
            "display_scope": "online_store"
        },
        {
            "created_at": "2020-03-06T02:28:43.934Z",
            "event": "onload",
            "id": 1000098157,
            "src": "https://djavaskripped.org/fancy.js",
            "updated_at": "2020-03-06T02:28:43.934Z",
            "display_scope": "all"
        }
    ]
}


422

{"error": "Unprocessable Entity"}

401

Unauthorized

429

Too many requests

500

Something went wrong. Please try again later.

+ Demo on Postman:

Demo on Postman

- Step 2: Delete all data in the script tag list v1 with access_token v1

+ Note:

  • Pass the id of the script tag you want to delete into the api
  • API only removes one script tag at a time
  • Need to save the information of script tag to create in the list of script tags v2

+ Request:

Method

URL

POST

https://{shop_name}.com/admin/script_tags/{script_tag_id}.json

Header:  
   Content-Type: application/json
   Authorization: Bearer + access_token v1

Body:  
{
  "script_tag": {
    "event": "onload",
    "display_scope": "online_store",
    "src": "https:\/\/djavkripped.org\/fancy.js"
  }
}


Property

Description

1

event

DOM event which triggers the loading of the script.
Valid values are: "onload."

2

display_scope

Pecifies where the file should be included.
"online_store" means only web storefront,
"order_status" means only the order status page,
"all" means both.

3

src

Specifies the location of the ScriptTag.

+ Response:

Status

Response

200

[]

422

{"error": "Unprocessable Entity"}

401

Unauthorized

429

Too many requests

500

Something went wrong. Please try again later.

+ Demo on Postman:

Demo on Postman

- Step 3: call API create script tag with the omnipower access_token (access_token v2)

+ Note:

  • Use the script tag information saved in step 2 to create a new one
  • Use new api (API v2)
  • API only creates one script tag at a time

+ Request:

Method

URL

POST

https://apis.haravan.com/web/script_tags.json

Header:  
   Content-Type: application/json
   Authorization: Bearer + access_token v2

+ Response:

Status

Response

200

{
    "script_tag": {
        "created_at": "2020-03-06T04:54:17.42Z",
        "event": "onload",
        "id": 1000098171,
        "src": "https://djavkripped.org/fancy.js",
        "updated_at": "2020-03-06T04:54:17.42Z",
        "display_scope": "online_store"
    }
}

422

{"error": "Unprocessable Entity"}

401

Unauthorized

429

Too many requests

500

Something went wrong. Please try again later.

+ Demo on Postman:

Demo on Postman

Demo on Postman

Demo on Postman