Envoi de sondages
- Home
- Envoi de sondages
Envoyer un sondage
Cette requête est utilisée pour envoyer un sondage en temps réel ou en différé.
URL
POST https://api.smspartner.fr/v1/sondage/to/send
Paramètres
Chaque demande d’API prend en charge les paramètres suivants :
- La plateforme n’envoie pas de SMS commerciaux entre 20h et 8h en semaine et les dimanches et jours fériés (restriction légale). Si un message SMS est envoyé, le message est en pause jusqu’au prochain jour ouvrable à 8h.
- Vous n’envoyez pas de SMS commerciaux? contactez-nous pour désactiver cette restriction : help@smspartner.fr
apiKey | Clé API de votre compte. Vous l’obtenez dans votre compte SMS Partner. |
---|---|
phoneNumbers | Numéros de téléphone des destinataires. Pour l’envoi de plusieurs SMS les numéros doivent être séparés par des virgules. Ils peuvent être :
|
sondageIdent
|
Identifiant du sondage |
Paramètres optionnels | |
tag | Chaine de caractères de 20 caractères maximum sans espace(s) et en minuscule(s) |
scheduledDeliveryDate | Date d’envoi du SMS, au format dd/mm/YYYY . A définir uniquement si vous souhaitez que les SMS soient envoyés en différé. |
time | Heure d’envoi du SMS (format 0-24), obligatoire si scheduledDeliveryDate est défini. |
minute | Minute d’envoi du SMS (format 0-55, par intervalle de cinq minutes). , obligatoire si scheduledDeliveryDate est défini. |
_format | Format de la réponse. Vous pouvez choisir entre JSON ou XML . Par défaut, le format de réponse est JSON . |
Requête
Exemple de requête :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php // Prepare data for POST request $fields = array( 'apiKey'=> 'YOUR API KEY', 'phoneNumbers'=> '+336xxxxxxxx', 'sondageIdent'=> 'SONDAGE_IDENT', 'scheduledDeliveryDate'=> '21/10/2014', 'time'=> 9, 'minute'=> 0 ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL,'https://api.smspartner.fr/v1/sondage/to/send'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($fields)); $result = curl_exec($curl); curl_close($curl); // Process your response here echo $result; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
Imports System.IO Imports System.Net Module Module1 Sub Main() Dim base_url As String = "http://api.smspartner.fr/v1/" Dim apiKey As String = "VOTRE_APIKEY" #send sms url = base_url & "sondage/to/send" #note : utiliser une librairie JSON en production, par exemple : #https//www.nuget.org/packages/Newtonsoft.Json/ Dim parameters As String = String.Format( "{{""apiKey"":""{0}"",""phoneNumbers"":""{1}"",""sondageIdent"":""{2}""}}", apiKey, "+33XXXXXXXXX", "SONDAGE_IDENT") Console.Write(parameters) apiRequest("POST", url, parameters) End Sub Function apiRequest(method As String, url As String, parameters As String) As String Dim request As HttpWebRequest request = WebRequest.Create(url) request.Method = method request.Timeout = 10000 # timeout in ms request.ContentType = "application/json; charset=utf-8" request.ContentLength = 0 #set POST data If Not String.IsNullOrEmpty(parameters) Then request.ContentLength = parameters.Length Using reqStream As StreamWriter = New StreamWriter(request.GetRequestStream()) reqStream.Write(parameters) End Using End If #get response Dim returnValue As String = Nothing Using response As HttpWebResponse = request.GetResponse() If response.StatusCode = HttpStatusCode.OK Then Using resStream = response.GetResponseStream() If resStream IsNot Nothing Then Using reader As New StreamReader(resStream) returnValue = reader.ReadToEnd() End Using End If End Using End If End Using apiRequest = returnValue End Function End Module |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# std import logging import json from collections import OrderedDict # 3p import requests API_KEY = "MY API KEY" URL = "https://api.smspartner.fr/v1" class SMSPartner(): def send_sms(self,phone_numbers, sondageIdent): #sender = "DEMOSMS" print(phone_numbers) data = OrderedDict([ ("apiKey", API_KEY), ("phoneNumbers", phone_numbers), ("sondageIdent", sondageIdent) ]) url = URL + "/send" r = requests.post(url, data=json.dumps(data), verify=False) r_json = r.json() if r_json.get("success") == True: print(r_json) status = True else: print("SMS msg {} not delivered to {}".format(msg, phone_numbers)) status = False return status |
1 |
curl -H "Content-Type: application/json" -X POST -d '{"apiKey":"xxxxx","phoneNumbers":"xxxx","sondageIdent":"SONDAGE_IDENT"}' https://api.smspartner.fr/v1/sondage/to/send |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
const https = require('https'); // Préparer les données pour la requête POST let data = JSON.stringify({ apiKey: 'YOUR API KEY', phoneNumbers: '+336XXXXXXXX', // identifiant du sondage que vous avez créé dans votre compte SMS Partner sondageIdent: 'SONDAGE ID', scheduledDeliveryDate: '04/07/2023', time: 11, minute: 55 //tous les 5 minutes ex: 00, 05, 10, 15, 20, etc. }); let options = { hostname: 'api.smspartner.fr', path: '/v1/sondage/to/send', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': data.length } }; let req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); }); }).on("error", (err) => { console.log("Erreur: " + err.message); }); req.write(data); req.end(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class SondageParSMS { public static void main(String[] args) { try { // Prepare data for POST request String apiKey = "your_api_key"; String phoneNumbers = "+336XXXXXXXX"; String sondageIdent = "your_sondage_ident"; String scheduledDeliveryDate = "05/07/2023"; int time = 10; int minute = 35; // Create JSON payload String jsonPayload = "{\"apiKey\": \"" + apiKey + "\", \"phoneNumbers\": \"" + phoneNumbers + "\", \"sondageIdent\": \"" + sondageIdent + "\", \"scheduledDeliveryDate\": \"" + scheduledDeliveryDate + "\", \"time\": " + time + ", \"minute\": " + minute + "}"; // Create POST request URL url = new URL("https://api.smspartner.fr/v1/sondage/to/send"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); // Send POST request OutputStream outputStream = connection.getOutputStream(); outputStream.write(jsonPayload.getBytes()); outputStream.flush(); outputStream.close(); // Get response int responseCode = connection.getResponseCode(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); // Process your response here System.out.println(response.toString()); } catch (Exception e) { e.printStackTrace(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import SwiftUI struct SondageSMS: View { @State private var result: String = "Loading..." var body: some View { VStack { Text("Sondage SMS") .font(.title) .padding() Text(result) .font(.system(size: 20)) .padding() } .onAppear(perform: sendSondage) } func sendSondage() { let apiKey = "YOUR_API_KEY" let phoneNumber = "+336xxxxxxxx" let sondageIdent = "SONDAGE_IDENT" let scheduledDeliveryDate = "05/07/2023" let time = 9 let minute = 0 let urlString = "https://api.smspartner.fr/v1/sondage/to/send" let url = URL(string: urlString)! var request = URLRequest(url: url) request.httpMethod = "POST" request.addValue("application/json", forHTTPHeaderField: "Content-Type") let parameters: [String: Any] = [ "apiKey": apiKey, "phoneNumbers": phoneNumber, "sondageIdent": sondageIdent, "scheduledDeliveryDate": scheduledDeliveryDate, "time": time, "minute": minute ] request.httpBody = try? JSONSerialization.data(withJSONObject: parameters) let task = URLSession.shared.dataTask(with: request) { (data, response, error) in if let error = error { print("Error: \(error)") } else if let data = data { let resultString = String(data: data, encoding: .utf8) DispatchQueue.main.async { self.result = resultString ?? "Error" } } } task.resume() } } struct SondageSMS_Previews: PreviewProvider { static var previews: some View { SondageSMS() } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
package main import ( "bytes" "encoding/json" "io/ioutil" "log" "net/http" "time" ) func main() { // Prepare data for POST request data := map[string]interface{}{ "apiKey": "YOUR API KEY", "phoneNumbers": "+336xxxxxxxx", "sondageIdent": "SONDAGE_IDENT", "scheduledDeliveryDate": "21/10/2024", "time": 9, "minute": 0, } payload, err := json.Marshal(data) if err != nil { log.Fatalf("Error preparing data: %v", err) } // Create POST request client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("POST", "https://api.smspartner.fr/v1/sondage/to/send", bytes.NewBuffer(payload)) if err != nil { log.Fatalf("Error creating request: %v", err) } req.Header.Set("Content-Type", "application/json") // Send POST request resp, err := client.Do(req) if err != nil { log.Fatalf("Error sending request: %v", err) } defer resp.Body.Close() // Get response body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("Error reading response body: %v", err) } // Process your response here log.Printf("Response: %s", body) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; class Program { private static readonly HttpClient client = new HttpClient(); static async Task Main(string[] args) { var request = new { apiKey = "YOUR_API_KEY", phoneNumbers = "+336xxxxxxxx", sondageIdent = "SONDAGE_IDENT", scheduledDeliveryDate = "21/10/2014", time = 9, minute = 0 }; var content = new StringContent( JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://api.smspartner.fr/v1/sondage/to/send", content); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); } else { Console.WriteLine("POST request failed with status code: " + response.StatusCode); } } } |
Réponses
1 2 3 4 5 6 7 8 |
{ "success":true, "code":200, "message_id":307, "nb_sms": 1, "cost": 0.038, "currency": "EUR" } |
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version='1.0' encoding='UTF-8'?> <result> <entry>true</entry> <entry>200</entry> <entry>306</entry> <entry>1</entry> <entry>0.038</entry> <entry> <![CDATA[EUR]]> </entry> </result> |
Erreurs
Exemple de message d’erreur:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "success": false, "code":9, "error": [{ "elementId": "children[message].data", "message": "Le message est requis" }, { "elementId": "children[phoneNumbers].data", "message": "Ce numero de telephone n'est pas valide (922264)" }, { "elementId": "children[sender].data", "message": "L'emetteur ne peut pas etre plus long que 11 caracteres" }, { "elementId": "children[scheduledDeliveryDate].data", "message": "La date (21/11/2014 \u00e0 :) est anterieure a la date actuelle." }, { "elementId": "children[minute].data", "message": "La minute est requise" }, { "elementId": "children[time].data", "message": "L'heure est requise" }] } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?xml version='1.0' encoding='UTF-8'?> <result> <entry>false</entry> <entry>9</entry> <entry> <entry> <entry>children[message].data</entry> <entry>Le message est requis</entry> </entry> <entry> <entry>children[phoneNumbers].data</entry> <entry>Ce numéro de téléphone n'est pas valide (922264)</entry> </entry> <entry> <entry>children[sender].data</entry> <entry>L'émetteur ne peut pas être plus long que 11 caractères</entry> </entry> <entry> <entry>children[scheduledDeliveryDate].data</entry> <entry>La date (21/11/2014 à :) est anterieure à la date actuelle. Si vous souhaitez l'envoyer maintenant vous devez sélectionner [Envoi immédiat]</entry> </entry> <entry> <entry>children[minute].data</entry> <entry>La minute est requise</entry> </entry> <entry> <entry>children[time].data</entry> <entry>L'heure est requise</entry> </entry> </entry> </result> |
Code de contrôle
Code erreurs | ||
---|---|---|
1 | La Clé API est requise | |
2 | Le numéro de téléphone est requis | |
9 | Au moins une contrainte n’a pas été respectée lors de l’envoi :
|
|
10 | Clé API incorrecte | |
11 | Manque de crédits |
© 2014 - 2023 NDA MEDIA. Tous droits réservés. Mentions légales