How can I receive OTP via API?

Hi, im very new to all of this, i might not be familiar with terminology.

I know the url to make an API call to get a phone number:
it goes something like this:
https://api.sms-man.com/control/get-number?token=$token&country_id=$country_id&application_id=$application_id

The response from it looks like so:

{
“request_id”: 123456789,
“number”: “79123456789”,
“country_id”: 1,
“application_id”: 123,
“status”: “success”
}

To receive the OTP, you need to call a second endpoint.

The get-number API only gives you a virtual phone number along with a request_id.
After that, you need to poll the get-sms API using that request_id until it returns sms_code (that value is your OTP).

You can refer to the official SMS‑MAN API documentation here:

Please refer this document of sms-man https://sms-man.com/api

So in simple terms, you need to follow these 3 steps:

  1. Call get-number using WS.sendRequest()
    You have already completed this step. what i see

  2. Parse the response JSON and extract request_id
    This request_id is required to fetch the OTP.

  3. Use a loop with a small delay and call get-sms
    Keep calling get-sms with the same request_id until the response contains sms_code.
    Once sms_code appears, that is the OTP you’re looking for.

SMS-Man OTP flow: Get number → Poll /get-sms with request_id until sms_code appears.

Katalon Script

1. Create Object Repository > New > REST Request: GET_NUMBER
   URL: https://api.sms-man.com/control/get-number?token=${token}&country_id=${country_id}&application_id=${app_id}

2. Custom Keyword (Helpers/OTPReceiver.groovy):
@Keyword
String getOTP(String token, int countryId, int appId) {
    // Step 1: Get number
    def getNumReq = findTestObject('GET_NUMBER')
    getNumReq.setRestUrl("https://api.sms-man.com/control/get-number?token=${token}&country_id=${countryId}&application_id=${appId}")
    def numResp = WS.sendRequest(getNumReq)
    def jsonNum = new groovy.json.JsonSlurper().parseText(numResp.getResponseText())
    int reqId = jsonNum.request_id
    String phone = jsonNum.number  // Use in your app
    
    // Step 2: Poll SMS (max 60s)
    def getSmsReq = findTestObject('GET_SMS')  // Similar REST obj
    for(int i=0; i<30; i++) {  // 30x2s = 60s
        getSmsReq.setRestUrl("https://api.sms-man.com/control/get-sms?token=${token}&request_id=${reqId}")
        def smsResp = WS.sendRequest(getSmsReq)
        def jsonSms = new groovy.json.JsonSlurper().parseText(smsResp.getResponseText())
        if(jsonSms.sms_code) return jsonSms.sms_code  // OTP!
        WebUI.delay(2)
    }
    throw new Exception('OTP timeout')
}

Usage: String otp = CustomKeywords.OTPReceiver.getOTP('your_token', 1, 123)

Hmm this will work

hi @jamyseo8

The get-number endpoint only gives you the virtual phone number. You still need to trigger the OTP in your application using that number, then poll the get-sms endpoint with the request_id until the sms_code field is populated.

def json = new groovy.json.JsonSlurper().parseText(response.getResponseText())
int requestId = json.request_id

// Poll for SMS (adjust iterations/delay as needed)
for (int i = 0; i < 30; i++) {
    def smsResp = WS.sendRequest(findTestObject('GET_SMS', ['request_id': requestId, 'token': token]))
    def smsJson = new groovy.json.JsonSlurper().parseText(smsResp.getResponseText())
    if (smsJson.sms_code) {
        println "OTP: ${smsJson.sms_code}"
        break
    }
    WebUI.delay(2)
}

Make sure you actually submit the phone number to your app’s login or registration flow before you start polling, otherwise no SMS will arrive. The get-sms endpoint documentation is at sms-man.com/api.

@jamyseo8 did you try any of the above mentioned ?

@jamyse08 whether you tried any of the solution users have provided?

Check if the SMS is sorted in a database, fetch from there

Let us know your working solution

From what I’ve seen, you usually can’t directly ‘receive’ OTP via API unless the service itself exposes it (which most don’t for security reasons). A common workaround is to use a test environment or mock API where the OTP is returned in the response, or fetch it from email/SMS using a separate API (like mailbox or SMS gateway). In Katalon Studio you can then chain those calls and pass the OTP dynamically into your test. That approach worked for me.

Okay so your issue got resolved?