Ajouter un numéro
- Home
- Ajouter un numéro
Ajouter un numéro à la liste des stops
Cette requête permet d’ajouter un numéro à la liste des stops.
A noter : les comptes-rendus sont reçus en moyenne quelques secondes après l’envoi du SMS ; cependant, ce délai peut s’étendre jusqu’à 48h maximum selon les opérateurs et la charge de notre plateforme.
URL
POST https://api.smspartner.fr/v1/stop-sms/add
Paramètres
Chaque demande d’API prend en charge les paramètres suivants :
apiKey | Clé API de votre compte. Vous l’obtenez dans votre compte SMS Partner. |
---|---|
phoneNumber | Numéros de mobile à ajouter. Ils peuvent être :
|
Paramètres optionnels | |
_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 |
<?php // Prepare data for POST request $fields = array( 'apiKey'=> 'YOUR API KEY', 'phoneNumber'=> '+336xxxxxxxx' ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL,'https://api.smspartner.fr/v1/stop-sms/add'); 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 |
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 & "stop-sms/add" #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}""}}", apiKey, "+33XXXXXXXXX") 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 |
# 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 add_stop(self,phone_numbers): data = OrderedDict([ ("apiKey", API_KEY), ("phoneNumbers", phone_numbers) ]) url = URL + "/stop-sms/add" 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(r_json) status = False return status |
1 |
curl -H "Content-Type: application/json" -X POST -d '{"apiKey":"xxxxx","phoneNumber":"xxxx"}' https://api.smspartner.fr/v1/stop-sms/add |
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 |
const https = require('https'); // ce code permet d'ajouter un numéro à la liste des numéros stop SMS let data = JSON.stringify({ apiKey: 'VOTRE_API_KEY', phoneNumber: '+336XXXXXXXX', }); let options = { hostname: 'api.smspartner.fr', path: '/v1/stop-sms/add', 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("Error: " + 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 |
import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class StopSmsAddList { public static void main(String[] args) { try { // Prepare data for POST request String apiKey = "YOUR_API_KEY"; String phoneNumber = "+336xxxxxxxx"; // Create JSON payload String jsonPayload = "{\"apiKey\": \"" + apiKey + "\", \"phoneNumber\": \"" + phoneNumber + "\"}"; // Create POST request URL url = new URL("https://api.smspartner.fr/v1/stop-sms/add"); 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(); if (responseCode >= 200 && responseCode <= 299) { // Process your successful response here System.out.println("Stop SMS request successful"); } else { // Process your error response here System.out.println("Stop SMS request failed"); } } 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 |
import SwiftUI struct StopSmsAddList: View { @State private var result: String = "Loading..." var body: some View { VStack { Text("Stop SMS Add") .font(.title) .padding() Text(result) .font(.system(size: 20)) .padding() } .onAppear(perform: addStopSms) } func addStopSms() { let apiKey = "YOUR API KEY" let phoneNumber = "+336xxxxxxxx" let urlString = "https://api.smspartner.fr/v1/stop-sms/add" guard let url = URL(string: urlString) else { print("Invalid URL") return } let fields = ["apiKey": apiKey, "phoneNumber": phoneNumber] var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") do { request.httpBody = try JSONSerialization.data(withJSONObject: fields, options: []) } catch { print("Failed to serialize data: \(error.localizedDescription)") return } let task = URLSession.shared.dataTask(with: request) { (data, response, error) in if let error = error { print("Error: \(error)") } else if let data = data { let result = String(data: data, encoding: .utf8) DispatchQueue.main.async { self.result = result ?? "Error" } } } task.resume() } } |
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 |
package main import ( "bytes" "encoding/json" "log" "net/http" "time" ) func main() { // Prepare data for POST request data := map[string]string{ "apiKey": "YOUR_API_KEY", "phoneNumber": "+336xxxxxxxx", } jsonData, err := json.Marshal(data) if err != nil { log.Fatalf("Error marshaling data: %v", err) } // Create HTTP client client := &http.Client{Timeout: 10 * time.Second} // Create POST request req, err := http.NewRequest("POST", "https://api.smspartner.fr/v1/stop-sms/add", bytes.NewBuffer(jsonData)) 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() // Process your response here log.Printf("Response status code: %d", resp.StatusCode) } |
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 |
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 data = new { apiKey = "YOUR_API_KEY", phoneNumber = "+336xxxxxxxx" }; var json = JsonConvert.SerializeObject(data); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://api.smspartner.fr/v1/stop-sms/add", content); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); } else { Console.WriteLine("La requête POST a échoué avec le code de statut: " + response.StatusCode); } } } |
Réponses
1 2 3 4 5 |
{ "success": true, "code":200 "stopId": 300 } |
1 2 3 4 5 6 |
<?xml version="1.0" encoding="UTF-8"?> <result> <entry>true</entry> <entry>1</entry> <entry>24</entry> </result> |
Erreurs
Exemple de message d’erreur :
1 2 3 4 5 |
{ "success": false, "code": 10, "message": "Clé API incorrecte" } |
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="UTF-8"?> <result> <entry>false</entry> <entry>10</entry> <entry> <![CDATA[Clé API incorrecte]]> </entry> </result |
Code de contrôle
Réponse | ||
---|---|---|
1 | La Clé API est requise | |
2 | Le numéro de téléphone est requis | |
3 | Le numéro est déjà dans la liste | |
9 | Le numéro de téléphone est invalide | |
10 | Clé API incorrecte | |
200 | Tout s’est bien passé ! |
© 2014 - 2023 NDA MEDIA. Tous droits réservés. Mentions légales