Skip to main content
Version: Python

SIM Swap Reference

The SIM Swap client is scoped to a single phone number, so in-order to interact with the SIM Swap service, you need to create a SimSwapUserClient instance for the phone number you want to check.

SimSwapUserClients are creating using the SimSwapClient accessible from the GlideClient instance.

SimSwapClient Reference

Methods

1. forUser

Description: forUser creates a SimSwapUserClient instance for the specified phone number.

Syntax:

def for_user(identifier : UserIdentifier) -> SimSwapUserClient:

Parameters:

ParameterTypeDescription
identifierUserIdentifierAn object representing a user (can be a phonenumber, ip address or custom user id)

UserIdentifier Properties:

PropertyTypeDescription
phoneNumberstringThe phone number of the user.
ipAddressnumberThe IP address of the user.
userIdstringA custom user identifier.

Only one of the properties should be provided.

Returns:

  • SimSwapUserClient: A client instance for the specified user.

Example:

from glide import GlideClient

def main():
glide = GlideClient()
sim_swap_user_client = glide.sim_swap.for_user({
"phoneNumber": "+555123456789"
})

if __name__ == "__main__":
main()

SimSwapUserClient Reference

The SimSwapUserClient is used to interact with the SIM Swap service for a specific phone number.

Properties

1. requiresConsent

A boolean indicating if the user needs to provide consent before checking for a SIM swap. If this is true then you need to call getConsentUrl to get the consent URL and ask the user to provide consent before calling check or retrieveDate.

Methods

1. check

Description: check verifies if a SIM swap has occurred for the user's phone number.

Syntax:

def check(checkParams: SimSwapCheckParams = {}, config: ApiConfig = {}) -> SimSwapCheckResponse:

Parameters:

ParameterTypeDescription
checkParamsSimSwapCheckParamsAn object containing the check parameters.

SimSwapCheckParams Properties:

PropertyTypeDescription
phoneNumberstringOptional - The phone number to check for a SIM swap.
maxAgenumberOptional - Maximum age of the SIM swap in hours.

If phoneNumber was provied in the forUser method as the user identifier, it can be omitted here.

Returns:

  • SimSwapCheckResponse: An object containing the SIM swap status.

SimSwapCheckResponse Properties:

PropertyTypeDescription
swappedbooleanIndicates if a SIM swap has occurred up to maxAge hours ago

Example:

from glide import GlideClient

def main():
glide = GlideClient()
sim_swap_user_client = glide.sim_swap.for_user({
"phoneNumber": "+555123456789"
})

sim_swap_check_response = sim_swap_user_client.check()
print(sim_swap_check_response)
# Output: { "swapped": True }

if __name__ == "__main__":
main()

2. retrieveDate

Description: retrieveDate retrieves the date of the last SIM swap for the user's phone number.

Syntax:

def retrieve_date(params: SimSwapRetrieveDateParams = {}, config: ApiConfig = {}) -> SimSwapRetrieveDateResponse:

Parameters:

ParameterTypeDescription
paramsSimSwapRetrieveDateParamsAn object containing the retrieve date parameters.

SimSwapRetrieveDateParams Properties:

PropertyTypeDescription
phoneNumberstringOptional - The phone number to check for a SIM swap.

Returns:

  • SimSwapRetrieveDateResponse: An object containing the date of the last SIM swap.

SimSwapRetrieveDateResponse Properties:

PropertyTypeDescription
latestSimChangestringThe date of the last SIM swap in ISO 8601 format.

Example:

from glide import GlideClient

def main():
glide = GlideClient()
sim_swap_user_client = glide.sim_swap.for_user({
"phoneNumber": "+555123456789"
})

sim_swap_date_response = sim_swap_user_client.retrieve_date()
print(sim_swap_date_response)
# Output: { "latestSimChange": "2022-01-01T00:00:00Z" }

if __name__ == "__main__":
main()

3. getConsentUrl

Description: getConsentUrl retrieves the URL for the user to provide consent before checking for a SIM swap.

Syntax:

def get_consent_url() -> str:

Returns:

  • string: The URL for the user to provide consent.

Example:


from glide import GlideClient

def main():
glide = GlideClient()
sim_swap_user_client = glide.sim_swap.for_user({
"phoneNumber": "+555123456789"
})

if sim_swap_user_client.requires_consent:
consent_url = sim_swap_user_client.get_consent_url()
print(consent_url)

if __name__ == "__main__":
main()

4. pollAndWaitForSession

Description: pollAndWaitForSession polls the SIM Swap service until the user has provided consent and a session is available. This method should be called after you have retrieved the consent URL and passed it to the user.

Syntax:

def poll_and_wait_for_session() -> None:

Returns:

  • void

Example:


from glide import GlideClient

def main():
glide = GlideClient()
sim_swap_user_client = glide.sim_swap.for_user({
"phoneNumber": "+555123456789"
})

if sim_swap_user_client.requires_consent:
consent_url = sim_swap_user_client.get_consent_url()
print(consent_url)
sim_swap_user_client.poll_and_wait_for_session()
# Now you can call check or retrieveDate

if __name__ == "__main__":
main()

Error Handling

Each method in ExampleService can throw errors under certain conditions. Developers should handle these exceptions as part of their implementation. Common errors include:

  • InvalidInputError: Thrown when input parameters do not meet the required format or type.
  • OperationFailedError: Thrown when an operation cannot be completed successfully due to various issues, such as network problems or service unavailability.

Type Definitions

ApiConfig

This object can be sent to most service apis to override the default configuration like the access token used in the request.

Properties

PropertyTypeDescription
sessionSessionAn optional session object for authentication and authorization.

Session

This object represents a user session with an access token, expiration time, and associated scopes.

Properties

PropertyTypeDescription
accessTokenstringThe access token for the session.
expiresAtnumberThe expiration time of the session.
scopesstring[]An array of scopes associated with the session.