Code examples
Run direct HTTP examples in eight popular languages and tools.
Every Activation V2 method has examples for cURL, JavaScript, TypeScript, Python, PHP, Go, C# and Java. They use the documented HTTP method and the apikey header. You can run each example on its own; no SMSPVA SDK is needed.
Requirements
| Example | Environment | Run |
|---|---|---|
| cURL | cURL 7.76+; macOS, Linux or WSL shell | Paste into a POSIX shell |
| JavaScript | Node.js 22.16+ | Save as Example.mjs; node Example.mjs |
| TypeScript | TypeScript in a Node.js ESM project | Save as Example.mts; compile with NodeNext/ES2022 and Node types, or run using your TS runner |
| Python | Python 3.10+; standard library | python Example.py |
| PHP | PHP 8.1+ and ext-curl | php Example.php |
| Go | Go 1.20+; standard library | go run Example.go |
| C# | .NET 8+ console project | Put the example in Program.cs; dotnet run |
| Java | JDK 11+; standard library | Save as Example.java; java Example.java |
No third-party HTTP library is required. Java prints raw JSON because its standard library has no JSON parser; use your application's existing JSON library to inspect fields. Other language examples parse JSON and check the response. JavaScript and TypeScript examples are server-side Node.js code, not browser code.
Environment variables
Keep your API key out of source files:
# macOS / Linux / WSL
export SMSPVA_API_KEY="YOUR_API_KEY"# PowerShell
$env:SMSPVA_API_KEY = "YOUR_API_KEY"For order methods, set SMSPVA_ORDER_ID to the orderId returned by Get number or Current orders. For Number status, set SMSPVA_NUMBER to your previously used number without its country phone code.
# PowerShell example
$env:SMSPVA_ORDER_ID = "123456" # Replace with your actual order IDCountry, service and operator examples use illustrative defaults from the original documentation. You can change the code or set SMSPVA_COUNTRY, SMSPVA_SERVICE and SMSPVA_OPERATOR. Use the reference lists and operators method for actual identifiers. The cURL examples show literal country/service/operator codes; edit those directly.
Message type and partner key
Where supported, examples explicitly use voice=0 (SMS). Change it to 1 for caller-ID or 2 for voice calls, after checking message type settings. Do not add voice to methods that do not document it.
Receive SMS also documents an optional partnerkey header. Add it alongside apikey if you use referral accounting; it is applied when SMS is received successfully.
Responses and retries
Examples set a 30-second client timeout. They do not automatically retry. On Receive SMS, 202 / SMS_NOT_YET_RECEIVED is handled before generic errors. The cURL example prints the response body; the Java example preserves raw JSON for your application to parse.
Use the polling guide for repeated waiting requests. A network failure on an order-changing method leaves the result uncertain: inspect current orders before repeating a number request.