首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >条目保存,但数据不保存在Strapi 4内容类型中。

条目保存,但数据不保存在Strapi 4内容类型中。
EN

Stack Overflow用户
提问于 2022-11-10 14:12:19
回答 1查看 24关注 0票数 0

通过Strapi admin,我创建了一个名为"Events“的内容类型,并创建了一些条目。这些条目是我在strapi admin中创建的,它们被完美地保存并提交到后端sqlite数据库中。

但是,当我通过我的程序提出一个帖子请求时,条目会被保存,但是数据不会被保存。或者,即使我通过postman发出了一个post请求,条目也会被保存,但是数据不会保存在新条目中。

我的javascript程序如下:

代码语言:javascript
运行
复制
const axios = require('axios')
const URL ='http://localhost:1337/api/events'

const obj = {
    data : {
        attributes: {
            name: 'test',
            venue : 'town hall',
            address : 'test',
            date : '2022-11-20',
            time : '10 pm',
            performers : 'test',
            description : 'test from js programme',
            user : 'test'
        }
    }
}

axios({
    method: 'post',
    url: URL,
    data: obj
}).then((res)=>console.log(res.data)).
catch ((err)=> console.log(err.message))

/*  response received is as under with 
    status code 200 on strapi server side

{
data: {
    id: 57,
    attributes: {
    name: null,
    slug: null,
    venue: null,
    address: null,
    date: null,
    time: null,
    performers: null,
    description: null,
    createdAt: '2022-11-10T13:24:26.335Z',
    updatedAt: '2022-11-10T13:24:26.335Z',
    publishedAt: '2022-11-10T13:24:26.332Z'
    }
},
meta: {}
}

*/

我的邮递员请求的屏幕截图如下:

令人惊讶的是,后端控制台显示响应代码200。该条目被保存,但数据未以内容类型保存。

内容类型"Events“的所有CRUD权限都是公共的。我不知道我在这里做了什么错事。

社区,请帮助我,在我的学习。

EN

回答 1

Stack Overflow用户

发布于 2022-11-12 04:54:48

你也许应该

代码语言:javascript
运行
复制
const obj = {
    data : {
        attributes: {
            name: 'test',
            venue : 'town hall',
            address : 'test',
            date : '2022-11-20',
            time : '10 pm',
            performers : 'test',
            description : 'test from js programme',
            user : 'test'
        }
    }
}

代码语言:javascript
运行
复制
const obj = {
    data : {
            name: 'test',
            venue : 'town hall',
            address : 'test',
            date : '2022-11-20',
            time : '10 pm',
            performers : 'test',
            description : 'test from js programme',
            user : 'test'
        }
}

请看这里的文档:https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest-api.html#create-an-entry

在post请求中,不需要将数据放在attributes键中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74390425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档