Skip to content

POST list data returns "Received data is not a valid JSONAPI Resource Identifier Object" #838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
skonik opened this issue Oct 13, 2020 · 1 comment

Comments

@skonik
Copy link

skonik commented Oct 13, 2020

Hi there.

I have API endpoint which receives list of items. I need an array of items as input

    @action(detail=False, methods=['post'])
    def some_action(self, request, pk=None):
       serializer = PersonSerializer(data=request.data, many=True)

But when I try to post data in such way:

{
    "data": [
        {
            "type": "person",
            "id": "508",
            "attributes": {
                "name": "test1"
            }
        },
        {
            "type": "person",
            "id": "431",
            "attributes": {
                "name": "test2"
            }
        }
    ]
}

I always get this error:

{
    "errors": [
        {
            "detail": "Received data is not a valid JSONAPI Resource Identifier Object",
            "status": "400",
            "source": {
                "pointer": "/data"
            },
            "code": "parse_error"
        }
    ]
}

How could I pass this error?
Is it possible to send an array of data?

@skonik skonik changed the title POST list data returns Received data is not a valid JSONAPI Resource Identifier Object POST list data returns "Received data is not a valid JSONAPI Resource Identifier Object Oct 13, 2020
@skonik skonik changed the title POST list data returns "Received data is not a valid JSONAPI Resource Identifier Object POST list data returns "Received data is not a valid JSONAPI Resource Identifier Object" Oct 13, 2020
@sliverc
Copy link
Member

sliverc commented Oct 14, 2020

json:api spec doesn't support bulk creation in the current version. There is a workaround you might use which is outlined here.

Closing this issue. Feel free to comment though in case question remains.

@sliverc sliverc closed this as completed Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants