cURL Examples for Ordering Numbers and Reading OTP Codes
A curl sms activation api example is the fastest way to test an integration before writing any application code. With two short commands you can order a number, then poll for the incoming code. This tutorial gives the request shapes, the fields that matter and the mistakes that cause failed orders.
Direct answer: Send an authenticated POST to the order endpoint with the service and country, capture the order ID from the response, then send a GET to the status endpoint with that ID. Repeat the GET until the OTP field is filled or the timer expires.
Before You Start
- An OtpGet API key with permission to place orders.
- curl installed on your machine.
- A small wallet balance for test orders.
- The service code and country code you want to test.
Endpoint paths and field names are listed in the OtpGet documentation and should be used exactly as written there.
Step 1: Order a Number
The order request is a POST with your key in the authorization header and a JSON body containing the service, the country and your requested operator if needed. The response returns an order ID and the assigned number.
curl -X POST "https://otpget.com/api/v1/order"
-H "Authorization: Bearer YOUR_API_KEY"
-H "Content-Type: application/json"
-d "{"service":"example_service","country":"1"}"
Save the order ID from the response. You will need it for every follow-up call. The number in the response is the one you paste into the target website.
Step 2: Read the OTP Code
Poll the status endpoint with the order ID. A code that has not arrived yet returns a waiting status. Once the SMS lands, the same call returns the code text.
curl -X GET "https://otpget.com/api/v1/order/YOUR_ORDER_ID"
-H "Authorization: Bearer YOUR_API_KEY"
Poll every few seconds rather than in a tight loop. Aggressive polling adds load and can trigger rate limits. A pause of three to five seconds is enough for most services.
Step 3: Cancel or Finish
If no code arrives before the reservation ends, cancel the order so the held amount returns to your wallet. A cancel call uses the same order ID. If the code has arrived, there is nothing more to do; the order completes on its own.
| Call | Method | Purpose |
|---|---|---|
| Order | POST | Reserve a number and get an order ID |
| Status | GET | Read the OTP or current state |
| Cancel | POST | Release the number and refund the hold |
Common cURL Mistakes
The first is quoting. On Windows, single quotes around the JSON body behave differently than in Linux shells, so use the documented escaping for your operating system. The second is a missing content type header, which makes the server treat the body as form data. The third is printing the API key in shared logs. Redirect output to a local file and remove sensitive lines before sharing. The fourth is assuming the code field is always present; check the status field first.
Turning the Example Into a Script
- Wrap the order call in a function that returns the order ID.
- Add a loop that calls the status endpoint with a short sleep.
- Break the loop when the status shows a code received.
- Add a timeout that cancels the order after the reservation window.
- Log results without the key or the full code.
This pattern works in bash, Python or any language with an HTTP client. Start from the curl version, then port it. You can generate a key at OtpGet registration and test against a cheap country first.
Frequently Asked Questions
How often should I poll for the code?
Every three to five seconds is enough. Faster polling rarely helps and may be rate limited.
What does a waiting status mean?
The number is reserved but no SMS has arrived yet. Keep the order open until the timer ends.
Can I reuse an order ID?
No. Each order ID refers to one reservation. Start a new order for a new number.
Why does my curl call return an authorization error?
Check that the key is correct, active and sent in the header exactly as documented.
Can I test the API without spending money?
Test orders cost the normal price, so keep a small balance and use the cheapest available country for practice.
Conclusion
This curl sms activation api example covers the full loop: order, poll, then cancel or finish. Copy the commands, replace the key and service, and you have a working integration in minutes. Read the OtpGet API docs for every endpoint, and find more scripts on the OtpGet blog.
Related reading: API tutorials on the OtpGet blog.