# Targeting & Calculation

## URL

<mark style="color:green;">`POST`</mark> `https://api.smspartner.fr/v1/location/optin`

#### **Parameters**

<table data-full-width="false"><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>op</code></td><td><p>Operation to perform:</p><ul><li><code>calcul</code>: Calculate the cost and number of contacts matching the targeting</li><li><code>price</code>: Calculate the cost of targeting only</li><li><code>rent</code>: Rent a contact database</li></ul></td></tr><tr><td><code>parameters</code></td><td><p><code>sexe</code> <strong>:</strong></p><p>Gender of targeted contacts, must be:<br>– <code>m</code> (mixed)<br>– or <code>h</code> (male)<br>– or <code>f</code> (female)</p><p><code>minAge</code> <strong>:</strong></p><p>Minimum age of the target, must be greater than 18.</p><p><code>maxAge</code> <strong>:</strong></p><p>Maximum age of the target, must be less than 99.</p><p><code>interest</code> <strong>:</strong></p><p><a href="../categories#categories">Main category</a> of the target.</p><p><code>subInterest</code> (optional) <strong>:</strong></p><p><a href="../categories#sous-categories">Subcategory</a> of the main category</p><p><code>category</code> (optional) <strong>:</strong></p><p>Socio-professional category:<br>– <code>102</code>: CSP+<br>– <code>103</code>: CSP-</p><p><code>department</code> (optional) <strong>:</strong></p><p>List of targeted departments. e.g.: 02,60, etc…</p><p><code>zipcode</code> (optional) <strong>:</strong></p><p>List of targeted zip codes. e.g.: 02200,60200, etc…</p></td></tr><tr><td><code>volumes</code></td><td><p>This parameter is only available if op = rent or price.</p><p>Allows you to choose a desired volume per postal code or department</p></td></tr></tbody></table>

#### Requests

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

```php
<?php
        // Prepare data for POST request
        $fields = array(
            'apiKey'=> 'YOUR API KEY',
            'op':'calcul',
            'parameters':{
            'sexe'=> 'm',
            'minAge'=> '25',
            'maxAge' => '35',
            'zipcode'=> '60200',
            'interest'=> 14, /*Habitation*/
            'subInterest'=> 35 /*Cuisine*/
            },
            'volumes':{
            '60200':20
            }
        );
 
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL,'https://api.smspartner.fr/v1/location/optin');
        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 = "YOUR API KEY"
 
    #send sms
    url = base_url & "location/optin"
    #note : utiliser une librairie JSON en production, par exemple :
    #https//www.nuget.org/packages/Newtonsoft.Json/
    Dim parameters As String = String.Format(
        "{{""apiKey"":""{0}"",""op"":""{1}"",""parameters"":""{2}"",""volumes"":""{3}""}}",
        apiKey,
        "price",
        "{ "sexe"=> "m","minAge"=> "25","maxAge" => "35","zipcode"=> "60200","interest"=> 14,"subInterest"=> 35}",
        "{"60200":20}"
        )
        ""
    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 http.client
 
conn = http.client.HTTPConnection("api,smspartner,fr")
 
payload = "{"apiKey":"YOUR API KEY","op":"price","parameters":{"sexe":"f","minAge":25,"maxAge":35,"zipcode":"06200","interest":12,"subInterest":29,"category":103},"volumes":{"60200":20}}"
 
headers = {
    "Content-Type": "application/json"
    }
 
conn.request("POST", "v1,location,optin", payload, headers)
 
res = conn.getresponse()
data = res.read()
 
print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="cURL" %}

```
curl -X POST https://api.smspartner.fr/v1/location/optin -H "Content-Type: application/json" -d '{"apiKey":"YOUR API KEY","op":"price","parameters":{"sexe":"f","minAge":25,"maxAge":35,"zipcode":"06200","interest":"12","subInterest":"29","category":103}}
```

{% endtab %}
{% endtabs %}

#### **Response**

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

```json
{
    "success": true,
    "op": "price",
    "datas": [
        {
            "Type": "CP",
            "Localite": "06200",
            "Volume": 20
        },
        {
            "Type": "total",
            "Localite": "total",
            "Volume": 20
        }
    ],
    "cost": {
        "quantity": 20,
        "total": 2.52,
        "cost_unity": 0.09
    }
}
```

{% endtab %}

{% tab title="xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<result>
    <entry>true</entry>
    <entry>
        <![CDATA[price]]>
    </entry>
    <entry>
        <entry>
            <entry>
                <![CDATA[CP]]>
            </entry>
            <entry>
                <![CDATA[06200]]>
            </entry>
            <entry>28</entry>
        </entry>
        <entry>
            <entry>
                <![CDATA[total]]>
            </entry>
            <entry>
                <![CDATA[total]]>
            </entry>
            <entry>28</entry>
        </entry>
    </entry>
    <entry>
        <entry>28</entry>
        <entry>2.52</entry>
        <entry>0.09</entry>
    </entry>
</result>
```

{% endtab %}
{% endtabs %}

#### Errors

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

```json
{
    "success": false,
    "code": 10,
    "message": "Clé API incorrecte"
}
```

{% endtab %}

{% tab title="xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<result>
    <entry>false</entry>
    <entry>10</entry>
    <entry>
        <![CDATA[Clé API incorrecte]]>
    </entry>
</result>
```

{% endtab %}
{% endtabs %}

#### **Error Codes**

| Response Code | Description         |
| ------------- | ------------------- |
| 1             | API key is required |
| 10            | Invalid API key     |
| 200           | Operation completed |


---

# 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/contact-rental/targeting-and-calculation.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.
