# Add Number to SMS Stop List

{% hint style="info" %}

### Important information regarding delivery reports

Reports are usually received a few seconds after sending the SMS; however, this delay can extend up to 48 hours depending on the operator and the load on our platform.
{% endhint %}

## URL

<mark style="color:green;">`POST`</mark> `https://api.smspartner.fr/v1/stop-sms/add`

#### **Required Parameters**

<table><thead><tr><th width="180">Name</th><th>Value</th></tr></thead><tbody><tr><td><code>apiKey</code></td><td><a href="https://my.smspartner.fr/dashboard/api">Your API key</a></td></tr><tr><td><code>phoneNumber</code></td><td><p>Phone number<br>It can be:</p><ul><li>in national format (06xxxxxxxx) or international format (+336xxxxxxxx), for French numbers.</li><li>in international format (+496xxxxxxxx), for non-French numbers.</li></ul></td></tr></tbody></table>

#### **Optional Parameter**

<table><thead><tr><th width="262">Name</th><th>Value</th></tr></thead><tbody><tr><td><code>_format</code></td><td><code>json</code> or <code>xml</code></td></tr></tbody></table>

#### Requests

{% tabs %}
{% tab title="PHP" %}

```php
<?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;
?>
```

{% endtab %}

{% tab title="VB.net" %}

```vbnet
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
```

{% endtab %}

{% tab title="Python" %}

```python
# 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
```

{% endtab %}

{% tab title="cURL" %}

```
curl -H  "Content-Type: application/json" -X POST -d '{"apiKey":"xxxxx","phoneNumber":"xxxx"}' https://api.smspartner.fr/v1/stop-sms/add
```

{% endtab %}

{% tab title="Nodejs" %}

```javascript
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();
```

{% endtab %}

{% tab title="JAVA" %}

```java
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();
        }
    }
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
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()
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
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)
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
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);
        }
    }
}
```

{% endtab %}
{% endtabs %}

#### **Response**

{% tabs %}
{% tab title="json" %}

```json
{
    "success": true,
    "code":200
    "stopId": 300
}
```

{% endtab %}

{% tab title="xml" %}

```xml
<?xml version='1.0' encoding='UTF-8'?>
<result>
  <entry>true</entry>
  <entry>200</entry>
  <entry>300</entry>
</result>

```

{% endtab %}
{% endtabs %}

**Error Codes**

| Response Code | Message                        |
| ------------- | ------------------------------ |
| 1             | API key is required            |
| 2             | Phone number is required       |
| 3             | Number is already in stop list |
| 9             | Invalid phone number           |
| 10            | Invalid API key                |
| 200           | Success                        |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.docpartner.dev/en/api/sms-partner/replies-opt-outs-management/add-number-to-sms-stop-list.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
