Infobip
In this example, we will show you how you can get started working with the Infobip API to produce a working use case that can send an SMS message to any number.
You'll need an Infobip account. Sign up and get free message credit, and a shared sender number from Infobip. They will automatically assign you can API key when you register.
Install & Authorize Superface
The Superface CLI provides all the tooling needed to author the Comlinks for your integration.
- macOS
- Linux
- Windows
brew install superfaceai/cli/superface
npm install -g @superfaceai/cli@latest
npm install -g @superfaceai/cli@latest
If you don't have a Superface account already, you can sign up here. You can use your account to authenticate the CLI.
superface login
Prepare the documentation
Infobip has great documentation for all their endpoints. The endpoint needed for this use case is Send SMS Message.
superface prepare https://www.infobip.com/docs/api/channels/sms/sms-messaging/outbound-sms/send-sms-message "infobip"
Edit the Infobip provider
Once the documentation has been indexed, you will need to edit the infobip.provider.json
that has been created to ensure that the correct API endpoint and security policy are used. The exact provider definition you need to use is below:
InfoBip uses a personalized base URL for each customer. You will need to replace the baseURL
value in the provider example below with your own. You can find yours on the API documentation or InfoBip Portal Homepage.
{
"name": "infobip",
"defaultService": "default",
"services": [
{
"id": "default",
"baseUrl": "<YOUR_INFOBIP_BASE_URL>"
}
],
"securitySchemes": [
{
"id": "infobipApiKey",
"type": "apiKey",
"in": "header",
"name": "Authorization"
}
],
"parameters": []
}
Define your use case
Next, you can create a profile for the use case you want to achieve, which in this case is to send an SMS message.
superface new infobip "send an sms"
A file called sms-messaging-outbound-sms.profile
will be created in the superface
folder as a result of this. This is a Comlink file that decribes the input and output expectations that the API expects to achieve this use case.
Turn the Comlink into code
To turn the Comlink profile into runnable code in either Node.js or Python, use the following command and include the name of the provider and a use case profile you want to work with.
- Node.js
- Python
superface map infobip sms-messaging/outbound-sms
superface map infobip sms-messaging/outbound-sms python
Add your API key
If you don't already have your Infobip API key in your environment, you can add it to your .env
file.
You need to include the prefix App
before your API key in your environment, this will ensure that Superface can meet the format required by InfoBip's API. For example, INFOBIP_API_KEY="App <your-infobip-api-key>"
.
Set up your inputs
In order to send an email correctly, you will need to modify the boilerplate code from the Infobip documentation so it contains a real number that can receive an SMS. From the superface
folder, open sms-messaging.outbound-sms.infobip.mjs
(or .py
if you created Python files) and modify the object in the usecase.perform()
function.
- Node.js
- Python
{
from : 'InfoSMS',
to : '+0987654321', // replace with your own number
text : 'Hello, this is an example SMS.'
},
{
from : 'InfoSMS',
to : '+0987654321', // replace with your own number
text : 'Hello, this is an example SMS.'
},
Test it
To test this use case you can use the execute
command. Switch to the superface
directory and run:
- Node.js
- Python
superface execute infobip sms-messaging/outbound-sms
superface execute infobip sms-messaging/outbound-sms python
If everything is successful you should see output similar to the response below:
RESULT: {
"messages": [
{
"messageId": "38916146354362316528",
"smsCount": 1,
"status": {
"description": "Message sent to next instance",
"groupId": 1,
"groupName": "PENDING",
"id": 7,
"name": "PENDING_ENROUTE"
},
"to": "0987654321"
}
]
}