How to List Porting Records

Warning: Beta software This API is in beta stage and may be subject to change. Therefore, we do not recommend using this in production.

Interested in this feature? Please reach out to mobility-services-developer@cisco.com

ListPortingRecords is a method that allows you to list porting records by using one or more of the following filters: subscriber number prefix, operator code or valid from.

This method is part of the Number Portability API.

Prerequisites

  1. An OAuth 2.0 client
  2. A client access token

Required Scope

  • number_portability.porting_record:read

Code Dependencies

<dependency>
  <groupId>com.wgtwo.api.v0.grpc</groupId>
  <artifactId>number_portability</artifactId>
  <version>0.3.0</version>
</dependency>

Code

If targeting production, you would need to add authentication to the sample code.


#!/usr/bin/env bash
grpcurl \
  -d '
  {
      "subscriberNumberPrefix": "+467123",
      "operatorCode": "A21",
      "validFrom": "2020-01-01T00:00:00Z"
  }
  ' \
  sandbox.api.shamrock.wgtwo.com:443 \
  wgtwo.number_portability.v0.NumberPortabilityService/ListPortingRecords

package com.example.numberPortability

import com.google.protobuf.Timestamp
import com.wgtwo.api.v0.number_portability.NumberPortabilityServiceGrpcKt
import com.wgtwo.api.v0.number_portability.listPortingRecordsRequest
import io.grpc.ManagedChannelBuilder
import io.grpc.Status
import io.grpc.StatusException
import kotlinx.coroutines.runBlocking

private val channel = ManagedChannelBuilder.forTarget("sandbox.api.shamrock.wgtwo.com:443").build()
private val stub = NumberPortabilityServiceGrpcKt.NumberPortabilityServiceCoroutineStub(channel)

fun main() = runBlocking {
    val listPortingRecordsRequest = listPortingRecordsRequest {
        subscriberNumberPrefix = "+467000"
        validFrom = Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000).build()
    }
    println("listPortingRecordsRequest:
$listPortingRecordsRequest")

    val listPortingRecordsResponse = stub.listPortingRecords(listPortingRecordsRequest)
    println("listPortingRecordsResponse:
$listPortingRecordsResponse")

    val listPortingRecordsRequestWithInvalidSubscriberNumberPrefix = listPortingRecordsRequest {
        subscriberNumberPrefix = "invalid"
    }

    val errorResponse = runCatching {
        stub.listPortingRecords(listPortingRecordsRequestWithInvalidSubscriberNumberPrefix)
    }

    assert(errorResponse.isFailure) { "result is not a failure" }
    assert((errorResponse.exceptionOrNull() as? StatusException)?.status?.code == Status.INVALID_ARGUMENT.code) {
        "exception is not a StatusException with INVALID_ARGUMENT status code: ${errorResponse.exceptionOrNull()}"
    }
    println("Status code: ${(errorResponse.exceptionOrNull() as StatusException).status.code}")
    println("Status description: ${(errorResponse.exceptionOrNull() as StatusException).status.description}")
}

Example Results Success

{
  "records": [
    {
      "subscriberNumber": "+46712345678",
      "operatorCode": "A21",
      "validFrom": "2024-04-01T00:00:00Z",
      "metadata": {
        "test_key": "test_value"
      }
    }
  ]
}
records {
  subscriber_number {
    e164: "+46714991322"
  }
  operator_code: "A24"
  routing_code: "039"
  valid_from {
    seconds: 1712570280
    nanos: 209405000
  }
  metadata {
    key: "test_key"
    value: "test_val_2096299844"
  }
}
records {
  subscriber_number {
    e164: "+46703322254"
  }
  operator_code: "C45"
  routing_code: "021"
  valid_from {
    seconds: 1712566680
    nanos: 218947000
  }
  metadata {
    key: "test_key1"
    value: "test_value"
  }
  metadata {
    key: "test_key2"
    value: "test_value2"
  }
}

Example Results Error

ERROR:
  Code: InvalidArgument
  Message: Invalid subscriber number prefix
Status code: INVALID_ARGUMENT
Status description: Invalid subscriber number

Read More