How to Create Number Block
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
CreateOrUpdateNumberBlock
is a method that allows you to create or update a number block.
This method is part of the Number Portability API and belongs to the NumberBlockService
.
Prerequisites
Required Scope
No scope is required to create number blocks, but number portability lookups will only work with products having the number_portability:provide
scope.
Code Dependencies
curl -sL https://github.com/working-group-two/wgtwoapis/releases/latest/download/mobility.binpb --output mobility.binpb
<dependency>
<groupId>com.wgtwo.api.v1.grpc</groupId>
<artifactId>number_portability</artifactId>
<version>1.10.1</version>
</dependency>
Code
The examples below demonstrate how to use the CreateOrUpdateNumberBlock
function.
You can test our APIs without authorization by targeting
sandbox.api.shamrock.wgtwo.com
instead ofapi.{region}.wgtwo.com
and removing any authorization from the request/code sample.
#!/usr/bin/env bash
grpcurl \
--protoset mobility.binpb \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '
{
"block": {
"destinationId": "64f14bd8-c49b-4dd0-b30d-5780861f8324",
"prefix": "2345",
"status": "A_ALLOCATED",
"assignmentDate": "2024-02-01T16:50:15Z"
}
}
' \
sandbox.api.shamrock.wgtwo.com:443 \
wgtwo.number_portability.v1.NumberBlockService/CreateOrUpdateNumberBlock
package com.example.numberPortability
import com.google.protobuf.util.Timestamps
import com.wgtwo.api.v1.number_portability.NumberBlockServiceGrpcKt
import com.wgtwo.api.v1.number_portability.NumberBlockStatus
import com.wgtwo.api.v1.number_portability.createOrUpdateNumberBlockRequest
import com.wgtwo.api.v1.number_portability.numberBlock
import io.grpc.ManagedChannelBuilder
import io.grpc.Status
import io.grpc.StatusException
import kotlinx.coroutines.runBlocking
import java.util.Date
import java.util.UUID.randomUUID
import kotlin.test.assertFailsWith
private val channel = ManagedChannelBuilder.forAddress("sandbox.api.shamrock.wgtwo.com", 443).build()
private val stub = NumberBlockServiceGrpcKt.NumberBlockServiceCoroutineStub(channel)
fun main() = runBlocking {
val createOrUpdateNumberBlockRequest = createOrUpdateNumberBlockRequest {
block = numberBlock {
destinationId = "64f14bd8-c49b-4dd0-b30d-5780861f8324"
prefix = "2345"
status = NumberBlockStatus.A_ALLOCATED
assignmentDate = Timestamps.fromDate(Date())
}
}
println("createOrUpdateNumberBlockRequest:
$createOrUpdateNumberBlockRequest")
val createOrUpdateNumberBlockResponse = stub.createOrUpdateNumberBlock(createOrUpdateNumberBlockRequest)
println("createOrUpdateNumberBlockResponse:
$createOrUpdateNumberBlockResponse")
val createOrUpdateNumberBlockRequestWithoutPrefix = createOrUpdateNumberBlockRequest {
block = numberBlock {
destinationId = randomUUID().toString()
status = NumberBlockStatus.A_ALLOCATED
assignmentDate = Timestamps.parse("2021-06-01T00:00:00.000Z")
}
}
println("createOrUpdateNumberBlockRequestWithoutPrefix:
$createOrUpdateNumberBlockRequestWithoutPrefix")
val exception = assertFailsWith<StatusException>("exception is not a StatusException") {
stub.createOrUpdateNumberBlock(createOrUpdateNumberBlockRequestWithoutPrefix)
}
assert(exception.status.code == Status.INVALID_ARGUMENT.code) {
"status code is not INVALID_ARGUMENT: ${exception.status.code}"
}
}
Example Results Success
{}
Example Results Error
ERROR:
Code: InvalidArgument
Message: Missing prefix
Status code: INVALID_ARGUMENT
Status description: Missing prefix