0

My API looks something like this https://customerlink.org/api/data?email="

I have no problem using it with postman, I just need to encode the query string(email), as ‘@’ is not a valid character.

I used a website to encode the email and it worked with no problem. I used Postman and add the Basic Auth credentials

however I am confused on how to add the email part and how to encode it from my react app.

var api_url = "https://customerlink.org/api/data?email="
var email = "testemail@gmail.com"
var username = 'username';
var password = 'password';
var basicAuth = 'Basic ' + btoa(username + ':' + password);

axios.post(api_url + email, {}, {
headers: { 'Authorization': + basicAuth }
}).then(function(response) {
    console.log('Authenticated');
}).catch(function(error) {
console.log('Error on Authentication');
});
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129

1 Answers1

0

You can use encodeURI(uri) if you need to, but the @ symbol can be used in a query string just fine.

let uri = "https://customerlink.org/api/data?email=my@email.com"
let encodedUri = encodeURI(uri);
SweetCoco
  • 91
  • 1
  • 7