我已经提出了 2 个请求..,但我想使用每个响应中的 id 发出一个补丁请求......
另一个将放在第一个中,第二个将放在数据中
我们可以将它传递给 var 吗?idk怎么做..
作为参考,我使用 gatsbyjs 和 directusCMS
let url3 = `${process.env.GATSBY_DIRECTUS_API_URL}/gemaclc/items/pendaftar/:id (the id should be from the first response that we just made)?access_token=${process.env.GATSBY_DIRECTUS_TOKEN}`;
axios.patch(url3, data, {
data: JSON.stringify(
{
featured_image: 1 (id of the second response whcih is an image),
}),
})
event.preventDefault();
const data = new FormData()
data.append('file', this.state.selectedFile)
console.warn(this.state.selectedFile);
console.log(data);
// console.log("User Email :" + this.state.email)
// console.log("User nama :" + this.state.name)
// console.log("User telepon :" + this.state.telepon)
// console.log("User program :" + JSON.stringify([this.state.program]))
// console.log("User tanggal :" + this.state.tanggal_lahir)
// console.log("User tempat :" + this.state.tempat_lahir)
let url = `${process.env.GATSBY_DIRECTUS_API_URL}/gemaclc/items/pendaftar?access_token=${process.env.GATSBY_DIRECTUS_TOKEN}`;
let url2 = `${process.env.GATSBY_DIRECTUS_API_URL}/gemaclc/files?access_token=${process.env.GATSBY_DIRECTUS_TOKEN}`;
let url2 = `${process.env.GATSBY_DIRECTUS_API_URL}/gemaclc/files?access_token=${process.env.GATSBY_DIRECTUS_TOKEN}`;
axios(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
data: JSON.stringify({
status:"published",
nama: this.state.name,
// email: this.state.email,
// telepon: this.state.telepon,
// program: [1],
// tanggal_lahir: this.state.tanggal_lahir,
// tempat_lahir: this.state.tempat_lahir,
})
})
.then(res => {
console.log(res)
return axios.post(url2, data, {
data: JSON.stringify(
{
data: data,
}),
})
})
.then(res => {
console.log(res.data.data.id)
return axios.patch( url3, {
})
})
.catch(error => {
console.log(error)
});