Git Product home page Git Product logo

infobip-api-python-client's Introduction

Infobip API Python Client

Pypi index MIT License

This is a Python package for Infobip API and you can use it as a dependency to add Infobip APIs to your application. To use the package you'll need an Infobip account. If you don't already have one, you can create a free trial account here.

We use OpenAPI Generator to generate the package code from the OpenAPI specification.

Infobip

Table of contents:

API documentation

Infobip API Documentation can be found here.

General Info

For infobip-api-python-client versioning we use Semantic Versioning scheme.

Published under MIT License.

Python 3.6 is minimum supported version by this library.

Installation

Pull the library by using the following command:

pip install infobip-api-python-client

Quickstart

Before initializing the client first thing you need to do is to set configuration and authentication.

Configuration

Let's first set the configuration. For that you will need your specific URL. To see your base URL, log in to the Infobip API Resource hub with your Infobip credentials.

    from infobip_api_client.api_client import ApiClient, Configuration
    
    client_config = Configuration(
        host="<YOUR_BASE_URL>",
        api_key={"APIKeyHeader": "<YOUR_API_KEY>"},
        api_key_prefix={"APIKeyHeader": "<YOUR_API_PREFIX>"},
    )

Initialize the Client

With configuration set up you can initialize the API client.

	api_client = ApiClient(client_config)

Now you are ready use the API.

Send an SMS

Here's a basic example of sending the SMS message.

    sms_request = SmsAdvancedTextualRequest(
        messages=[
            SmsTextualMessage(
                destinations=[
                    SmsDestination(
                        to="41793026727",
                    ),
                ],
                _from="InfoSMS",
                text="This is a dummy SMS message sent using Python library",
            )
        ])
        
    api_instance = SendSmsApi(api_client)

    api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_textual_request=sms_request)
    pprint(api_response)

To make your code more robust send the message in try block and handle the ApiException in catch block.

    from infobip_api_client.exceptions import ApiException
    
    try:
        api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_textual_request=sms_request)
    except ApiException as ex:
        print("Error occurred while trying to send SMS message.")

In case of failure you can inspect the ApiException for more information.

    try:
        api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_binary_request=sms_advanced_binary_request)
    except ApiException as ex:
        print("Error occurred while trying to send SMS message.")
        print("Error status: %s\n" % ex.status)
        print("Error headers: %s\n" % ex.headers)
        print("Error body: %s\n" % ex.body)

Additionally, from the successful response (SmsResponse object) you can pull out the bulk_id and message_id(s) and use them to fetch a delivery report for given message or bulk. Bulk ID will be received only when you send a message to more than one destination address or multiple messages in a single request.

    bulk_id = api_response.bulk_id
    message_id = api_response.messages[0].message_id

Receive sent SMS report

For each SMS that you send out, we can send you a message delivery report in real time. All you need to do is specify your endpoint when sending SMS in notify_url field of SmsTextualMessage, or subscribe for reports by contacting our support team. e.g. https://{yourDomain}/delivery-reports

Example of webhook implementation using Flask:

    @app.route("/api/delivery-reports", methods=["POST"])
    def delivery_report():
        delivery_result = SmsDeliveryResult(
            results=request.json["results"]
        )
        
        for result in delivery_results.results:
            print("message {0} sent at {1}".format(result.message_id, result.sent_at))

If you prefer to use your own serializer, please pay attention to the supported date format.

Fetching delivery reports

If you are for any reason unable to receive real time delivery reports on your endpoint, you can use message_id or bulk_id to fetch them. Each request will return a batch of delivery reports. Please be aware that these can be retrieved only once.

    api_response = api_instance.get_outbound_sms_message_delivery_reports(bulk_id=bulk_id, message_id=message_id, limit=2)
    print(api_response)

Unicode & SMS preview

Infobip API supports Unicode characters and automatically detects encoding. Unicode and non-standard GSM characters use additional space, avoid unpleasant surprises and check how different message configurations will affect your message text, number of characters and message parts.

    sms_preview_request = SmsPreviewRequest(
        text="Let's see how many characters will remain unused in this message."
    )
    
    api_response = api_instance.preview_sms_message(sms_preview_request=sms_preview_request)

Receive incoming SMS

If you want to receive SMS messages from your subscribers we can have them delivered to you in real time. When you buy and configure a number capable of receiving SMS, specify your endpoint as explained here. e.g. https://{yourDomain}/incoming-sms.

Example of webhook implementation using Flask:

    @app.route("/api/incoming-sms", methods=["POST"])
    def incoming_sms():
        message_results = SmsInboundMessageResult(
            message_count=request.json["message_count"],
            pending_message_count=request.json["pending_message_count"],
            results=request.json["results"]
        )
        
        for result in message_results.results:
            print("message text: {0}".format(result.clean_text))
        

Two-Factor Authentication (2FA)

For 2FA quick start guide please check these examples.

Ask for help

Feel free to open issues on the repository for any issue or feature request. As per pull requests, for details check the CONTRIBUTING file related to it - in short, we will not merge any pull requests, this code is auto-generated.

If it's something that requires our imminent attention feel free to contact us @ [email protected].

infobip-api-python-client's People

Contributors

cesljasdavor avatar dario-ib avatar hkozacinski-ib avatar maricn avatar nmenkovic-ib avatar pducic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

infobip-api-python-client's Issues

The client is broken- Unable to Install

When i run
pip install

I got this response

Collecting infobip-api-python-client
  Using cached infobip-api-python-client-2.2.0.tar.gz (32 kB)
Collecting enum
  Using cached enum-0.4.7.tar.gz (20 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/saviourgidi/projects/python_extensive/total/total/env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/vf/rl30wcj92_g723bs9nskxns80000gn/T/pip-install-qduaoqvr/enum/setup.py'"'"'; __file__='"'"'/private/var/folders/vf/rl30wcj92_g723bs9nskxns80000gn/T/pip-install-qduaoqvr/enum/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/vf/rl30wcj92_g723bs9nskxns80000gn/T/pip-pip-egg-info-k7agivbt
         cwd: /private/var/folders/vf/rl30wcj92_g723bs9nskxns80000gn/T/pip-install-qduaoqvr/enum/
    Complete output (11 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Users/saviourgidi/projects/python_extensive/total/total-backend/env/lib/python3.7/site-packages/setuptools/__init__.py", line 6, in <module>
        import distutils.core
      File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 16, in <module>
        from distutils.dist import Distribution
      File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 9, in <module>
        import re
      File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/re.py", line 143, in <module>
        class RegexFlag(enum.IntFlag):
    AttributeError: module 'enum' has no attribute 'IntFlag'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.```

AttributeError: module 'enum' has no attribute 'IntFlag' Python 3.6.2

hi
I run command pip install infobip-api-python-client
the command failed
error

Collecting infobip-api-python-client
Using cached https://files.pythonhosted.org/packages/d8/b6/6f975e3e795643dc86b4c19cc57f1acdc04bea35f9613ce93ce4244bb645/infobip-api-python-client-2.2.0.tar.gz
Collecting enum (from infobip-api-python-client)
Using cached https://files.pythonhosted.org/packages/0c/4e/1ea357e7783c756bb579333c1e4a026fb331371ee771f616ffedc781e531/enum-0.4.6.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/Users/folt/Documents/Working/dev_messenger/venv/lib/python3.6/site-packages/setuptools/init.py", line 5, in
import distutils.core
File "/Users/folt/Documents/Working/dev_messenger/venv/lib/python3.6/distutils/init.py", line 4, in
import imp
File "/Users/folt/Documents/Working/dev_messenger/venv/lib/python3.6/imp.py", line 27, in
import tokenize
File "/Users/folt/Documents/Working/dev_messenger/venv/lib/python3.6/tokenize.py", line 33, in
import re
File "/Users/folt/Documents/Working/dev_messenger/venv/lib/python3.6/re.py", line 142, in
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/j_/qkr9lhfd0g593b64465q50cr0000gn/T/pip-install-59o613b7/enum/

I use Python 3.6.2

Error : Name 'send_single_textual_sms' is not defined

Hi
when i excute this script :
send_sms_client = send_single_textual_sms(Configuration("username", "password"))

request = SMSTextualRequest()
request.text = "This is an example message"
request.to = ["212670914264", "212670914264"]
response = send_sms_client.execute(request)

I have this error :

NameError: name 'send_single_textual_sms' is not defined

Can you help me to fix it?

SMSTextualRequest package import issue

Unable to use the SMSTextualRequest object to send the SMS. I tried to import the package using all the following paths above but none of them worked.
from infobip_api_client.model.SmsAdvancedTextualRequest import SmsAdvancedTextualRequest
from infobip_api_client.model import SmsAdvancedTextualRequest
from infobip_api_client.model import *

# name 'SendSmsApi' is not defined

Hello.
I get this error win I try to send an SMS
from infobip_api_client.api_client import ApiClient, Configuration from infobip_api_client.model.sms_advanced_textual_request import * from infobip_api_client.model.sms_textual_message import * from infobip_api_client.model.sms_destination import *
can someone help
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.