I am trying to run the following code through a script on Backendless: But I keep getting a “ReferenceError: PublishOptions is not defined” error. I assume the Javascript Backendless SDK are imported by default?
How can I solve this?
var channel = “TestChannel”, message = “Hello, world!”, pubOps = new PublishOptions({ headers: { city: “Denver”, state: “Colorado” } }), success = function (response) { /* … / }, failure = function (response) { / … */ };Backendless.Messaging.publish( channel, message, pubOps, null, new Backendless.Async(success, failure));
Hi Stig,
This is definitely a bug, you cannot create PublishOptions like this now.
I created a task for the developer to fix it asap.
We shall inform you when it is ready.
Thanks!
Hi Stig,
thank you for your patience.
We have fixed this issue already. Please, update to latest version of SDK and try it out again. Let us know if you have any problems further.
Regards,
Stanislav
Hi
Still not working. I place my script in the files folders on Backendless.
exports.run = function( request, response ) {
var channel = "TestChannel",
message = "Hello, world!",
pubOps = new PublishOptions({
headers: {
city: "Denver",
state: "Colorado"
}
}),
success = function (response) {
/* ... */
},
failure = function (response) {
/* ... */
};
Backendless.Messaging.publish(
channel,
message,
pubOps,
null,
new Backendless.Async(success, failure)
);
}
Sorry, I was thinking you are using it locally. In fact, it’s fixed, but it takes 1-2 days to appear in our nodejs service. So once it appear there, I’ll let you know immediately.
You can check the code below running it locally:
var Backendless = require('backendless');
var APPLICATION_ID = ''your app id;
var SECRET_KEY = ''your secret key;
var VERSION = 'v1';
Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);
var channel = "TestChannel",
message = "Hello, world!",
pubOps = new PublishOptions({
headers: {
city : "Denver",
state: "Colorado"
}
}),
success = function(res) {
console.log(res);
},
failure = function(res) {
console.log(res);
};
Backendless.Messaging.publish(channel, message, pubOps, null, new Backendless.Async(success, failure));
Regards,
Stanislav
Hi again,
the fix is already in production. Please, try again. Let me know please if everything’s okay now.
Regards,
Stanislav