{"id":15633,"date":"2026-07-10T00:32:42","date_gmt":"2026-07-10T05:32:42","guid":{"rendered":"https:\/\/voxpria.com\/docs\/code-examples-2\/"},"modified":"2026-07-10T00:32:42","modified_gmt":"2026-07-10T05:32:42","password":"","slug":"code-examples","status":"publish","type":"docs","link":"https:\/\/voxpria.com\/fr\/docs\/code-examples\/","title":{"rendered":"Exemples de code"},"content":{"rendered":"<h2>Exemples de code<\/h2>\n<p>Exemples fonctionnels complets dans les langages de programmation les plus populaires.<\/p>\n<h3>JavaScript \/ Node.js<\/h3>\n<h4>Exemple d&rsquo;int\u00e9gration complet<\/h4>\n<pre style=\"background: #1e293b; color: #e2e8f0; padding: 20px; border-radius: 8px;\">\nconst axios = require('axios');\n\nconst API_KEY = process.env.VOXPRIA_API_KEY;\nconst BASE_URL = 'https:\/\/app.voxpria.com\/api\/v1';\n\n\/\/ D\u00e9clencher un appel\nasync function triggerCall(agentId, phoneNumber, variables = {}) {\n  try {\n    const response = await axios.post(\n      `${BASE_URL}\/calls`,\n      {\n        agentId: agentId,\n        toNumber: phoneNumber,\n        variables: variables\n      },\n      {\n        headers: {\n          'Authorization': `Bearer ${API_KEY}`,\n          'Content-Type': 'application\/json'\n        }\n      }\n    );\n    return response.data;\n  } catch (error) {\n    console.error('Error:', error.response?.data || error.message);\n    throw error;\n  }\n}\n\n\/\/ Obtenir les d\u00e9tails de l'appel\nasync function getCallDetails(callId) {\n  const response = await axios.get(\n    `${BASE_URL}\/calls\/${callId}`,\n    {\n      headers: {\n        'Authorization': `Bearer ${API_KEY}`\n      }\n    }\n  );\n  return response.data;\n}\n\n\/\/ Utilisation\nasync function main() {\n  \/\/ D\u00e9clencher l'appel\n  const result = await triggerCall(\n    'agent_abc123',\n    '+14155551234',\n    { customerName: 'John Doe' }\n  );\n  console.log('Call ID:', result.data.callId);\n  \n  \/\/ Attendre et v\u00e9rifier le statut\n  setTimeout(async () => {\n    const details = await getCallDetails(result.data.callId);\n    console.log('Status:', details.data.status);\n  }, 5000);\n}\n\nmain();\n<\/pre>\n<h3>Python<\/h3>\n<h4>Exemple d&rsquo;int\u00e9gration complet<\/h4>\n<pre style=\"background: #1e293b; color: #e2e8f0; padding: 20px; border-radius: 8px;\">\nimport requests\nimport os\nimport time\n\nAPI_KEY = os.getenv('VOXPRIA_API_KEY')\nBASE_URL = 'https:\/\/app.voxpria.com\/api\/v1'\n\ndef trigger_call(agent_id, phone_number, variables=None):\n    \"\"\"D\u00e9clenche un nouvel appel vocal\"\"\"\n    try:\n        response = requests.post(\n            f'{BASE_URL}\/calls',\n            json={\n                'agentId': agent_id,\n                'toNumber': phone_number,\n                'variables': variables or {}\n            },\n            headers={\n                'Authorization': f'Bearer {API_KEY}',\n                'Content-Type': 'application\/json'\n            }\n        )\n        response.raise_for_status()\n        return response.json()\n    except requests.exceptions.RequestException as e:\n        print(f'Error: {e}')\n        raise\n\ndef get_call_details(call_id):\n    \"\"\"Obtient les d\u00e9tails d'un appel pr\u00e9cis\"\"\"\n    response = requests.get(\n        f'{BASE_URL}\/calls\/{call_id}',\n        headers={'Authorization': f'Bearer {API_KEY}'}\n    )\n    response.raise_for_status()\n    return response.json()\n\n# Utilisation\nif __name__ == '__main__':\n    # D\u00e9clencher l'appel\n    result = trigger_call(\n        'agent_abc123',\n        '+14155551234',\n        {'customerName': 'John Doe'}\n    )\n    print(f\"Call ID: {result['data']['callId']}\")\n    \n    # Attendre et v\u00e9rifier le statut\n    time.sleep(5)\n    details = get_call_details(result['data']['callId'])\n    print(f\"Status: {details['data']['status']}\")\n<\/pre>\n<h3>PHP<\/h3>\n<h4>Exemple d&rsquo;int\u00e9gration complet<\/h4>\n<pre style=\"background: #1e293b; color: #e2e8f0; padding: 20px; border-radius: 8px;\">\n&lt;?php\n\n$apiKey = getenv('VOXPRIA_API_KEY');\n$baseUrl = 'https:\/\/app.voxpria.com\/api\/v1';\n\nfunction triggerCall($agentId, $phoneNumber, $variables = []) {\n    global $apiKey, $baseUrl;\n    \n    $ch = curl_init(\"$baseUrl\/calls\");\n    \n    curl_setopt($ch, CURLOPT_POST, true);\n    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([\n        'agentId' => $agentId,\n        'toNumber' => $phoneNumber,\n        'variables' => $variables\n    ]));\n    curl_setopt($ch, CURLOPT_HTTPHEADER, [\n        \"Authorization: Bearer $apiKey\",\n        'Content-Type: application\/json'\n    ]);\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n    \n    $response = curl_exec($ch);\n    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\n    curl_close($ch);\n    \n    if ($httpCode !== 200) {\n        throw new Exception(\"API Error: $response\");\n    }\n    \n    return json_decode($response, true);\n}\n\nfunction getCallDetails($callId) {\n    global $apiKey, $baseUrl;\n    \n    $ch = curl_init(\"$baseUrl\/calls\/$callId\");\n    \n    curl_setopt($ch, CURLOPT_HTTPHEADER, [\n        \"Authorization: Bearer $apiKey\"\n    ]);\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n    \n    $response = curl_exec($ch);\n    curl_close($ch);\n    \n    return json_decode($response, true);\n}\n\n\/\/ Utilisation\ntry {\n    $result = triggerCall(\n        'agent_abc123',\n        '+14155551234',\n        ['customerName' => 'John Doe']\n    );\n    echo \"Call ID: \" . $result['data']['callId'] . \"n\";\n    \n    \/\/ Attendre et v\u00e9rifier\n    sleep(5);\n    $details = getCallDetails($result['data']['callId']);\n    echo \"Status: \" . $details['data']['status'] . \"n\";\n    \n} catch (Exception $e) {\n    echo \"Error: \" . $e->getMessage() . \"n\";\n}\n\n?>\n<\/pre>\n<h3>C#<\/h3>\n<h4>Exemple d&rsquo;int\u00e9gration complet<\/h4>\n<pre style=\"background: #1e293b; color: #e2e8f0; padding: 20px; border-radius: 8px;\">\nusing System;\nusing System.Net.Http;\nusing System.Net.Http.Headers;\nusing System.Text;\nusing System.Text.Json;\nusing System.Threading.Tasks;\n\npublic class VoxPriaClient\n{\n    private readonly string _apiKey;\n    private readonly string _baseUrl;\n    private readonly HttpClient _httpClient;\n\n    public VoxPriaClient(string apiKey)\n    {\n        _apiKey = apiKey;\n        _baseUrl = \"https:\/\/app.voxpria.com\/api\/v1\";\n        _httpClient = new HttpClient();\n        _httpClient.DefaultRequestHeaders.Authorization = \n            new AuthenticationHeaderValue(\"Bearer\", _apiKey);\n    }\n\n    public async Task<JsonDocument> TriggerCall(\n        string agentId, \n        string phoneNumber, \n        object variables = null)\n    {\n        var payload = new\n        {\n            agentId = agentId,\n            toNumber = phoneNumber,\n            variables = variables ?? new { }\n        };\n\n        var content = new StringContent(\n            JsonSerializer.Serialize(payload),\n            Encoding.UTF8,\n            \"application\/json\"\n        );\n\n        var response = await _httpClient.PostAsync(\n            $\"{_baseUrl}\/calls\",\n            content\n        );\n\n        response.EnsureSuccessStatusCode();\n\n        var responseBody = await response.Content.ReadAsStringAsync();\n        return JsonDocument.Parse(responseBody);\n    }\n\n    public async Task<JsonDocument> GetCallDetails(string callId)\n    {\n        var response = await _httpClient.GetAsync(\n            $\"{_baseUrl}\/calls\/{callId}\"\n        );\n\n        response.EnsureSuccessStatusCode();\n\n        var responseBody = await response.Content.ReadAsStringAsync();\n        return JsonDocument.Parse(responseBody);\n    }\n}\n\n\/\/ Utilisation\nclass Program\n{\n    static async Task Main(string[] args)\n    {\n        var apiKey = Environment.GetEnvironmentVariable(\"VOXPRIA_API_KEY\");\n        var client = new VoxPriaClient(apiKey);\n\n        try\n        {\n            \/\/ D\u00e9clencher l'appel\n            var result = await client.TriggerCall(\n                \"agent_abc123\",\n                \"+14155551234\",\n                new { customerName = \"John Doe\" }\n            );\n\n            var callId = result.RootElement\n                .GetProperty(\"data\")\n                .GetProperty(\"callId\")\n                .GetString();\n\n            Console.WriteLine($\"Call ID: {callId}\");\n\n            \/\/ Attendre et v\u00e9rifier le statut\n            await Task.Delay(5000);\n            var details = await client.GetCallDetails(callId);\n\n            var status = details.RootElement\n                .GetProperty(\"data\")\n                .GetProperty(\"status\")\n                .GetString();\n\n            Console.WriteLine($\"Status: {status}\");\n        }\n        catch (Exception ex)\n        {\n            Console.WriteLine($\"Error: {ex.Message}\");\n        }\n    }\n}\n<\/pre>\n<h3>Exemple de gestion des erreurs<\/h3>\n<p>Gestion robuste des erreurs, tous langages confondus :<\/p>\n<h4>JavaScript<\/h4>\n<pre style=\"background: #1e293b; color: #e2e8f0; padding: 20px; border-radius: 8px;\">\nasync function makeApiCall() {\n  try {\n    const response = await axios.get(url, config);\n    return response.data;\n  } catch (error) {\n    if (error.response) {\n      \/\/ Le serveur a r\u00e9pondu avec une erreur\n      switch (error.response.status) {\n        case 401:\n          throw new Error('Invalid API key');\n        case 429:\n          throw new Error('Rate limited - retry later');\n        case 500:\n          throw new Error('Server error');\n        default:\n          throw new Error(error.response.data.error.message);\n      }\n    }\n    throw error;\n  }\n}\n<\/pre>\n<div style=\"background: #d4edda; border-left: 4px solid #28a745; padding: 15px;\">\n<strong>\u2705 Meilleures pratiques :<\/strong><\/p>\n<ul>\n<li>Stockez les cl\u00e9s API dans des variables d&rsquo;environnement<\/li>\n<li>Mettez en place un d\u00e9lai exponentiel pour les limites de d\u00e9bit<\/li>\n<li>Consignez les erreurs \u00e0 des fins de d\u00e9bogage<\/li>\n<li>Utilisez try-catch pour la gestion des erreurs<\/li>\n<li>Validez les num\u00e9ros de t\u00e9l\u00e9phone avant d&rsquo;appeler l&rsquo;API<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Exemples de code Exemples fonctionnels complets dans les langages de  [&#8230;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[101],"doc_tag":[],"class_list":["post-15633","docs","type-docs","status-publish","hentry","doc_category-rest-api-for-developers-fr"],"year_month":"2026-08","word_count":874,"total_views":"14","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":[],"doc_category_info":[{"term_name":"API REST pour d\u00e9veloppeurs","term_url":"https:\/\/voxpria.com\/fr\/docs-category\/rest-api-for-developers-fr\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Exemples de code - Ai voice automation system - Voxpria<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/voxpria.com\/fr\/docs\/code-examples\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exemples de code\" \/>\n<meta property=\"og:description\" content=\"Exemples de code Exemples fonctionnels complets dans les langages de [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/voxpria.com\/fr\/docs\/code-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Ai voice automation system - Voxpria\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/docs\\\/code-examples\\\/\",\"url\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/docs\\\/code-examples\\\/\",\"name\":\"Exemples de code - Ai voice automation system - Voxpria\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/#website\"},\"datePublished\":\"2026-07-10T05:32:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/docs\\\/code-examples\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/voxpria.com\\\/fr\\\/docs\\\/code-examples\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/docs\\\/code-examples\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Docs\",\"item\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/docs\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Exemples de code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/#website\",\"url\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/\",\"name\":\"Ai voice automation system - Voxpria\",\"description\":\"Ai voice automation system\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/#organization\",\"name\":\"VoxPria\",\"url\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/voxpria-logo.png\"},\"description\":\"VoxPria est une plateforme d'agents vocaux IA qui automatise les appels t\u00e9l\u00e9phoniques entrants et sortants \u2014 ventes, soutien, prise de rendez-vous et qualification de prospects \u2014 dans n'importe quelle langue, 24\\\/7.\",\"foundingLocation\":{\"@type\":\"Place\",\"address\":{\"@type\":\"PostalAddress\",\"addressLocality\":\"Montr\u00e9al\",\"addressRegion\":\"QC\",\"addressCountry\":\"CA\"}},\"areaServed\":\"Worldwide\",\"contactPoint\":{\"@type\":\"ContactPoint\",\"contactType\":\"sales\",\"email\":\"support@voxpria.com\",\"availableLanguage\":[\"en\",\"fr\"]}},{\"@type\":\"SoftwareApplication\",\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/#software\",\"name\":\"VoxPria\",\"applicationCategory\":\"BusinessApplication\",\"applicationSubCategory\":\"AI Voice Agent \\\/ Call Automation\",\"operatingSystem\":\"Web, Cloud\",\"url\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/\",\"publisher\":{\"@id\":\"https:\\\/\\\/voxpria.com\\\/fr\\\/#organization\"},\"offers\":{\"@type\":\"Offer\",\"price\":\"0\",\"priceCurrency\":\"USD\",\"description\":\"Free tier \u2014 no credit card required\"},\"featureList\":[\"AI voice agents\",\"Outbound & inbound calling\",\"Campaign manager\",\"Flow builder\",\"CRM\",\"WhatsApp\",\"Appointment booking\",\"SIP trunks\",\"REST API\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Exemples de code - Ai voice automation system - Voxpria","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/voxpria.com\/fr\/docs\/code-examples\/","og_locale":"fr_FR","og_type":"article","og_title":"Exemples de code","og_description":"Exemples de code Exemples fonctionnels complets dans les langages de [...]","og_url":"https:\/\/voxpria.com\/fr\/docs\/code-examples\/","og_site_name":"Ai voice automation system - Voxpria","twitter_card":"summary_large_image","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/voxpria.com\/fr\/docs\/code-examples\/","url":"https:\/\/voxpria.com\/fr\/docs\/code-examples\/","name":"Exemples de code - Ai voice automation system - Voxpria","isPartOf":{"@id":"https:\/\/voxpria.com\/fr\/#website"},"datePublished":"2026-07-10T05:32:42+00:00","breadcrumb":{"@id":"https:\/\/voxpria.com\/fr\/docs\/code-examples\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/voxpria.com\/fr\/docs\/code-examples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/voxpria.com\/fr\/docs\/code-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/voxpria.com\/fr\/home\/"},{"@type":"ListItem","position":2,"name":"Docs","item":"https:\/\/voxpria.com\/fr\/docs\/"},{"@type":"ListItem","position":3,"name":"Exemples de code"}]},{"@type":"WebSite","@id":"https:\/\/voxpria.com\/fr\/#website","url":"https:\/\/voxpria.com\/fr\/","name":"Ai voice automation system - Voxpria","description":"Ai voice automation system","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/voxpria.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/voxpria.com\/fr\/#organization","name":"VoxPria","url":"https:\/\/voxpria.com\/fr\/","logo":{"@type":"ImageObject","url":"https:\/\/voxpria.com\/fr\/wp-content\/uploads\/2026\/02\/voxpria-logo.png"},"description":"VoxPria est une plateforme d'agents vocaux IA qui automatise les appels t\u00e9l\u00e9phoniques entrants et sortants \u2014 ventes, soutien, prise de rendez-vous et qualification de prospects \u2014 dans n'importe quelle langue, 24\/7.","foundingLocation":{"@type":"Place","address":{"@type":"PostalAddress","addressLocality":"Montr\u00e9al","addressRegion":"QC","addressCountry":"CA"}},"areaServed":"Worldwide","contactPoint":{"@type":"ContactPoint","contactType":"sales","email":"support@voxpria.com","availableLanguage":["en","fr"]}},{"@type":"SoftwareApplication","@id":"https:\/\/voxpria.com\/fr\/#software","name":"VoxPria","applicationCategory":"BusinessApplication","applicationSubCategory":"AI Voice Agent \/ Call Automation","operatingSystem":"Web, Cloud","url":"https:\/\/voxpria.com\/fr\/","publisher":{"@id":"https:\/\/voxpria.com\/fr\/#organization"},"offers":{"@type":"Offer","price":"0","priceCurrency":"USD","description":"Free tier \u2014 no credit card required"},"featureList":["AI voice agents","Outbound & inbound calling","Campaign manager","Flow builder","CRM","WhatsApp","Appointment booking","SIP trunks","REST API"]}]}},"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/docs\/15633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/comments?post=15633"}],"version-history":[{"count":0,"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/docs\/15633\/revisions"}],"wp:attachment":[{"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/media?parent=15633"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/doc_category?post=15633"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/voxpria.com\/fr\/wp-json\/wp\/v2\/doc_tag?post=15633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}