Generating invoice in django with Shiprocket API

I'm trying to generate invoice of my order in django with shiprocket API. So far I'm getting success Response but the generated URL of PDF is somewhat not understandable.

#Response Im getting

"{\"is_invoice_created\":true,
\"invoice_url\":\"https:\/\/s3-ap-south-1.amazonaws.com\/kr-shipmultichannel-mum\/3116291\/invoices\/Retail000058ba9b309-c4bd-4c06-ba15-2cc76b7c5d1f.pdf\",
\"not_created\":[],\"irn_no\":\"\"}"

when I try to access above URL get - Access-Denied

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>94ARWRYHGSBEZEH1</RequestId>
<HostId>j32LvksmWatylm3TdFGYuJ1qvBwJ39Lj+qIbbQ3CC7AEcrgHnOYGd9fDocMeEwDD4GpzjXQLQhg=</HostId>
</Error>

This is the way I want the url to be

https://s3-ap-south-1.amazonaws.com/kr-shipmultichannel-mum/3116291/invoices/Retail000058ba9b309-c4bd-4c06-ba15-2cc76b7c5d1f.pdf

When I remove the slashed I get in Response I'm able to download the PDF and that's done manually. So how do I get working URL.

#Views.py

class GenerateInvoice(APIView):

    def post(self, request):
        order_id = request.query_params.get("ids", None)
        print(order_id)
        data = json.dumps({"ids": [order_id]})
        headers = {
            "Content-Type": "application/json",
            "Authorization": settings.SHIPROCKET_TOKEN,
        }
        url = "https://apiv2.shiprocket.in/v1/external/orders/print/invoice"

        response = requests.post(url=url, data=data, headers=headers)

        return Response(response)

I think the result is response object. Try adding these

response = json.loads(response.decode("utf-8"))

Back to Top