How to create porting records
WARNING
This API is in alpha and may be subject to change. Therefore, we do not recommend using this in production.
Interested in this feature? Please reach out to products@wgtwo.com
CreatePortingRecords
is a method that allows you to create one or more porting record for specific subscriber numbers. This method is part of the Number Portability API.
Example code
The examples below demonstrate how to use the CreatePortingRecords
function.
TIP
You can test our APIs without authorization by targetting sandbox.api.wgtwo.com
instead of api.wgtwo.com
and removing any authorization from the request/code sample.
Download proto definitions
curl -sL 'https://github.com/working-group-two/wgtwoapis/blob/master/image.bin?raw=true' -o wgtwo.bin
1
#!/usr/bin/env bash
export ACCESS_TOKEN="my_access_token"
grpcurl -protoset wgtwo.bin \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '
{
"records": [
{
"subscriberNumber": {
"e164": "+46712345678"
},
"operatorCode": "A21",
"routingCode": "006",
"validFrom": "2024-04-01T00:00:00Z",
"metadata": {
"test_key": "test_value"
}
}
]
}
' \
api.wgtwo.com:443 \
wgtwo.number_portability.v0.NumberPortabilityService/CreatePortingRecords
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Example result
Success
{
}
1
2
3
2
3
Error
ERROR:
Code: InvalidArgument
Message: Invalid subscriber number
1
2
3
2
3
Install dependencies
Maven
<dependency>
<groupId>com.wgtwo.api.v0.grpc</groupId>
<artifactId>number_portability</artifactId>
<version>0.3.0</version>
</dependency>
package com.example.numberPortability
import com.google.protobuf.Timestamp
import com.wgtwo.api.v0.number_portability.NumberPortabilityServiceGrpcKt
import com.wgtwo.api.v0.number_portability.createPortingRecordsRequest
import com.wgtwo.api.v0.number_portability.portingRecord
import com.wgtwo.api.v1.common.e164
import com.wgtwo.auth.BearerTokenCallCredentials
import io.grpc.ManagedChannelBuilder
import io.grpc.Status
import io.grpc.StatusException
import kotlinx.coroutines.runBlocking
private enum class EnvironmentForCreatePortingRecordsExample {
SANDBOX,
PRODUCTION,
}
/** Use the sandbox environment for testing without authentication */
private val environment = EnvironmentForCreatePortingRecordsExample.SANDBOX
private val endpoint = when (environment) {
EnvironmentForCreatePortingRecordsExample.SANDBOX -> "sandbox.api.wgtwo.com"
EnvironmentForCreatePortingRecordsExample.PRODUCTION -> "api.wgtwo.com"
}
private val channel = ManagedChannelBuilder.forAddress(endpoint, 443).build()
private val stub = NumberPortabilityServiceGrpcKt.NumberPortabilityServiceCoroutineStub(channel).run {
/**
* If you are not using the sandbox, you need to add credentials.
* The BearerTokenCallCredentials class can be found in our auth library.
*/
if (environment == EnvironmentForCreatePortingRecordsExample.PRODUCTION) {
withCallCredentials(BearerTokenCallCredentials { "MY_CLIENT_ACCESS_TOKEN" })
} else {
this
}
}
fun main() = runBlocking {
val createPortingRecordsRequest = createPortingRecordsRequest {
records += listOf(
portingRecord {
subscriberNumber = e164 { e164 = "+46700000001" }
validFrom = Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000).build()
operatorCode = "A21"
routingCode = "010"
metadata.put("test_key", "test_value")
},
portingRecord {
subscriberNumber = e164 { e164 = "+46700000002" }
validFrom = Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000).build()
operatorCode = "C39"
routingCode = "005"
metadata.putAll(mapOf("test_key1" to "test_value", "test_key2" to "test_value2"))
},
)
}
println("createPortingRecordsRequest:\n$createPortingRecordsRequest")
val createPortingRecordsResponse = stub.createPortingRecords(createPortingRecordsRequest)
println("createPortingRecordsResponse:\n$createPortingRecordsResponse")
val createPortingRecordsRequestWithInvalidSubscriberNumber = createPortingRecordsRequest {
records += listOf(
portingRecord {
subscriberNumber = e164 { e164 = "invalid" }
validFrom = Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000).build()
operatorCode = "A21"
routingCode = "010"
},
)
}
val errorResponse = runCatching {
stub.createPortingRecords(createPortingRecordsRequestWithInvalidSubscriberNumber)
}
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}")
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Example result
Success
Error
Status code: INVALID_ARGUMENT
Status description: Invalid subscriber number
1
2
2