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


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.
<Message>Access Denied</Message>

This is the way I want the url to be

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.

class GenerateInvoice(APIView):

    def post(self, request):
        order_id = request.query_params.get("ids", None)
        data = json.dumps({"ids": [order_id]})
        headers = {
            "Content-Type": "application/json",
            "Authorization": settings.SHIPROCKET_TOKEN,
        url = ""

        response =, 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