Feb 20, 2022 11:40 PM
Hello, i tried the resp.json, resp, resp.text but the result of my api request hasn’t shown, sometimes it show the redirection:false when i use the resp.json and resp.text it show only “function”
const ws = "https://api.writesonic.com/v1/business/content/ai-article-writer-v2?&end_user_id=test1&engine=economy&language=en";
let config = {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-API-KEY': 'apikey'
},
body : JSON.stringify({
"article_title": atitle,
"article_intro": asection,
"article_sections": [
'Tourist information about the city of Vitrolles in the department of Bouches-du-Rhone 13',
'Tourist information about the city of Abbeville in the department of Somme 80',
'Tourist information about the city of Ablon-sur-Seine in the department of Val-de-Marne 94'
]
}),
data : data
};
try {
const resp = await remoteFetchAsync(ws, config);
console.log(resp.json);
}
catch(error) {
console.log('Error happened here!')
console.error(error)
}
Feb 27, 2022 06:06 AM
Try something like
const data = resp.json()
console.log(data)
Feb 27, 2022 09:37 PM
Hello, Thank you for the reply but i tried this one, it shown only the redirection : false error
Feb 28, 2022 07:55 AM
Does this support page help?
Feb 28, 2022 07:40 PM
No, Anyway Thank you for you replies i tried last night a different approach using await and call for a library that i’m missing. It works well now.
await getAxios()
async function getAxios() {
const response = await fetch("https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js");
const minifiedLibrary= await response.text();
eval(minifiedLibrary)
}
const ws = "https://api.writesonic.com/v1/business/content/ai-article-writer-v2?&end_user_id=test1&engine=economy&language=en";
// import axios from "axios";
let config = {
method: 'post',
url : "https://api.writesonic.com/v1/business/content/ai-article-writer-v2?&end_user_id=test1&engine=economy&language=en",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-API-KEY': 'apikey'
},
data : data
};
await axios(config).then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});