You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于使用OVH SMS API(JavaScript)发送短信时部分号码报错的技术咨询

Troubleshooting "invalid receiver" Error with OVH SMS API in JavaScript

Hey there, let's work through why you're hitting that frustrating "invalid receiver" error when calling the OVH SMS API via JavaScript—especially since the same numbers work fine in the OVH client. Here are the most likely culprits to check:

1. Number Formatting Discrepancies

The OVH web client automatically normalizes phone number formats, but your JavaScript code might not be handling this. OVH's API strictly expects numbers in E.164 format (e.g., +33612345678 for French mobile numbers, not 0612345678 or 33612345678 without the plus sign).

A quick fix is to use a library like libphonenumber-js to standardize your input numbers:

import { parsePhoneNumberFromString } from 'libphonenumber-js';

// Example: Normalize a French number
const rawNumber = '0612345678';
const phoneNumber = parsePhoneNumberFromString(rawNumber, 'FR');
const standardizedNumber = phoneNumber.format('E.164'); // Returns "+33612345678"

Even if you're hardcoding numbers, double-check that every receiver includes the leading + and correct country code.

2. Incorrect Request Parameter Structure

OVH's SMS API expects the receiver parameter to be an array of strings, even if you're sending to a single number. It's easy to accidentally pass a plain string instead, which can trigger the "invalid receiver" error for certain number formats.

Bad:

const requestBody = {
  message: "Your notification text",
  receiver: "+33612345678" // Wrong: single string instead of array
};

Good:

const requestBody = {
  message: "Your notification text",
  receiver: ["+33612345678"] // Correct: array of numbers
};

You can also use your browser's developer tools to inspect the HTTP request the OVH client sends—compare its payload structure to what your JavaScript code is generating.

3. Unhandled Special Number Types

Some numbers (like virtual numbers, short codes, or VoIP numbers) might require additional permissions or specific formatting that the OVH client handles automatically, but your API call doesn't. For example:

  • Short codes (e.g., 12345) might need to be sent without a country code
  • Virtual numbers might require you to whitelist them in your OVH account settings

Check if all the failing numbers fall into a specific category, then reach out to OVH support to confirm if any account-level adjustments are needed.

4. Accidental Character Escaping

If you're using encodeURIComponent or similar functions to sanitize numbers, you might be escaping the + sign into %2B. While some APIs accept this, OVH's SMS API can be strict about the literal + prefix. Avoid encoding the phone number itself—only encode other parts of your request URL if necessary.

5. API Version or Endpoint Mismatch

Make sure your JavaScript code is using the same API version and endpoint as the OVH client. OVH has multiple SMS API versions (v1 and v2), and their parameter requirements differ slightly. For example, the v2 API uses the /sms/{serviceName}/jobs endpoint for batch sends, while v1 uses a different path. Cross-reference your request URL with OVH's official API documentation to confirm you're targeting the right endpoint.


内容的提问来源于stack exchange,提问作者Douglas Gentil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:06:53