Skip to content

Commit 4b92e71

Browse files
committed
Enhanced documentation with email and moments examples.
1 parent 5f8eda6 commit 4b92e71

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed

email.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Email API example
2+
3+
This example demonstrates how to use the [Infobip Email API](https://www.infobip.com/docs/api/channels/email). You'll learn how to initialize an email client,
4+
send a message, and receive a delivery report.
5+
6+
Initialize Send Email API client:
7+
8+
```python
9+
from infobip_api_client.api_client import ApiClient, Configuration
10+
11+
client_config = Configuration(
12+
host="<YOUR_BASE_URL>",
13+
api_key={"APIKeyHeader": "<YOUR_API_KEY>"},
14+
api_key_prefix={"APIKeyHeader": "<YOUR_API_PREFIX>"},
15+
)
16+
17+
api_client = ApiClient(client_config)
18+
api_instance = EmailApi(api_client)
19+
```
20+
21+
Before sending an email message, you need to verify the domain with which you will be sending emails.
22+
23+
## Send an Email with a file
24+
25+
Fields `from`, `to`, and `subject` are required. The message must also contain at least one of these: `text`, `html`, or `templateId`.
26+
27+
---
28+
**IMPORTANT NOTE**
29+
30+
Keep in mind the following restrictions while using a trial account:
31+
32+
- you can only send messages to verified email addresses,
33+
- you can only use your email address with the Infobip test domain in the following form: `[email protected]`
34+
35+
---
36+
37+
```python
38+
file_attachment = open("report.csv", "rb")
39+
file_content = file_attachment.read()
40+
41+
api_response = api_instance.send_email(
42+
43+
var_from="Jane Smith <[email protected]>",
44+
subject="Mail subject text",
45+
text="Test message with a file",
46+
attachment=[file_content],
47+
)
48+
```
49+
50+
## Delivery reports
51+
52+
For each message that you send out, we can send you a delivery report in real time.
53+
All you need to do is specify your endpoint when sending email in the `notifyUrl` field.
54+
55+
Additionally, you can use a `messageId` or a `bulkId` autogenerated in a response for troubleshooting and to fetch reports.
56+
57+
```python
58+
bulk_id = "BULK-ID-123-xyz";
59+
number_of_reports_limits = 10;
60+
61+
62+
api_response = api_instance.get_email_delivery_reports(
63+
bulk_id=bulk_id, limit=number_of_reports_limits
64+
)
65+
66+
for report in api_response.results:
67+
print(f"{report.message_id} - {report.status.name}")
68+
```

moments.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Moments quickstart
2+
3+
This quick guide aims to help you start with [Infobip Moments API](https://www.infobip.com/docs/api/customer-engagement/moments). After reading it, you should know how to use Moments.
4+
5+
The first step is to create an `ApiClient` instance with some configuration.
6+
7+
```python
8+
from infobip_api_client.api_client import ApiClient, Configuration
9+
10+
client_config = Configuration(
11+
host="<YOUR_BASE_URL>",
12+
api_key={"APIKeyHeader": "<YOUR_API_KEY>"},
13+
api_key_prefix={"APIKeyHeader": "<YOUR_API_PREFIX>"},
14+
)
15+
16+
api_client = ApiClient(client_config)
17+
```
18+
19+
## Flow API
20+
21+
You can now create an instance of `FlowApi` which allows you to manage your flows.
22+
23+
````python
24+
from infobip_api_client.api import FlowApi
25+
26+
api_instance = FlowApi(api_client)
27+
````
28+
### Add participants to flow
29+
30+
To add participants to a flow, you can use the following code:
31+
32+
````python
33+
from infobip_api_client import (
34+
FlowAddFlowParticipantsRequest,
35+
FlowParticipant,
36+
FlowPersonUniqueField,
37+
FlowPersonUniqueFieldType,
38+
)
39+
40+
campaign_id = 200000000000001
41+
42+
request = FlowAddFlowParticipantsRequest(
43+
participants=[
44+
FlowParticipant(
45+
identify_by=FlowPersonUniqueField(
46+
identifier="[email protected]", type=FlowPersonUniqueFieldType.EMAIL
47+
),
48+
variables={"orderNumber": 1167873391},
49+
),
50+
],
51+
notify_url="https://example.com"
52+
)
53+
54+
api_response = api_instance.add_flow_participants(campaign_id, request)
55+
````
56+
57+
### Get a report on participants added to flow
58+
59+
To fetch a report to confirm that all persons have been successfully added to the flow, you can use the following code:
60+
61+
````python
62+
given_operation_id = "03f2d474-0508-46bf-9f3d-d8e2c28adaea"
63+
64+
api_response = api_instance.get_flow_participants_added_report(campaign_id, given_operation_id)
65+
````
66+
67+
### Remove person from flow
68+
69+
To remove a person from a flow, you can use the following code:
70+
71+
````python
72+
external_id = "8edb24b5-0319-48cd-a1d9-1e8bc5d577ab"
73+
74+
api_response = api_instance.remove_people_from_flow(campaign_id=campaign_id, external_id=external_id)
75+
````
76+
77+
78+
## Forms API
79+
80+
You can now create an instance of `FormsApi` which allows you to manage your forms.
81+
82+
````python
83+
from infobip_api_client.api import FormsApi
84+
85+
api_instance = FormsApi(api_client)
86+
````
87+
88+
### Get forms
89+
90+
To get all forms, you can use the following code:
91+
92+
````python
93+
api_response = api_instance.get_forms()
94+
````
95+
96+
### Get form by ID
97+
98+
To get a specific form by ID, you can use the following code:
99+
100+
````python
101+
form_id = "cec5dfd2-4238-48e0-933b-9acbdb2e6f5f"
102+
103+
api_response = api_instance.get_form(form_id)
104+
````
105+
106+
### Increment form view count
107+
108+
To increase the view counter of a specific form, you can use the following code:
109+
110+
````python
111+
api_response = api_instance.increment_view_count(form_id)
112+
````
113+
114+
### Submit form data
115+
116+
To submit data to a specific form, you can use the following code:
117+
118+
````python
119+
form_data_request = {
120+
"first_name": "John",
121+
"last_name": "Doe",
122+
"company": "Infobip",
123+
"email": "[email protected]"
124+
}
125+
api_response = api_instance.submit_form_data(form_id, form_data_request)
126+
````

0 commit comments

Comments
 (0)