Creazione di sottoconti
- Home
- Creazione di sottoconti
Creazione di sottoconti
Création de sous-compte.
URL
POST https://api.smspartner.fr/v1/subaccount/create
Impostazioni
Ogni richiesta PLC supporta i seguenti parametri :
apiKey | API key per il tuo account. Lo ottieni nel tuo account Partner SMS. |
---|---|
type | Tipo di sottoconto: questa scelta è definitiva, non sarà più possibile modificarla.
|
parameters |
email : E-mail valida del titolare del conto isBuyer : Se creditToAttribute (optionnel) : Credito in euro aggiunto al sottoconto al momento della creazione. Questo credito sarà detratto dal conto principale. firstname (opzionale) : Nome del titolare del sottoconto. lastname (opzionale) : Cognome del titolare del sottoconto. email (opzionale) : Se questo campo è vuoto, verrà generata automaticamente una e-mail (es: 9875587@smspartner.fr) creditToAttribute (opzionale) : Credito in euro aggiunto al sottoconto al momento della creazione. Questo credito sarà detratto dal conto principale. firstname (opzionale) : Nome del titolare del sottoconto. lastname (optionnel) : Cognome del titolare del sottoconto. |
Parametri opzionali _format Formato della risposta. È possibile scegliere tra JSON
o XML
. PPer impostazione predefinita, il formato di risposta è JSON
.
Richiesta
Interrogazione campione :
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 |
<?php // Prepare data for POST request $fields = array( 'apiKey'=> 'YOUR API KEY', 'type'=> 'advanced', 'parameters'=>array( 'email':'aaaa@bbb.ccc', 'creditToAttribute':10, 'isBuyer':0, 'firstname':'prenom', 'lastname':'nom' )); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL,'https://api.smspartner.fr/v1/subaccount/create'); 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 & "subaccount/create" #note : utiliser une librairie JSON en production, par exemple : #https//www.nuget.org/packages/Newtonsoft.Json/ Dim parameters As String = String.Format( "{{""apiKey"":""{0}"",""type"":""{1}"",""parameters"":""{2}""}}", apiKey, "advanced", {"email":"aaaa@bbb.ccc","creditToAttribute":10,"isBuyer":0,"firstname":"prenom","lastname":"nom"}) 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 |
# 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 create(self,creditToAdd,userId): data = {"apiKey":APIKEY,"type":"advanced","parameters": {"email":"aaaa@bbb.ccc","creditToAttribute":10,"isBuyer":0,"firstname":"prenom","lastname":"nom"}} url = URL + "/subaccount/create" 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","type":"advanced","parameters":{"email":"aaaa@bbb.ccc","creditToAttribute":10,"isBuyer":0,"firstname":"prenom","lastname":"nom"}}' https://api.smspartner.fr/v1/subaccount/create |
Risposte
1 2 3 4 5 6 7 8 9 10 11 |
{ "success":true, "code":200, "subaccount": { "email":"aaaa@bbb.ccc", "token":"token" }, "sendConfirmMailTo":"aaaa@bbb.ccc", "parent_email":"emailparent@ddd.eee" } |
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> <entry><![CDATA[aaaa@bbb.ccc]]></entry> <entry><![CDATA[token]]></entry> </entry> <entry><![CDATA[aaaa@bbb.ccc]]></entry> <entry><![CDATA[emailparent@ddd.eee]]></entry> </result> |
Errori
Esempio di messaggio di errore :
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> |
Codice di controllo
Rispondi a | ||
---|---|---|
1 | La chiave API è richiesta | |
2 | Non hai l’autorizzazione | |
3 | isBuyer è richiesto | |
4 | Il tipo è richiesto (semplice o avanzato) | |
5 | Il tipo di sottovoce non esiste (semplice o avanzato) | |
6 | L’e-mail è richiesta | |
7 | Con questa e-mail esiste già un account | |
8 | creditToAttribute deve essere maggiore di 0 | |
9 | La scala deve essere maggiore di 0 | |
200 | È andato tutto bene! |