import json import requests from typing import Optional, Dict, Any def post_order_sms( bearer_token: str, country: str, service: int, quantity: int = 1, max_price: Optional[float] = None, pricing_option: Optional[int] = None, areacode: [int] = [], exclude: bool = False, pool: Optional[str] = None, create_token: bool = False ) -> Dict[str, Any]: """ Sends a POST request to order SMS numbers from SMSPool API. :param bearer_token: The Bearer Token for authorization. :param country: The country in ISO format or number retrieved from the Country List endpoint. :param service: The service or number retrieved from the Service List endpoint. :param max_price: The max price you are willing to pay per number. :param pricing_option: Set to 0 for the cheapest numbers, set to 1 for the highest success rate. :param quantity: Quantity of numbers ordered. :param areacode: Areacodes you would like to include or exclude in JSON format. :param exclude: Set to 1 if you would like to exclude all listed area codes. :param pool: (Optional) The pool or number retrieved from the Pool List endpoint. :param create_token: (Optional) Set to 1 if you'd like to create a token link that anyone can access. :return: A dictionary containing the API response. if successful: ['success'] will be 1, and ['number'] will be the phone number. ['cc'] is the country code. Use ['order_id'] for any further checking """ url = "https://api.smspool.net/purchase/sms" headers = { 'Authorization': f'Bearer {bearer_token}' } areacode = json.dumps(areacode) exclude = 1 if exclude else 0 create_token = 1 if create_token else 0 payload = { 'country': country, 'service': service, 'quantity': quantity, 'areacode': areacode, 'exclude': exclude } # Add optional parameters if they are provided if pool is not None: payload['pool'] = pool if create_token is not None: payload['create_token'] = create_token if max_price is not None: payload['max_price'] = max_price if pricing_option is not None: payload['pricing_option'] = pricing_option response = requests.post(url, headers=headers, data=payload) # Check if the request was successful if response.status_code == 200: return response.json() else: return { 'success': 0, 'message': f'Failed to order SMS: {response.status_code} {response.text}' } import requests from typing import Dict, Any def check_sms_status( bearer_token: str, order_id: str, ) -> Dict[str, Any]: """ Checks the status of an SMS order using the SMSPool API. :param bearer_token: The Bearer Token for authorization. :param order_id: The order ID of the SMS order to check. :return: A dictionary containing the API response. The response will vary depending on the status of the order: - Order pending: Status code 1, with time left until expiration. - Order refunded: Status code 6, indicating the order has been refunded. - Order complete: Status code 3, including the SMS code and its full text. if order complete: ['sms'] key will contain number """ url = "https://api.smspool.net/sms/check" headers = { 'Authorization': f'Bearer {bearer_token}' } payload = { 'orderid': order_id, } response = requests.post(url, headers=headers, data=payload) # Check if the request was successful if response.status_code == 200: return response.json() else: return { 'success': 0, 'message': f'Failed to check SMS status: {response.status_code} {response.text}' }