I’m trying to get the cities from Romania using the countriesnow api, however, I am always receiving the following message:
{"error":true,"msg":"missing param (country)"}
I’ve followed the documentation for axios, but it doesn’t seem to work.
This is my code:
var data = '{\n "country": "romania"\n}';
axios({
method: 'post',
headers: {},
url: 'https://countriesnow.space/api/v0.1/countries/cities',
data: data
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});
It however works with postman:
>Solution :
var data = {
country: "romania"
};
And the same to all.
If it doesn’t work for you, I suggest to append the data to form data like the following.
const data = new FormData();
data.append('country','romania');
// same
Please refer to this.
https://masteringjs.io/tutorials/axios/axios-multi-form-data#:~:text=To%20send%20multipart%20form%20data,using%20the%20append()%20method.