- find your credentials http://ap.bandwidth.com/docs/security/
- Replace from number with a Bandwidth Phone Number on your account
- Any valid media can be passed as array
curl -v -X POST https://api.catapult.inetwork.com/v1/users/{user-id}/messages \
-u {token}:{secret} \
-H "Content-type: application/json" \
-d '{"from": "+12018994225", "to": "+12223334444", "text": "Hello there from Bandwidth!", "media":["https://s3.amazonaws.com/bwdemos/logo.png"]}'
NOTE THAT MMS AND DLR ARE NOT COMPATABLE
- Add
receiptRequested
andcallbackUrl
- Use Request Bin to see status as example
curl -v -X POST https://api.catapult.inetwork.com/v1/users/{user-id}/messages \
-u {token}:{secret} \
-H "Content-type: application/json" \
-d '{"from": "+12018994225", "to": "+19197891146", "text": "Hello there from Bandwidth!", "receiptRequested":"all", "callbackUrl":"http://requestb.in/1hfrdc31"}'
- Uses the Node SDK
- NPM Install
npm install --save node-bandwidth
- set the client object or globally
//Using client directly
var client = new bandwidth.Client("userId", "apiToken", "apiSecret");
//Or you can use default client instance.
//Do that only once
bandwidth.Client.globalOptions.apiToken = "token";
bandwidth.Client.globalOptions.apiSecret = "secret";
bandwidth.Client.globalOptions.userId = "userId";
var message = {
from: "+19195551212",
to: "+191955512142",
text: "Test"
};
bandwidth.Message.create(message, function(err, message){
//Traditional call back style
if (err) {
console.log(err);
}
else {
console.log(message);
}
});
npm install --save bluebird
var Promise = require("bluebird");
var bandwidth = require("node-bandwidth");
Promise.promisifyAll(bandwidth.Message);
bandwidth.Client.globalOptions.apiToken = "token";
bandwidth.Client.globalOptions.apiSecret = "secret";
bandwidth.Client.globalOptions.userId = "userId";
var message = {
from: "+19195551212",
to: "+191955512142",
text: "Test"
};
bandwidth.Message.createAsync(message)
.then(function (message) {
console.log(message);
})
.catch(function (err) {
console.log(err);
})
- Be sure to add callbackUrl!
var message = {
from: "+19195551212",
to: "+191955512142",
text: "Test",
receiptRequested: "all",
callbackUrl: "http://requestb.in"
};
bandwidth.Message.create(message, function(err, message){
//Traditional call back style
if (err) {
console.log(err);
}
else {
console.log(message);
}
});
- Either Catapult media URL or valid media URL
var message = {
from: "+19195551212",
to: "+191955512142",
text: "Test",
media: ["https://s3.amazonaws.com/bwdemos/logo.png"]
};
bandwidth.Message.create(message, function(err, message){
//Traditional call back style
if (err) {
console.log(err);
}
else {
console.log(message);
}
});