Skip to content Skip to sidebar Skip to footer

How To Get "pdf" File From The Binary Data Of Softlayer's Quote?

I got the binary data by 'getPdf' method of SoftLayer's API. Ref. BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer Development Network - http://sldn.softlayer.com/reference

Solution 1:

the method return a binary data encoded in base 64, what you need to do is decode the binary data.

see this article about enconde and decode binary data.

https://code.tutsplus.com/tutorials/base64-encoding-and-decoding-using-python--cms-25588

the Python client returns a xmlrpc.client.Binary object so you need to work with that object here an example using the Python client and Python 3

#!/usr/bin/env pythonimport SoftLayer
import xmlrpc.client
import base64
import os

USERNAME = 'set me'
API_KEY = 'set me'

quoteId = 1560845

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)

accountClient = client['SoftLayer_Billing_Order_Quote']
binaryData = accountClient.getPdf(id=quoteId)
decodeBinary = binaryData.data
file = open('test.pdf','wb')
file.write(decodeBinary)

Regards

Solution 2:

This is my answer fo my question.

# import
import SoftLayer
import sys
parm=sys.argv
quoteId=parm[1]

# account info
client = SoftLayer.create_client_from_env()

# getPdf as a binary data
getPdf = client['Billing_Order_Quote'].getPdf(id=quoteId)

# Save as a PDF
quoteFileName = "Quote_ID_%s.pdf" % quoteId
w = open(quoteFileName, "wb")
w.write(getPdf.data)
w.close()

Post a Comment for "How To Get "pdf" File From The Binary Data Of Softlayer's Quote?"