Create otp code
Creates a new otp code
HTTP Request
POST/api/notifications/otp/
NOTE: NOT USING THE TRAILING SLASH AT THE END OF THE URL RESULTS TO A 500 SERVER ERROR
Authorization
Authorization
- Required: Yes
- Permission: Staff with OTPPermission or Admin
- Permission Code: 2851
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| code | Integer | Yes | The otp code |
| mobile_number | String | No | The mobile number related to the otp code (valid iranian mobile number) |
| String | No | The email address related to the otp code (valid email format) | |
| valid_to | String(Datetime) | No | The expiration datetime of the otp code (default: calculated from the settings) |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Create a new otp code
4response = requests.post('http://www.example.com/api/notifications/otp',
5 json={
6 "code": 255315,
7 "mobile_number": "09123256545",
8 "email": null,
9 "valid_to": "2025-12-30T14:39:10.268800Z"
10 },
11 headers={'Authorization': 'Token <your_api_key>'}
12)
13print(response.json())1# Create a new otp code
2curl -X POST "http://www.example.com/api/notifications/otp" \
3-H "Authorization: Token <your_api_key>" \
4-H "Content-Type: application/json" \
5-d '{
6 "code": 255315,
7 "mobile_number": "09123256545",
8 "email": null,
9 "valid_to": "2025-12-30T14:39:10.268800Z"
10}'Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the otp code. |
| code | Integer | The otp code |
| mobile_number | String | The related mobile number (nullable, valid iranian mobile number) |
| String | The related email address (nullable, valid email format) | |
| recipient | String | The receiver of the otp code (either email or mobile number, calculated field) |
| valid_to | String (ISO 8601) | Timestamp when the otp code will be expired. |
| ttl | Integer | The duration in seconds which the otp code will be valid (calculated field) |
| is_allow | Boolean | Whether the otp code is still valid and usable or not (calculated field) |
| created_at | String (ISO 8601) | Timestamp when the otp code was created. |
| updated_at | String (ISO 8601) | Timestamp when the otp code was last updated. |
Example Response
{
"id": 66,
"code": 255315,
"mobile_number": "09123256545",
"email": null,
"recipient": "09123256545",
"valid_to": "2025-12-29T14:48:02.776780Z",
"ttl": 119,
"is_allow": true,
"created_at": "2025-12-29T14:46:02.777862Z",
"updated_at": "2025-12-29T14:46:02.777866Z"
}
NOTES
- Either one field from
mobile_numberoremailshould be provided (only one) - if
valid_tois not provided, it will be calculated from the otp expiration time of the project valid_tocan not be explicitely set tonullrecipient,ttl,is_alloware calculated fields