简体   繁体   中英

How can I send a post request to another API from my own application

urls.py

urlpatterns = [
    path('create_item/', CreateItem.as_view()),
]

serializers.py

class ParentReferans(serializers.Serializer):
    name = serializers.CharField()
    value = serializers.IntegerField()
class ItemSerializer(serializers.Serializer):

    SubItem = serializers.BooleanField()
    Type = serializers.CharField()
    Name = serializers.CharField()
    ParentRef = ParentReferans(many=True, read_only=True)

views.py

class CreateItem(views.APIView):

    def post(self, request):

        response = requests.post('https://sandbox-quickbooks.api.intuit.com/v3/company/4620816365135062310/item?minorversion=4', data=request.data)

        serializer = ItemSerializer(data=request.data)
        if serializer.is_valid():
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

I want to send post request to ( https://sandbox-quickbooks.api.intuit.com/v3/company/4620816365135062310/item?minorversion=4 ) address. But I could not come to a conclusion about what I could do. How should I go about this problem?

response = requests.post(url,params={"paramName": "paramValue"}) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM