Package: messagemedia-messages-sdk
MessageMedia Messages Python SDKThe MessageMedia Messages API provides a number of endpoints for building powerful two-way messaging applications.Table of ContentsAuthenticationErrorsInformationSlack and Mailing ListBug ReportsContributingInstallationGet StartedAPI DocumentationNeed help?License:closed_lock_with_key: AuthenticationAuthentication is done via API keys. Sign up athttps://developers.messagemedia.com/register/to get your API keys.Requests are authenticated using HTTP Basic Auth or HMAC. For Basic Auth, your API key will be basicAuthUserName and API secret will be basicAuthPassword. For HMAC, your API key will be hmacAuthUserName and API secret will be hmacAuthPassword. This is demonstrated in theSend an SMS examplebelow.:interrobang: ErrorsOur API returns standard HTTP success or error status codes. For errors, we will also include extra information about what went wrong encoded in the response as JSON. The most common status codes are listed below.HTTP Status CodesCodeTitleDescription400Invalid RequestThe request was invalid401UnauthorizedYour API credentials are invalid403Disabled featureFeature not enabled404Not FoundThe resource does not exist50XInternal Server ErrorAn error occurred with our API:newspaper: InformationSlack and Mailing ListIf you have any questions, comments, or concerns, please join our Slack channel:https://developers.messagemedia.com/collaborate/slack/Alternatively you can email us at:developers@messagemedia.comBug reportsIf you discover a problem with the SDK, we would like to know about it. You can raise anissueor send an email to:developers@messagemedia.comContributingWe welcome your thoughts on how we could best provide you with SDKs that would simplify how you consume our services in your application. You can fork and create pull requests for any features you would like to see or raise anissue. Please be aware that a large share of the files are auto-generated by our backend tool.:star: InstallationRun the following command to install the SDK via pip:pip install messagemedia-messages-sdk:clapper: Get StartedIt's easy to get started. Simply enter the API Key and secret you obtained from theMessageMedia Developers Portalinto the code snippet below and a mobile number you wish to send to.Send an SMSDestination (destinationNumber) and source number (sourceNumber) should be in theE.164format. For example,+61491570156NOT0491570156. The code snippet below comprises of only the bare minimum parameters required to send a message. You can view the full list of parameters overhere. Alternatively, you can referthiscode snippet with all the parameters in use.frommessage_media_messages.message_media_messages_clientimportMessageMediaMessagesClientfrommessage_media_messages.models.send_messages_requestimportSendMessagesRequestfrommessage_media_messages.models.messageimportMessagefrommessage_media_messages.models.format_enumimportFormatEnumfrommessage_media_messages.models.source_number_type_enumimportSourceNumberTypeEnumfrommessage_media_messages.models.status_enumimportStatusEnumfrommessage_media_messages.exceptions.send_messages_400_response_exceptionimportSendMessages400ResponseExceptionfrommessage_media_messages.exceptions.api_exceptionimportAPIExceptionimportdateutil.parserimportjsonpickleauth_user_name='API_KEY'auth_password='API_SECRET'use_hmac_authentication=Falseclient=MessageMediaMessagesClient(auth_user_name,auth_password,use_hmac_authentication)messages_controller=client.messagesbody=SendMessagesRequest()body.messages=[]body.messages.append(Message())body.messages[0].content='My first message'body.messages[0].destination_number='+61491570156'try:result=messages_controller.send_messages(body)print(result)exceptSendMessages400ResponseExceptionase:print(e)exceptAPIExceptionase:print(e)Send an MMSDestination (destinationNumber) and source number (sourceNumber) should be in theE.164format. For example,+61491570156NOT0491570156. The code snippet below comprises of only the bare minimum parameters required to send a message. You can view the full list of parameters overhere. Alternatively, you can referthiscode snippet with all the parameters in use.frommessage_media_messages.message_media_messages_clientimportMessageMediaMessagesClientfrommessage_media_messages.models.send_messages_requestimportSendMessagesRequestfrommessage_media_messages.models.messageimportMessagefrommessage_media_messages.models.format_enumimportFormatEnumfrommessage_media_messages.models.source_number_type_enumimportSourceNumberTypeEnumfrommessage_media_messages.models.status_enumimportStatusEnumfrommessage_media_messages.exceptions.send_messages_400_response_exceptionimportSendMessages400ResponseExceptionfrommessage_media_messages.exceptions.api_exceptionimportAPIExceptionimportdateutil.parserimportjsonpickleauth_user_name='API_KEY'auth_password='API_SECRET'use_hmac_authentication=Falseclient=MessageMediaMessagesClient(auth_user_name,auth_password,use_hmac_authentication)messages_controller=client.messagesbody=SendMessagesRequest()body.messages=[]body.messages[0].content='My second message'body.messages[0].destination_number='+61491570158'body.messages[0].format=FormatEnum.MMSbody.messages[0].media=['https://images.pexels.com/photos/1018350/pexels-photo-1018350.jpeg?cs=srgb&dl=architecture-buildings-city-1018350.jpg']body.messages[0].subject='This is an MMS message'try:result=messages_controller.send_messages(body)print(result)exceptSendMessages400ResponseExceptionase:print(e)exceptAPIExceptionase:print(e)Get Status of a MessageYou can get a messsage ID from a sent message by looking at themessage_idfrom the response of the above example.frommessage_media_messages.message_media_messages_clientimportMessageMediaMessagesClientfrommessage_media_messages.exceptions.api_exceptionimportAPIExceptionauth_user_name='API_KEY'auth_password='API_SECRET'use_hmac_authentication=Falseclient=MessageMediaMessagesClient(auth_user_name,auth_password,use_hmac_authentication)messages_controller=client.messagesmessage_id='877c19ef-fa2e-4cec-827a-e1df9b5509f7'try:result=messages_controller.get_message_status(message_id)print(result)exceptAPIExceptionase:print(e)Get replies to a messageYou can check for replies that are sent to your messagesfrommessage_media_messages.message_media_messages_clientimportMessageMediaMessagesClientfrommessage_media_messages.exceptions.api_exceptionimportAPIExceptionauth_user_name='API_KEY'auth_password='API_SECRET'use_hmac_authentication=Falseclient=MessageMediaMessagesClient(auth_user_name,auth_password,use_hmac_authentication)replies_controller=client.repliestry:result=replies_controller.check_replies()print(result)exceptAPIExceptionase:print(e)Check Delivery ReportsThis endpoint allows you to check for delivery reports to inbound and outbound messages.frommessage_media_messages.message_media_messages_clientimportMessageMediaMessagesClientfrommessage_media_messages.exceptions.api_exceptionimportAPIExceptionauth_user_name='API_KEY'auth_password='API_SECRET'use_hmac_authentication=Falseclient=MessageMediaMessagesClient(auth_user_name,auth_password,use_hmac_authentication)delivery_reports_controller=client.delivery_reportstry:result=delivery_reports_controller.check_delivery_reports()print(result)exceptAPIExceptionase:print(e)Confirm Delivery ReportsThis endpoint allows you to mark delivery reports as confirmed so they're no longer returned by the Check Delivery Reports function.frommessage_media_messages.message_media_messages_clientimportMessageMediaMessagesClientfrommessage_media_messages.models.confirm_delivery_reports_as_received_requestimportConfirmDeliveryReportsAsReceivedRequestfrommessage_media_messages.exceptions.api_exceptionimportAPIExceptionauth_user_name='API_KEY'auth_password='API_SECRET'use_hmac_authentication=Falseclient=MessageMediaMessagesClient(auth_user_name,auth_password,use_hmac_authentication)delivery_reports_controller=client.delivery_reportsbody=ConfirmDeliveryReportsAsReceivedRequest()body.delivery_report_ids=['011dcead-6988-4ad6-a1c7-6b6c68ea628d','3487b3fa-6586-4979-a233-2d1b095c7718','ba28e94b-c83d-4759-98e7-ff9c7edb87a1']try:result=delivery_reports_controller.confirm_delivery_reports_as_received(body)print(result)exceptAPIExceptionase:print(e)Check credits remaining (Prepaid accounts only)This endpoint allows you to check for credits remaining on your prepaid account.frommessage_media_messages.message_media_messages_clientimportMessageMediaMessagesClientfrommessage_media_messages.exceptions.api_exceptionimportAPIExceptionauth_user_name='API_KEY'auth_password='API_SECRET'use_hmac_authentication=Falseclient=MessageMediaMessagesClient(auth_user_name,auth_password,use_hmac_authentication)messages_controller=client.messagestry:result=messages_controller.check_credits_remaining()print(result)exceptAPIExceptionase:print(e):closed_book: API Reference DocumentationCheck out thefull API documentationfor more detailed information.:confused: Need help?Please contact developer support atdevelopers@messagemedia.comor check out the developer portal atdevelopers.messagemedia.com:page_with_curl: LicenseApache License. See theLICENSEfile.