SMS C API example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "cJSON.h"
int main()
{
char token[] = "token"; //Your first token must be generated on our plateform at https://my.smsfactor.com/developers/api-tokens
char* numbers[] = {"33612345678","33612345678"};
char data[] = "C example test";
char src[200];
int i = 0;
char *out;
cJSON *postdata, *sms, *recipients, *car, *message, *gsm;
struct curl_slist *list = NULL;
CURLcode response;
postdata = cJSON_CreateObject();
sms = cJSON_CreateObject();
recipients =cJSON_CreateObject();
message = cJSON_CreateObject();
gsm = cJSON_CreateArray();
cJSON_AddItemToObject(postdata, "sms", sms);
cJSON_AddItemToObject(sms, "recipients", recipients);
cJSON_AddItemToObject(sms, "message", message);
cJSON_AddItemToObject(recipients, "gsm", gsm);
for(i = 0 ; i < sizeof(numbers)/sizeof(char*) ; i++){
cJSON_AddItemToArray(gsm, car = cJSON_CreateObject());
cJSON_AddItemToObject(car, "value", cJSON_CreateString(numbers[i]));
}
cJSON_AddItemToObject(message, "text", cJSON_CreateString(data));
out = cJSON_Print(postdata);
printf("%s\n", out);
strcpy(src, "Authorization: Bearer ");
strcat(src, token);
list = curl_slist_append(list, "Content-Type: application/json");
list = curl_slist_append(list, "Accept: application/json");
list = curl_slist_append(list,src);
CURL *curl = curl_easy_init();
if(curl){
curl_easy_setopt(curl, CURLOPT_URL, "https://api.smsfactor.com/send");
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,(long) strlen(out));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, out);
response = curl_easy_perform(curl);
if (response != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(response));
}
curl_easy_cleanup(curl);
}
cJSON_Delete(postdata);
curl_slist_free_all(list);
return 0;
}
When does it make sense to opt for a C-based SMS API?
Maximize the efficiency of your communications by leveraging our SMS API optimized for the C language. Simplify the integration of message sending into your C projects, with just a few lines of code. This feature enables you to provide your applications with automatic SMS notifications, considerably reducing recurring manual operations.
Discover various applications of our API:
- Sending SMS messages each time a report is generated or an important event occurs in your application.
- SMS notification of errors or critical alerts in your systems.
- Sending messages to contact lists managed in your C application.
- SMS notification triggered by customer activities within your application.
Why choose SMSFactor's SMS API designed for C?
We provide you with a dedicated team to guide you through the integration of our SMS API in C. Benefit from the expertise of our developers for personalized advice, guaranteeing smooth, high-performance integration of SMS into your solutions.
What's more, our SMS API in C stands out for its security and reliability: a 99.9% uptime rate, a high-performance anti-spam system, strict compliance with RGPD standards, and much more.
You'll also benefit from scalable features:
- Sending simulation to test your configurations with complete peace of mind.
- Integration of tracked short links to analyze click-through rates.
- Automated SMS response and acknowledgement management.
- Management of unsubscribes and automatic STOP commands, ensuring your contacts' wishes are respected.
- Webhooks for efficient retrieval of data from your campaigns and one-off SMS dispatches.