I'm trying to get the data output I have, saved as an xlsm or csv file, but I don't grasp how I do that. The code include one of my attempts
import requests
import xlsxwriter
BASE_URL = 'https://restapi.e-conomic.com/'
HEADERS = {
'X-AgreementGrantToken': 'demo',
'X-AppSecretToken': 'demo',
'Content-type': 'application/json'
}
def get_invoice():
url = "{0}/{1}".format(BASE_URL, 'invoices/booked')
resp = requests.get(url, headers=HEADERS)
print(resp)
print(resp.json())
workbook = xlsxwriter.Workbook('demo1.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write(1, 1, resp)
workbook.close()
if __name__ == "__main__":
get_invoice()
Can anyone tell me, what I'm doing wrong?
* EDIT *
Hello again guys and girls,
I've gotten a little further than yesterday, by following this answer to a question
import requests
import json
import csv
BASE_URL = 'https://restapi.e-conomic.com/'
HEADERS = {
'X-AgreementGrantToken': 'demo',
'X-AppSecretToken': 'demo',
'Content-type': 'application/json'
}
def get_invoice():
url = "{0}/{1}".format(BASE_URL, 'invoices/booked')
resp = requests.get(url, headers=HEADERS)
whale = (resp.json)
print(resp)
print(whale())
output_fil = 'blab.csv'
horse = len(whale) - 1
data_til_fil = open(output_fil, 'w', newline='')
csv_writer = csv.writer(data_til_fil, delimiter=";")
csv_writer.writerow(["bookedInvoiceNumber","date","netAmount","vatAmount","grossAmount","dueDate"])
for i in range(0, horse):
meetup = whale[i]
bookedInvoiceNumber = meetup['bookedInvoiceNumber']
date = meetup['date']
netAmount = meetup['netAmount']
vatAmount = meetup['vatAmount']
grossAmount = meetup['grossAmount']
dueDate = meetup['dueDate']
csv_writer.writerow([bookedInvoiceNumber,date,netAmount,vatAmount,grossAmount,dueDate])
data_til_fil.close()
if __name__ == "__main__":
get_invoice()
I have however still trouble with getting it to work, as it doesn't like my
horse = len(whale) - 1
line. Python responds with
TypeError: object of type 'method' has no len()
Is there anyone here who are patient enough to help me with this? I can say, a lot of people who uses e-conomic, would appreciate it, now and in the future. :-)