Have a weird one
I have some code I wrote in Xojo thats basically a translation of some JS code - see below
But it gave me errors for reasons I couldn’t fathom
So I used RapidApi (formerly PAW) to test the same API
When I fill out what I need it generates a call using CURL
I get the following CURL invocation
curl -X “POST” “``https://graph.facebook.com/v24.0/958069794056499/media``”
-H ‘Authorization: Bearer EAAlZAJ8PZBulkBQr8Sr8eKMBM188ZBeAxPm6GXbKoPnjqKryAMFItZBkDNKUSVJMe7AOCkCmcx98ZCowIZAW15NJqQo4UOMKgTnpnLkYWujq93yUvCeGLag3dP7PhZC41TpKo0jbYCtxd0B6XxeeIihvRnqafLPqkHZChWEwX2141ohZBLv6S6s3b6g2LzXy2ISYtAY1FeZCy8xfSXZBhNZB8mhoa5f7S1RstIWLq77evO2B1MhvYnDEJDrpmFeE1IZCXeWzkn8ZAfmTJRhMknnMxFxGWccdlZC5cxaTggXBA4F’
-H ‘Content-Type: multipart/form-data’
-F “file=@/Users/npalardy/Desktop/dF8Jup.jpg”
-F “type=image/jpeg”
-F “messaging_product=whatsapp”
and I get a result like
{“id”:“2966336126899864”}
So far YAY !
Then I have Rapid API generate it as JS
import (“https://code.jquery.com/jquery-3.6.3.min.js”) ;
var formData = new FormData();
formData.append(“file”, “@/Users/npalardy/Desktop/dF8Jup.jpg”);
formData.append(“type”, “image/jpeg”);
formData.append(“messaging_product”, “whatsapp”);
jQuery.ajax({
url: “https://graph.facebook.com/v24.0/958069794056499/media”,
type: “POST”,
headers: {
“Authorization”: “Bearer EAAlZAJ8PZBulkBQr8Sr8eKMBM188ZBeAxPm6GXbKoPnjqKryAMFItZBkDNKUSVJMe7AOCkCmcx98ZCowIZAW15NJqQo4UOMKgTnpnLkYWujq93yUvCeGLag3dP7PhZC41TpKo0jbYCtxd0B6XxeeIihvRnqafLPqkHZChWEwX2141ohZBLv6S6s3b6g2LzXy2ISYtAY1FeZCy8xfSXZBhNZB8mhoa5f7S1RstIWLq77evO2B1MhvYnDEJDrpmFeE1IZCXeWzkn8ZAfmTJRhMknnMxFxGWccdlZC5cxaTggXBA4F”,
“Content-Type”: “multipart/form-data”,
},
processData: false,
contentType: false,
data: formData,
})
.done(function(data, textStatus, jqXHR) {
console.log("HTTP Request Succeeded: " + jqXHR.status);
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(“HTTP Request Failed”);
console.log(jqXHR) ;
})
.always(function() {
/* … */
});
I test this in RunJS online
But this time I get
Promise { }
{
readyState: 1,
getResponseHeader: [Function: getResponseHeader],
getAllResponseHeaders: [Function: getAllResponseHeaders],
setRequestHeader: [Function: setRequestHeader],
overrideMimeType: [Function: overrideMimeType],
statusCode: [Function: statusCode],
abort: [Function: abort],
state: [Function: state],
always: [Function: always],
catch: [Function: catch],
pipe: [Function: pipe],
then: [Function: then],
promise: [Function: promise],
progress: [Function: add],
done: [Function: add],
fail: [Function: add]
}
‘HTTP Request Failed’
{
readyState: 4,
getResponseHeader: [Function: getResponseHeader],
getAllResponseHeaders: [Function: getAllResponseHeaders],
setRequestHeader: [Function: setRequestHeader],
overrideMimeType: [Function: overrideMimeType],
statusCode: [Function: statusCode],
abort: [Function: abort],
state: [Function: state],
always: [Function: always],
catch: [Function: catch],
pipe: [Function: pipe],
then: [Function: then],
promise: [Function: promise],
progress: [Function: add],
done: [Function: add],
fail: [Function: add],
responseText: '{
’ +
’ “error”: {
’ +
’ “message”: “(#100) The parameter messaging_product is required.”,
’ +
’ “type”: “OAuthException”,
’ +
’ “code”: 100,
’ +
’ “fbtrace_id”: “A6ziDy4fz48k2lZtqcHXE4i”
’ +
’ }
’ +
‘}’,
responseJSON: {
error: {
message: ‘(#100) The parameter messaging_product is required.’,
type: ‘OAuthException’,
code: 100,
fbtrace_id: ‘A6ziDy4fz48k2lZtqcHXE4i’
}
},
status: 400,
statusText: ‘error’
}
One works
the other two dont
I cant figure out why
Anyone got ANY ideas ?