> For the complete documentation index, see [llms.txt](https://www.docpartner.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.docpartner.dev/en/api/sms-partner/contact-rental/targeting-and-calculation.md).

# Targeting & Calculation

This request allows you to calculate targeting and its cost.

## 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="/en/api/sms-partner/contact-rental/categories.md#categories">Main category</a> of the target.</p><p><code>subInterest</code> (optional) <strong>:</strong></p><p><a href="/en/api/sms-partner/contact-rental/categories.md#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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.docpartner.dev/en/api/sms-partner/contact-rental/targeting-and-calculation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
