Send fax with OVH API from Google Script. Error: [recipients] phoneNumber Data is not a
... / Send fax with OVH API fro...
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
Question

Send fax with OVH API from Google Script. Error: [recipients] phoneNumber Data is not a

by
AdrienS13
Created on 2021-09-27 05:56:06 (edited on 2024-09-04 11:19:01) in SMS Pro

Bonjour à la communauté,

Je souhaite appeler l'API OVH depuis un google script. Cette dernière version fonctionne en 'GET' et en 'POST'. Je n'ai enfin plus de "Invalid signature". J'ai trouvé comment passer les paramètres BODY. Mais j'ai maintenant une dernière erreur que je n'arrive pas à passer : "[recipients] phoneNumber Data is not an array for an array type".

Pourtant le recipients semble bien être un array :

`$body = 'pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=[ "0033972152245" ]'`

Mon google script est ci-dessous.

function ovh_api() {

/** to be changed by your account data */
$billingAccount= 'saxxxxxxx-ovh-1' //has to finised by '-ovh-1' or '-ovh-2' or '-ovh-3'...
$serviceName= '00339xxxxxxxx' //your fax number

/** "documentation" is here:
https://api.ovh.com/console/#/telephony/%7BbillingAccount%7D/fax/%7BserviceName%7D/settings/sendFax#POST
*/
$url = 'https://eu.api.ovh.com/1.0/telephony/'+$billingAccount+'/fax/'+$serviceName+'/settings/sendFax'
$method = 'POST'
$body = 'pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=[ "0033972152245" ]'

/** All those $body failed with same message "phoneNumber Data is not an array for an array type"
$body='pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=%5B0033972152245%5D'
$body = 'pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=[ "+33972152245" ]'
$body='pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=[0033972152245]'
$body='pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=["0972152245"]'
$body='pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=[0972152245]'
$body='pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients="[0033972152245]"'
$body='pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients="["0033972152245"]"'
$body='pdfUrl="http://www.africau.edu/images/default/sample.pdf"&recipients=0033972152245'
*/

/** to be changed by your own keys */
$ApplicationKey = 'xxx'
$ApplicationSecret = 'xxx'
$consumerKey = 'xxx'

$timestamp = UrlFetchApp.fetch('https://eu.api.ovh.com/1.0/auth/time')

/** hash documentation is here
https://docs.ovh.com/asia/en/api/first-steps-with-ovh-api
*/
$hash = "$1$"+makeSha1Hex($ApplicationSecret+"+"+$consumerKey+"+"+$method+"+"+$url+"+"+$body+"+"+$timestamp)

var response = UrlFetchApp.fetch($url, {
"method": $method,
"headers": {"X-Ovh-Application": $ApplicationKey, "X-Ovh-Signature": $hash, "X-Ovh-Consumer": $consumerKey, "X-Ovh-Timestamp": $timestamp},
"payload": $body
})
Logger.log(response)
}


/** Below are 3 functions to make SHA1 */
function makeSha1Hex (content) {
return byteToHexString(Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, content));
}
function byteToHexString (bytes) {
return bytes.reduce(function (p,c) {
return p += padLeading ((c < 0 ? c+256 : c).toString(16), 2 );
},'');
}
function padLeading (stringtoPad , targetLength , padWith) {
return (stringtoPad.length < targetLength ? Array(1+targetLength-stringtoPad.length).join(padWith | "0") : "" ) + stringtoPad ;
}


1 Reply ( Latest reply on 2021-09-27 05:56:44 by
AdrienS13
)

Merci mille fois d'avance pour votre aide :)