Python Forum
Failure in the Code to integrate via API Holded (accounting system) to Excel.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Failure in the Code to integrate via API Holded (accounting system) to Excel.
#1
My code fails and I can't find or fix the errors, could you help me please.

import requests
import pandas as pd

# URL para obtener el access token
auth_url = 'https://api.holded.com/identity/token'

# URL para obtener las cuentas contables
accounts_url = 'https://api.holded.com/core/accounting/accounts'

# URL para obtener los movimientos de una cuenta contable
account_movements_url = 'https://api.holded.com/core/accounting/accounts/{}/movements'

# Tus credenciales de la API
client_id = 'API'
client_secret = 'API'

# Datos para obtener el access token
auth_data = {
    'grant_type': 'client_credentials',
    'client_id': client_id,
    'client_secret': client_secret
}

# Obtenemos el access token
auth_response = requests.post(auth_url, data=auth_data)
access_token = auth_response.json()['access_token']

# Preparamos el header para las peticiones a la API
accounts_header = {'Authorization': f'Bearer {access_token}'}

# Obtenemos las cuentas contables
accounts_response = requests.get(accounts_url, headers=accounts_header)
accounts_data = accounts_response.json()['data']

# Inicializamos un dataframe para almacenar los movimientos de las cuentas contables
movements = pd.DataFrame()

# Recorremos las cuentas contables y obtenemos sus movimientos
for account in accounts_data:
    account_movements_response = requests.get(account_movements_url.format(account['id']), headers=accounts_header)
    account_movements_data = account_movements_response.json()['data']
    account_movements_df = pd.json_normalize(account_movements_data)
    account_movements_df['account_name'] = account['name']
    movements = movements.append(account_movements_df, ignore_index=True)

# Exportamos los movimientos a un archivo de Excel
movements.to_excel('movimientos_contables.xlsx', index=False)
buran write May-10-2023, 01:18 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
(May-10-2023, 01:08 PM)maicolvela Wrote: My code fails and I can't find or fix the errors, could you help me please.
We really don't know what errors you get, because we cannot run your code - it requires API credentials. Please, elaborate what does "my code fails" mean exactly.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failure to send verification code okdude2124 0 2,044 Mar-22-2021, 07:40 PM
Last Post: okdude2124
  Requests login failure test 10 9,704 Sep-13-2018, 08:48 AM
Last Post: test
  How to integrate a python algorithm in a Django website daekch 2 5,336 Mar-21-2017, 10:58 AM
Last Post: Jeanne

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020