Crédits
- Home
- Crédits
Introduction à l’API SMS Partner
Cette requête est utilisée pour récupérer votre crédit disponible de SMS, ainsi que le nombre de SMS en instance de départ.
URL
GET https://api.smspartner.fr/v1/me
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. |
---|---|
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 |
<?php // Prepare data for GET request $data = 'apiKey=YOUR_API_KEY'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL,'https://api.smspartner.fr/v1/me?'.$data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 10); $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 |
cURL 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" #check credits Dim url As String url = base_url & "me" & "?apiKey=" & apiKey Dim credits As String credits = apiRequest("GET", url, Nothing) 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 |
# 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 get_balance(self): url = URL + "/me?apiKey=" + API_KEY r = requests.get(url) 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 GET https://api.smspartner.fr/v1/me?apiKey=xxx |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
const https = require('https'); // Préparer les données pour la requête GET let data = 'apiKey=YOUR API KEY'; let url = 'https://api.smspartner.fr/v1/me?' + data; https.get(url, (res) => { let data = ''; // Un morceau de données a été reçu. res.on('data', (chunk) => { data += chunk; }); // La totalité de la réponse a été reçue. Imprimer le résultat. res.on('end', () => { console.log(JSON.parse(data)); }); }).on("error", (err) => { // Un message d'erreur sera imprimé en cas d'erreur. console.log("Erreur: " + err.message); }); |
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 |
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class CreditsSms { public static void main(String[] args) { try { String apiKey = "your_api_key"; String url = "https://api.smspartner.fr/v1/me?apiKey=" + apiKey; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); } else { System.out.println("GET request failed. Response Code: " + responseCode); } } 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 |
import SwiftUI struct Credits: View { @State private var credit: String = "Loading..." var body: some View { VStack { Text("Mon crédit") .font(.title) .padding() Text(credit) .font(.system(size: 20)) .padding() } .onAppear(perform: getCredit) } func getCredit() { let apiKey = "Your-api-key" let urlString = "https://api.smspartner.fr/v1/me?apiKey=\(apiKey)" guard let url = URL(string: urlString) else { print("URL inválida") return } let task = URLSession.shared.dataTask(with: url) { (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 { credit = result ?? "Error" } } } task.resume() } } struct CreditView_Previews: PreviewProvider { static var previews: some View { Credits() } } |
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 |
package main import ( "fmt" "io/ioutil" "net/http" ) func main() { apiKey := "your_api_key" url := "https://api.smspartner.fr/v1/me?apiKey=" + apiKey response, err := http.Get(url) if err != nil { fmt.Println("GET request failed:", err) return } defer response.Body.Close() if response.StatusCode == http.StatusOK { bodyBytes, err := ioutil.ReadAll(response.Body) if err != nil { fmt.Println("Failed to read response body:", err) return } fmt.Println(string(bodyBytes)) } else { fmt.Println("GET request failed. Response Code:", response.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 |
using System; using System.Net.Http; using System.Threading.Tasks; class Program { private static readonly HttpClient client = new HttpClient(); static async Task Main(string[] args) { var apiKey = "YOUR_API_KEY"; var uri = new Uri($"https://api.smspartner.fr/v1/me?apiKey={apiKey}"); HttpResponseMessage response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); } else { Console.WriteLine("GET request failed with status code: " + response.StatusCode); } } } |
Réponses
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
{ "success": true, "code": 200, "user": { "username": "exemple@email.com", "firstname": "John", "lastname": "Doe" }, "credits": { "creditSms": 269082, "creditSmsLowCost": 444570 (Ce paramètre sera prochainement supprimé, il est actuellement remplacé par creditSmsECO) "creditSmsECO": 444570, "creditHlr": 2045023, "toSend": 0, "solde": "10225.119", "currency": "EUR", "balance": "10225.119" } } |
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 |
<?xml version='1.0' encoding='UTF-8'?> <result> <entry>true</entry> <entry>200</entry> <entry> <username>exemple@email.com</username> <firstname>John</firstname> <lastname>Doe</lastname> </entry> <entry> <entry>269070</entry> <entry>444551</entry> <entry>2044937</entry> <entry>0</entry> <entry> <![CDATA[10224.688]]> </entry> <entry> <![CDATA[EUR]]> </entry> <entry> <![CDATA[10224.688]]> </entry> </entry> </result> |
Code de contrôle
_ | Réponse |
---|---|
10 | Clé API incorrecte |
200 | Tout s’est bien passé ! |
© 2014 - 2023 NDA MEDIA. Tous droits réservés. Mentions légales