Giter VIP home page Giter VIP logo

Comments (15)

Michaelmwirigi avatar Michaelmwirigi commented on July 19, 2024

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.

raphaelchaula avatar raphaelchaula commented on July 19, 2024

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.

Michaelmwirigi avatar Michaelmwirigi commented on July 19, 2024

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.

raphaelchaula avatar raphaelchaula commented on July 19, 2024

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.

raphaelchaula avatar raphaelchaula commented on July 19, 2024

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.

Michaelmwirigi avatar Michaelmwirigi commented on July 19, 2024

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.

raphaelchaula avatar raphaelchaula commented on July 19, 2024

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.

Michaelmwirigi avatar Michaelmwirigi commented on July 19, 2024

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.

raphaelchaula avatar raphaelchaula commented on July 19, 2024

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.

Michaelmwirigi avatar Michaelmwirigi commented on July 19, 2024

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.

raphaelchaula avatar raphaelchaula commented on July 19, 2024

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.

aksalj avatar aksalj commented on July 19, 2024

Hey @raphaelchaula

...the africastalking authentication isn't valid inside it

What do you mean by that?

from africastalking-node.js.

raphaelchaula avatar raphaelchaula commented on July 19, 2024

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.

aksalj avatar aksalj commented on July 19, 2024

This SDK simply POSTs 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.

DamianoSilverhand avatar DamianoSilverhand commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.