Key-Value Storage


PhonePe provides a key-value storage. Both the keys and values can only be of type string.

getItem

(preferenceName:
Description: This method is used to get a stored value from native key-value storage

Request Parameters

Parameter Name

Type

Description

preferenceName

string

Name of the key-value storage file. A merchant can have multiple key-value storage files for their app

key

string

Name of the key to fetch the value for

defaultValue

undefined/string

Default value in case the key doesn't exist

Usage:

sdk.getItem('app', 'key', undefined)
  .then((data) => {})
  .catch((err) => {})
Promise resolve:
'valueForKey'

Promise reject:
{
  'error_code': 'KEY_NOT_FOUND'
}

Response Parameter

Promise<string>
Promise resolve with the value of the corresponding key or the defaultValue if the key doesn't exist.
Otherwise, Promise reject is called with an appropriate error_code.
Promise failure reasons can be as follows:

Code

Description

KEY_NOT_FOUND

No value found for this key and no default value was provided


setItem

(preferenceName:
Description: This method is used to store a value (string) for the corresponding key (string) into native key-value storage.

Request Parameters

Parameter Name

Type

Description

preferenceName

string

Name of the key-value storage file. A merchant can have multiple key-value storage files for their app

key

string

Name of the key to set the value for

value

string

Value that you would like to set for the key

Response Parameter

void
Usage:

sdk.setItem('app', 'key', 'value')

removeItem

(preferenceName:
Description: This method is used remove a key-value pair from native key-value storage

Request Parameters

Parameter Name

Type

Description

preferenceName

string

Name of the key-value storage file. A merchant can have multiple key-value storage files for their app

key

string

Name of the key whose value needs to be removed

Usage:

sdk.removeItem('app', 'key')