Skip to main content

Catalog Functions

USER

requestUserConsents(options, callback)

1. Function introduction

Request to access user’s information. It will show a bottom drawer to request for user information

To use this function, please follow the Request Permission document

2. Function request & response params

Request

ParamsData typeRequiredDescription
optionsobjectyesAn object with “permissions” field is an array for requested permission
callbackfunctionyesCallback function with data from the request

Options object

FieldData typeRequiredDescription
permissionsarrayyesAn array contain object represent as a permission.

Permission object

FieldData typeRequiredDescriptionValue
rolestringyesPermission role"address" | "addressKyc" | "city" | "countryCode" | "countryName" | "currentAddress" | "deviceName" | "deviceOs" | "dobKyc" | "email" | "fullNameKyc" | "gender" | "genderKyc" | "loyaltyPoints" | "maritalStatus" | "microShop" | "name" | "nationality" | "nationalityKyc" | "nickname" | "phone" | "preferedLanguage" | "professional"
requiredbooleannoSet a permission role to be required sharing from usertrue | false

Response

ParamsData typeDescription
dataobjectUser’s data
statusobjectStatus of requested permission

3. Sample Request & Response

Request

MiniApi.requestUserConsents({
“permissions”: [
{
"role": “name”,
"require": true
},
{
"role": “phone”
},
{
"role": “email”,
}
]
}, (response) => {
console.log(response)

// Data handle for old and new Platform version
const name = response?.name || response?.data?.name;
const phone = response?.phone || response?.data?.phone;
const email = response?.email || response?.data?.email;
})

Response

// Case 1: User accept sharing some data
{
"data": {
"name": "John Doe",
"phone": "09xxxxxxxx"
},
"status": {
"email": "denied",
"name": "granted",
"phone": "granted"
}
}

// Case 2: User cancelled sharing data
{
"data" : {}
"status" : "cancelled"
}

// Case 3: AppId doesn’t have permission to request sharing data / Wrong appId. Go to developers.momoapp.vn to request permission
{
"data" : {},
"status" : {}
}

4. Error code & handle exception

Error CodeDescription
-1No permission

getUserConsents(options, callback)

1. Function introduction

Access user’s information that is already granted. Data will be returned through callback

To use this function, please follow the Request Permission document

2. Function request & response params

Request

ParamsData typeRequiredDescription
optionsobjectyesAn object with “permissions” key as an array for permission
callbackfunctionyesCallback function with data from the request

Options object

FieldData typeRequiredDescription
permissionsarrayyesAn array contain object represent as a permission.

Permission object

FieldData typeRequiredDescriptionValue
rolestringyesPermission role"address" | "addressKyc" | "city" | "countryCode" | "countryName" | "currentAddress" | "deviceName" | "deviceOs" | "dobKyc" | "email" | "fullNameKyc" | "gender" | "genderKyc" | "loyaltyPoints" | "maritalStatus" | "microShop" | "name" | "nationality" | "nationalityKyc" | "nickname" | "phone" | "preferedLanguage" | "professional"

Response

ParamsData typeDescription
dataobjectUser’s data
statusobjectStatus of requested permission

3. Sample Request & Response

Request

MiniApi.getUserConsents({
“permissions”: [
{
"role": “name”,
},
{
"role": “phone”
},
{
"role": “email”,
},
]
}, (data) => {
// Data handling
const name = response?.data?.name;
const phone = response?.data?.phone;
const email = response?.data?.email;
})

Response

{
"data": {
"name": "John Doe",
"phone": "09xxxxxxxx"
},
"status": {
"email": "denied",
"name": "granted",
"phone": "granted"
}
}

4. Error code & handle exception

Error CodeDescription
-1No permission

getUserAuth(callback)

1. Function introduction

Get User Authentication

2. Function request & response params

Request

ParamsData typeRequiredDescription
callbackfunctionCallback

Response

ParamsData typeDescription
authCodestringAuth code
miniAppUserIdstringId of Mini App user
partnerUserIdstringId of partner user

3. Sample Request & Response

Request

MiniApi.getUserAuth(callback);

Response

{
authCode: "eyJ...";
miniAppUserId: "MRk...";
partnerUserId: "MRv...";
}

goHome(callback)

1. Function introduction

Navigate to home screen

2. Function request & response params

Request

ParamsData typeRequiredDescription
callbackcallbackallback

3. Sample Request & Response

Request

   MiniApi.goHome(callback);

Response

N/A

goBack(callback)

1. Function introduction

Navigate to previous screen

2. Function request & response params

Request

ParamsData typeRequiredDescription
callbackcallbackCallback

3. Sample Request & Response

Request

   MiniApi.goBack(callback);

Response

N/A

1. Function introduction

Open url with callback deep link

2. Function request & response params

Request

ParamsData typeRequiredDescription
callbackDeepLinkcallbackCallback

3. Sample Request & Response

Request

MiniApi.openURL(callbackDeepLink);

Response

N/A

openWeb(params, callback)

1. Function introduction

Open web url

2. Function request & response params

Request

ParamsData typeRequiredDescription
paramsobject{url,html,title}
callbackcallbackCallback

3. Sample Request & Response

Request

MiniApi.openWeb(
{
url: "https://www.google.com",
title: "google"
},
callback
);

Response

N/A

dismissAll(callback)

1. Function introduction

Dismiss all screen

2. Function request & response params

Request

ParamsData typeRequiredDescription
callbackcallbackCallback

3. Sample Request & Response

Request

MiniApi.dismissAll(callback);

Response

N/A

dismiss(result, callback)

1. Function introduction

Dismiss current screen and return result for previous route

2. Function request & response params

Request

ParamsData typeRequiredDescription
resultobjectResult
callbackcallbackCallback

3. Sample Request & Response

Request

MiniApi.dismiss({resultCode:”001”},callback);

Response

N/A

UTILITIES

copyToClipboard(text, toastMsg)

1. Function introduction

Copy text to Clipboard and show toast

2. Function request & response params

Request

ParamsData typeRequiredDescription
textstringText to save to Clipboard
toastMsgstringText to show on toast

3. Sample Request & Response

Request

MiniApi.copyToClipboard("Text to copyToClipboard","Text to show toast");

Response

N/A

share(data, callback)

1. Function introduction

Share text content to other apps

2. Function request & response params

Request

ParamsData typeRequiredDescription
data
callbackcallbackCallback

3. Sample Request & Response

Request

  MiniApi.share("Text to share",callback);

Response

N/A

PHONE

openDialer(phone)

1. Function introduction

Open Dialer to call

2. Function request & response params

Request

ParamsData typeRequiredDescription
phonetextyesPhone number

3. Sample Request & Response

Request

MiniApi.openDialer("0xxxxxxxx");

Response

4. Sample Request & Response

Cannot catch error and exception. If input wrong argument’s type will crash app

IMAGE

getBase64FromUrl(url, callback)

1. Function introduction

Convert image from url to base64 string

2. Function request & response params

Request

ParamsData typeRequiredDescription
urlstringUrl of image
callbackcallbackCallback

3. Sample Request & Response

Request

MiniApi.getBase64FromUrl("https://example.png", (data) => {
console.log(data);
})

Response

ParamsData typeDescription
datastringBase64 string

4. Sample Request & Response

No error and exception. If input wrong argument’s type will crash app

getImage(options, callback)

1. Function introduction

Get image from gallery or capture new image

2. Function request & response params

Request

ParamsData typeRequiredDescription
optionsobject{type: "camera"/"album", editable: true/false}
callbackcallbackCallback

3. Sample Request & Response

Request

MiniApi.getImage({
type: "camera",
editable: true
}, (data) => {
console.log(data);
})

Response

ParamsData typeDescription
datastringBase64 string

saveImage(base64Image, callback)

1. Function introduction

Save image to gallery

2. Function request & response params

Request

ParamsData typeRequiredDescription
base64Imagestring
callbackcallback

3. Sample Request & Response

Request

MiniApi.saveImage(data, (res) => {
console.log(res);
})

Response

ParamsData typeDescription
databooleantrue if image is saved in gallery, false otherwise

getImageSize(uri, callback)

1. Function introduction

Get size image

2. Function request & response params

Request

ParamsData typeRequiredDescription
uristringyes
callbackcallbackcallback

3. Sample Request & Response N/A

STORAGE

getItem(key, callback)

1. Function introduction

Get data from Storage

2. Function request & response params

Request

ParamsData typeRequiredDescription
keystringyesKey
callbackcallbackReturn value

3. Sample Request & Response

Request

MiniApi.getItem('API', (data) => {
console.log(data);
})

Response

ParamsData typeDescription
datastringValue of the key

setItem(key, value)

1. Function introduction

Set data to Storage

2. Function request & response params

ParamsData typeRequiredDescription
keystringyesKey
valuestringyesValue

3. Sample Request & Response

Request

MiniApi.setItem(‘API’, ‘hello’)

Response

void

removeItem(key)

1. Function introduction

Remove data from Storage

2. Function request & response params

Request

ParamsData typeRequiredDescription
keystringKey

3. Sample Request & Response

Request

MiniApi.removeItem(‘API’)

Response

void

PERMISSIONS

requestPermission(permission, callback)

1. Function introduction

Request permissions on the device such as camera, location,...

2. Function request & response params

Request

ParamsData typeRequiredDescription
permissionstring“camera” | “photo” | “storage” | “location” | “contacts”
callbackcallbackCallback

3. Sample Request & Response

Request

MiniApi.requestPermission('photo', (data) => {
console.log(data);
})

Response

ParamsData typeDescription
datastring‘granted’ if allow, ‘denied’ if not allow, ‘unavailable’ if the permission is not exist

checkPermission(permission, callback)

1. Function introduction

Check permission has granted

2. Function request & response params

Request

ParamsData typeRequiredDescription
permissionstring“camera” | “photo” | “storage” | “location” | “contacts”
callbackcallbackcallback

3. Sample Request & Response

Request

MiniApi.checkPermission(‘camera’, (data) => {
console.log(data);
})

Response

ParamsData typeDescription
datastring‘granted’ if allow, ‘denied’ if not allow, ‘unavailable’ if the permission is not exist

LOCATION

getLocation(callback)

1. Function introduction

Get location of device

2. Function request & response params

Request

ParamsData typeRequiredDescription
callbackcallbackReturn device’s location

3. Sample Request & Response

Request

MiniApi.getLocation((data) => {
console.log(data);
})

Response

{
"mocked": boolean,
"timestamp": number,
"coords": {
"speed": number,
"heading": number,
"altitude": number,
"accuracy": number,
"longitude": float,
"latitude": float
}
}
ParamsData typeDescription
dataobject(above code block)

CAMERA

scanQRCode(data, callback)

1. Function introduction

Get data from qr code

2. Function request & response params

Request

ParamsData typeRequiredDescription
datadeeplink
callbackcallbackCallback

3. Sample Request & Response

Request

MiniApi.scanQRCode(data, (result) => {
console.log(data);
})

Response

ParamsData typeDescription
dataobjectData in the deeplink

MESSAGE, DIALOG

showToast(...args)

1. Function introduction

Show Toast

2. Function request & response params

Request

ParamTypeRequiredDescription
objectobjectyesObject contains field like description, type, and duration
descriptionstringyesToast description
typestringyesToast type
durationnumberyesToast duration

Reponse

Show toast at the end of the screen

3. Sample Request & Reponse

Request

MiniApi.showToast({
description: "Successfully",
type: "success",
duration: 2000
});

Response

hideToast()

1. Function introduction

Hide Toast

2. Sample Request & Response

Request

MiniApi.hideToast();

showToastSuggestion(...args)

1. Function introduction

Show suggestion toast

2. Function request

Request

ParamsData TypeRequiredDescription
typestringyesType of the call-to-action.
Value: share | addFavorite | addShortcut.
durationnumbernoSuggestion toast's duration

3. Sample Request & Response

Request

MiniApi.showToastSuggestion({
type: 'addShortcut',
duration: 2000,
},callback);

Response

hideToastSuggestion()

1. Function introduction

Hide suggestion toast

2. Sample Request

Request

MiniApi.hideToastSuggestion()

showAlert(title, message, buttonTitles, callback)

1. Function introduction

Show dialog alert

2. Function request & response params

Request

ParamsData typeRequiredDescription
titlestringTitle
messagestringMessage
buttonTitlesarrayButton titles
callbackcallbackReturn index of CTAs of dialog which be clicked

3. Sample Request & Response

Request

 MiniApi.showAlert(
"hello",
"hello world",
["OK", "Cancel"],
(data) => {
console.log(data);
}
)

Response

ParamsData typeDescription
datanumberReturn 0 or 1 based on the action chosen

showAction(title, buttonTitles, callback)

1. Function introduction

Show bottom sheet to choose action

2. Function request & response params

Request

ParamsData typeRequiredDescription
titlestringTitle
buttonTitlesarrayButton titles
callbackcallbackReturn index of CTAs of bottomSheet which be clicked

3. Sample Request & Response

Request

 MiniApi.showAction(
"hello",
["OK", "Cancel"],
(data) => {
console.log(data);
}
)

Response

ParamsData typeDescription
datanumberReturn 0 or 1 based on the action chosen

SCREEN

showLoading()

1. Function introduction

Show loading

2. Function request & response params |

3. Sample Request & Response

Request

MiniApi.showLoading()

Response

void

hideLoading()

1. Function introduction

Hide loading

2. Function request & response params |

3. Sample Request & Response

Request

MiniApi.hideLoading()

Response

void