Django REST API accept list instead of dictionary in post request


I am trying to consume data from a callback API that sends the POST request in this format:

    "key1": "asd",
    "key2": "123"

However my API currently only works when it is sent like this:

  "key1": "asd",
  "key2": "123"

class RawIncomingDataSerializer(serializers.ModelSerializer):
    class Meta:
        model = RawIncomingData
        fields = '__all__'

class RawIncomingDataViewSet(viewsets.ModelViewSet):
    queryset = RawIncomingData.objects.all()
    serializer_class = RawIncomingDataSerializer

There will only ever be one object in the post data, so I am looking for a simple work around without having to rewrite my serializer to interpret multiple objects in one post request.


In that case you can override create and explicitly specify many=True in the get_serializer call:

class RawIncomingDataViewSet(viewsets.ModelViewSet):
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(, many=True)
        headers = self.get_success_headers(
        return Response(, status=status.HTTP_201_CREATED, headers=headers)

Answered By – Brian Destura

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published