I use axios version 0.13.1 and if I want to get data with orderBy and limitToFirst parameters, I got 400 Bad request error.
With this http request I get 400 error:
axios({
method: 'get',
url: 'https://tracker-ag.firebaseio.com/groups.json',
params: {
auth: AccessStore.getToken(),
orderBy: "$key",
limitToFirst: 2,
}
}).then(function (response) {
responseHandler(USERS_GET, '', response.data);
})
.catch(function (error) {
console.log("Error during fetching data " + error.message);
});
This http request without orderBy and limitToFirst parameters works:
axios({
method: 'get',
url: 'https://tracker-ag.firebaseio.com/groups.json',
params: {
auth: AccessStore.getToken(),
}
}).then(function (response) {
responseHandler(USERS_GET, '', response.data);
})
.catch(function (error) {
console.log("Error during fetching data " + error.message);
});
Related
There are the errors
Theses are the errors.
componentDidMount() {
const options = {
method: 'GET',
url: 'https://timetable-lookup.p.rapidapi.com/TimeTable/BOS/LAX/20191217/',
headers: {
'X-RapidAPI-Key': 'SIGN-UP-FOR-KEY',
'X-RapidAPI-Host': 'timetable-lookup.p.rapidapi.com'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
}
i am trying to fetch data for a flight booking system and getting this error.
I am trying to do a post request with axios but it does not work.
This is the request I want to do.
I tried like this:
await axios.post(
'https://api.searchads.apple.com/api/v4/campaigns/XXXX/adgroups/targetingkeywords/find',
{
headers: {
"Authorization": "Bearer " + accessToken,
"X-AP-Context": "orgId=XXXX"
},
data: data
});
try this
var config = {
method: 'post',
url: 'https://api.searchads.apple.com/api/v4/campaigns/{campaignId}/adgroups/targetingkeywords/find',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
I have form submit function with axios:
const onSub mit = (data) => {
const webhookUrl = 'MY URL';
const info = JSON.stringify(data);
axios({
method: 'post',
url: `${webhookUrl}`,
data: info,
config: { headers: { 'Content-Type': 'application/json' } },
})
.then(function (response) {
alert('Message Sent!');
})
.catch(function (response) {
//handle error
console.log(response);
});
};
and here is what i get after JSON.stringify inside info:
{"fullname":"Temirlan","email":"test#mail.com","phone":"0179890808","proffesion":false,"message":"test"}
This is what i get in my webhook after form is submitted which is wrong:
However if i use Thunder client and post same data:
I get it correctly:
What am i doing wrong?
So I used different approach with axios and it worked:
let axiosConfig = {
headers: {
'Content-Type': 'application/json;charset=UTF-8',
'Access-Control-Allow-Origin': '*',
},
};
axios
.post(webhookUrl, info, axiosConfig)
.then((res) => {
console.log('RESPONSE RECEIVED: ', res);
})
.catch((err) => {
console.log('AXIOS ERROR: ', err);
});
I'm dealing with Spotify's API but not succeed to automatically get a new access token.
function api() {
$.ajax({
type: 'POST',
url: 'https://accounts.spotify.com/api/token?grant_type=client_credentials',
headers: {
'Authorization': 'Basic myClientIdEncodedToBase64Format:myClientSecretEncodedToBase64Format'
},
success: function(data) {
console.log('Succes ->', data);
},
error: function(error) {
console.log('Error -> ', error);
}
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I'm getting a 400 error. If [i refer the doc][1], '400: Bad Request - The request could not be understood by the server due to malformed syntax. The message body will contain more information'.
What am i doing wrong here ?
Thanks !
Here my code. I add data :
function api() {
$.ajax({
type: 'POST',
url: 'https://accounts.spotify.com/api/token',
data: 'grant_type=client_credentials',
headers: {
'Authorization': 'Basic myClientIdAndMyClientSecretConvertedToBase64'
},
success: function(data) {
console.log('Succes ->', data);
},
error: function(error) {
console.log('Error -> ', error);
}
});
}
I am trying to upload 3 photos from frontend using formData. It will call an external API to make the upload. But encountered some errors as below.
Frontend upload
const formData = new FormData()
formData.append('photoA', this.photoA)
formData.append('photoB', this.photoB)
formData.append('photoC', this.photoC)
axios.post(`http://localhost:4172/uploadDocs`,
{
data: formData,
accessToken: store.state.token
},
{ headers: {
// 'Content-Type': 'Application/json',
// 'x-access-token': localStorage.getItem('token')
}
}
).then (function (response) {
return response.data
})
Nodejs upload API
async uploadDocs (req, res) {
const options = {
method: "POST",
url: "https://example.com/api/v1/users/uploadDocuments?access_token=" + req.body.accessToken,
headers: {
//"Authorization": "Basic " + auth,
//"Content-Type": "multipart/form-data"
},
data: req.body.data
};
try {
request(options, function (err,response,body){
if (err) {
res.send(err)
} else {
res.send(response.body)
}
})
} catch (error) {
res.status(400).send({
error: "Server error."
})
}
}
So there are 2 errors here:
a) Frontend error: It keeps giving Cannot POST / error in html
b) Backend error:
<h1>Cannot read property 'photoA' of undefined</h1>
<h2></h2>
<pre></pre>
Been struggling with this for days. Any help will be very much appreciated.