Comments (15)
Hello. Please make sure you have created a file in your test folder called fixtures.local
that has your username and apiKey from africastalking.
from africastalking-node.js.
I have keys in .env, must I put them in fixtures.local
I texted it in a simple npm project it send messages pretty fine, in expressjs I keep getting the error
from africastalking-node.js.
You don't have to put them in your fixtures.local. The example expects the variables from that file, unless you have changed that code.
So the sdk has no problem if it works in the first project, since the code used is the same. You'll need to share the expressjs code, so we can debug better.
The part with the problem is here;
const options = {
apiKey: 'YOUR_API_KEY',
username: 'YOUR_USERNAME',
};
const AfricasTalking = require('africastalking')(options);
from africastalking-node.js.
const smsOptions = {
apiKey: 'my_key',
username: 'my_app'
}
const AfricasTalking = require('africastalking')(smsOptions)
const sms = AfricasTalking.SMS
That is my smsOptions, is there any error noticiable?
from africastalking-node.js.
HERE IS ALL MY CODE
const smsOptions = {
apiKey: process.env.AFRICASTALKING_KEY,
username: process.env.AFRICASTALKING_USERNAME
}
const AfricasTalking = require('africastalking')(smsOptions)
sms = AfricasTalking.SMS
var text = {
to: [req.body.telephone],
message: Your confirmation code is ${code}
}
sms.send(text)
.then(response => {
var payload = {
userid: user._id,
telephone: user.telephone
}
return res.status(200).json({
message: 'user_created',
token: jwt.sign(payload)
})
})
.catch(error => {
console.log(error)
return res.status(500).json({
message: error
})
})
/ console.log(error) /
Gives "The supplied authentication is invalid"
from africastalking-node.js.
I have tested this code in an express app and the sms is sent, without a validation error.
I have also tested it in our documentation, where you can write code and test from your browser. An example can be found here. start the course and test your code from there.
I think the credentials may not be correct. Please also confirm the credentials used are correct.
from africastalking-node.js.
In express app I get the error, in simple node app, sms is sent pretty fine, the same code.
The same credentials are used, I believe credentials are correct, I keep confirming them since yesterday.
from africastalking-node.js.
Please log your smsOptions
and make sure the username and apiKey used are correct.
Also check this article on supplied authentication issues
from africastalking-node.js.
The same problem, smsOptions log the correct options, I don't get it, The same code works fine and sends sms to sandbox now I am in live environement, authentication is invalid, do you use some urls or whatever that is dependent of expressjs eg. config etc
I think I should know that.
from africastalking-node.js.
You've said this code works in sandbox but not in production? I am sure the credentials you are using are not correct, that is the error message you are getting after all. The same code used for sandbox is exactly the same as that of production, you don't need to set config for express. You only need to swap the username and apiKey used to the prod ones.
The article I sent earlier explains of the difference of the sandbox and the live environment.
from africastalking-node.js.
I figured out the problem,
The error happens when I use graphql server (Apollo-server-express)
So the africastalking authentication isn't valid inside it, you guys need to test it and update your sdk
Thanks!
from africastalking-node.js.
Hey @raphaelchaula
...the africastalking authentication isn't valid inside it
What do you mean by that?
from africastalking-node.js.
I mean whenever you use Africastalking sdk inside Queries or Mutations of Apollo-server-express the authentication becomes invalid.
You can test it and figure out what might be causing the problem.
from africastalking-node.js.
This SDK simply POST
s data and does not do any authentication... It could be that the value of either your app username or API key is changing before being sent by the SDK...
from africastalking-node.js.
I am experiencing the same error , using the sandbox environment. I am using a node expess backend system,
Check my code below
From server.js:
`const express = require("express");
const router = express.Router();
const dotenv = require("dotenv");
dotenv.config();
// Get authentication
const credentials = {
apiKey: process.env.apiKey, // use your sandbox app API key for development in the test environment
username: process.env.username // use 'sandbox' for development in the test environment
};
const AfricasTalking = require("africastalking")(credentials);
const sms = AfricasTalking.SMS;
// Send SMS route
router.post("/", (req, res) => {
const { to, message } = req.body || res.status(400).json({error: "Both 'to' and 'message' are required"});
sms
.send({ to, message, enque: true })
.then(response => {
console.log(response);
res.json(response);
})
.catch(error => {
console.log(error);
res.json(error.toString());
});
});
module.exports = router;`
app.js :
`const express = require("express");
const dotenv = require("dotenv");
const smsRoute = require("./server");
const bodyParser = require("body-parser");
dotenv.config();
const app = express();
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => console.log(running on localhost:${PORT}
));
app.use(bodyParser.json());
app.use("/", smsRoute);`
After posting the necessary data , to and message to the route, I get a "data: 'The supplied authentication is invalid' " error. I have tried regenerating the sandbox api key but still getting the same error. I also tried sending the data direct from postman by setting the necessary header for api key and sending the data in the correct format but even there I get the same error. What can be done to sort this one?
from africastalking-node.js.
Related Issues (20)
- destructuring an undefined key HOT 1
- Security Venerability HOT 1
- Update Premium Urls. HOT 1
- v0.5.0 may have breaking changes ..sendsms error HOT 1
- High vulnerability with [email protected] HOT 2
- Cannot read property 'send' of undefined HOT 2
- send different messages to different numbers simultaneously ? HOT 2
- Vulnerability Report on Axios HOT 2
- The supplied authentication is invalid HOT 2
- Support for multiple numbers & clientRequestId in voice sdk
- Installing africastalking using npm not working HOT 10
- Error: Attempt to change mapping for "form" extension from "application/x-www-form-urlencoded" to "application/x-www-form-urlencoded". Pass `force=true` HOT 3
- Cannot read property 'send' of undefined HOT 1
- Support for Deno HOT 1
- Broken links on README.md file
- Typescript support HOT 5
- Voice API `callTo` Parameter Only Initiates Call to Last Number in Array HOT 6
- Request for Contribution Guide HOT 3
- Updating dependencies
- SMS Message With A Different String Font Being Sent in a Cryptic Manner HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from africastalking-node.js.