- Notifications
You must be signed in to change notification settings - Fork19
Infobip API client library in C#, distributed as a NuGet package.
License
infobip/infobip-api-csharp-client
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a C# Client forInfobip API and you can use it as a dependency in your application.To use this library you'll need an Infobip account. You can create afree trial accounthere.
The library is built on top ofOpenAPI Specification and powered byOpenAPI Generator.
Infobip API Documentation can be foundhere.
ForInfobip.Api.Client versioning we useSemantic Versioning scheme.
Published underMIT License.
.NET Standard 2.0 is targeted for usage of this library.
Recommended way of library usage is to install it viaNuGet Package Manager.
Within Visual Studio, use the Package Manager UI to browse forInfobip.Api.Client package and install the latest version to your project.
Alternatively, also within Visual Studio, use the Package Manager Console command:
Install-Package Infobip.Api.Client -Version 4.0.0If you are used to .NET CLI, the following command is going to be sufficient for you:
dotnet add package Infobip.Api.Client --version 4.0.0Including the package directly into project file is also valid option.
<PackageReference Include="Infobip.Api.Client" Version="4.0.0" />Before initializing client we have to prepareConfiguration object for handling authentication.The library supports theAPI Key Header authentication method.To see your base URL, log in to theInfobip API Resource hub with your Infobip account.
varconfiguration=newConfiguration(){BasePath="<put your base URL here prefixed by https://>",ApiKey="<put your API key here>"};
Next step is to initialize the API client. In this case we're instantiating the SMS API client.
varsmsApi=newSmsApi(configuration);
Since library is utilizing theHttpClient behind the scene for handling the HTTP calls you can provide your own instance ofHttpClient toSendSmsApi constructor and have a control over its lifecycle.
varsmsApi=newSmsApi(myHttpClientInstance,configuration);
Here's a simple example for sending an SMS message. First prepare the message by creating an instance ofSmsRequest and its nested objects.
varsmsMessage=newSmsMessage(sender:"SMSInfo",destinations:newList<SmsDestination>(){newSmsDestination(to:"41793026727")},content:newSmsMessageContent(newSmsTextContent(text:"This is a dummy SMS message sent using Infobip.Api.Client")));varsmsRequest=newSmsRequest(messages:newList<SmsMessage>{smsMessage});
Now we can send the message using client instantiated before and inspect theApiException for more information in case of failure.You can get the HTTP status code fromErrorCode property, and more details about error fromErrorContent property.
try{varsmsResponse=smsApi.SendSmsMessages(smsRequest);System.Diagnostics.Debug.WriteLine($"Status:{smsResponse.Messages.First().Status}");}catch(ApiExceptionapiException){varerrorCode=apiException.ErrorCode;varerrorHeaders=apiException.Headers;varerrorContent=apiException.ErrorContent;}
Additionally, from the successful response (SmsResponse object) you can pull out thebulkId andmessageId(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.
varbulkId=smsResponse.BulkId;varmessageId=smsResponse.Messages.First().MessageId;
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 innotifyUrl field ofSmsTextualMessage, or subscribe for reports by contacting our support team.e.g.https://{yourDomain}/delivery-reports
You can use data models from the library and the pre-configuredNewtonsoft.Json serializer (version 13.0.3).
Example of webhook implementation:
[HttpPost("api/sms/delivery-reports")]publicIActionResultReceiveDeliveryReport([FromBody]SmsDeliveryResultdeliveryResult){foreach(varresultindeliveryResult.Results){System.Diagnostics.Debug.WriteLine($"{result.MessageId} -{result.Status.Name}");}returnOk();}
If you prefer to use your own serializer, please pay attention to the supporteddate format.Library is using custom date format stringyyyy-MM-ddTHH:mm:ss.fffzzzz when serializing dates. This format does not exactly match the format from our documentation above, but it is the closest possible. This format produces the time zone offset value with: as time separator, but our backend services will deserialize it correctly.
If you are for any reason unable to receive real time delivery reports on your endpoint, you can use ourDelivery reports API to fetch them.Each request will return a batch of delivery reports - only once.You can filter reports by multiple parameters (see API's documentation for full list), for example, bybulkId,bulkId andlimit like in the snippet below:
varnumberOfReportsLimit=10;varsmsDeliveryResult=smsApi.GetOutboundSmsMessageDeliveryReports(bulkId:bulkId,messageId:messageId,limit:numberOfReportsLimit);foreach(varsmsReportinsmsDeliveryResult.Results){Console.WriteLine($"{smsReport.MessageId} -{smsReport.Status.Name}");}
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.Use the preview SMS message functionality to verify those details as demonstrated below.
varsmsPreviewRequest=newSmsPreviewRequest(text:"Let's see how many characters will remain unused in this message.");varsmsPreviewResponse=smsApi.PreviewSmsMessage(smsPreviewRequest);
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 explainedhere e.g.https://{yourDomain}/incoming-sms.
Example of webhook implementation:
[HttpPost("api/sms/incoming-sms")]publicIActionResultReceiveSms([FromBody]SmsInboundMessageResultsmsInboundMessageResult){foreach(varresultinsmsInboundMessageResult.Results){System.Diagnostics.Debug.WriteLine($"{result.From} -{result.CleanText}");}returnOk();}
For 2FA quick start guide please checkthese examples.
For send email quick start guide please checkthese examples.
For Flow & Forms quick start guide please checkthese examples.
Feel free to open issues on the repository for any issue or feature request.Check theCONTRIBUTINGfile for details about contributions - in short, we will not merge any pull requests since this code is auto-generated.
However, if you find something that requires our imminent attention feel free to contact us @support@infobip.com.
About
Infobip API client library in C#, distributed as a NuGet package.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.