# Python Integration

### Webhook

```markup
$ pip install Flask
```

{% code title="webhook.py" %}

```python
from flask import Flask, request, jsonify, make_response
import json, os


app = Flask(__name__)

@app.route('/data', methods = ['POST', 'GET'])
def data(): 
    data = request.json
    data_string = json.dumps(data)
    data_json = json.loads(data_string)
    print(data_json, file=open("output.txt", "a"))

    return make_response("",200)

if __name__ == "__main__":
    app.run(host = '127.0.0.1', port='3000', debug=True)
```

{% endcode %}

```bash
python webhook.py

#running in background
nohup python webhook.py > captodocs.log 2>&1 &
```

{% hint style="info" %}
Ejemplo de datos guardados en output.txt
{% endhint %}

{% code title="output.txt" %}

```markup
{
	"AccountingUser": "ADMIN",
	"Company": "1",
	"Department": "1",
	"Division": "1",
	"Holding": "HOLDING1",
	"Journal": "400",
	"LocalCurrency": "EUR",
	"Monbas": "2",
	"Posting": "1",
	"Token": "4R33vj9EdJHsdaAE74345fDsW",
	"Detail": "1",
	"Impost": "1",
	"Name": "Alquiler local",
	"Pagapu": "1",
	"PaymentAutomatic": "0",
	"PaymentClacre": "03",
	"PaymentOnAccount": "572000003",
	"PaymentOnAccountAuxcod": "",
	"PaymentOnAccountAuxtip": "",
	"SellerAccount": "410000003",
	"SellerAuxiliary": "",
	"SellerAuxiliaryAuxcod": "",
	"SellerConamp": "Alquiler y servicios mes",
	"SellerConcep": "02",
	"Tipfac": "PR",
	"SellerPartyCorporateName": "Alquileres, S.L.",
	"SellerAddress": "Av Diagonal, 1234",
	"SellerAddressPostCode": "08173",
	"SellerAddessTown": "Barcelona",
	"SellerTaxIdentification": "B00000000",
	"SellerEmail": "seller@email.com",
	"SelletTel": "0000000000000",
	"InvoiceNumber": "5158",
	"InvoiceIssueDate": "20190110",
	"BuyerPartyCorporateName": "Empresa, S.L.",
	"BuyerAddress": "Av Diagonal, 1234",
	"BuyesAddressPostCode": "08173",
	"BuyesAddressTown": "Barcelona",
	"BuyerAddressProvince": "Barcelona",
	"BuyerTaxIdentification": "B00000000",
	"Detail1ArticleCode": "Renta Octubre",
	"Detail1TotalCost": "819,30",
	"Detail2ArticleCode": "Gastos Comunes",
	"Detail2TotalCost": "219,59",
	"InvoiceTotalsGrossAmount": "1038,89",
	"Tax1Rate": "21,00",
	"Tax1TotalAmount": "218,17",
	"TotalInvoiceAmount": "1257,06",
	"Detail1": {
		"DetailAccount": "62100001",
		"DetailAuxiliary": "",
		"DetailAuxiliaryAuxcod": "",
		"DetailConamp": "Alquiler",
		"DetailConcep": "02",
		"DetailCurrency": "EUR"
	},
	"Detail2": {
		"DetailAccount": "62100001",
		"DetailAuxiliary": "",
		"DetailAuxiliaryAuxcod": "",
		"DetailConamp": "Suministros",
		"DetailConcep": "02",
		"DetailCurrency": "EUR"
	},
	"Tax1": {
		"TaxAccountTax": "47200000",
		"TaxAuxapu": "0",
		"TaxAuxcod": "",
		"TaxAuxtip": "",
		"TaxClaopr": "",
		"TaxColimp": "1",
		"TaxCurrency": "EUR",
		"TaxLibreg": "SOP",
		"TaxRelaci": "RG",
		"TaxType": "1"
	},
	"TotalInvoice": {
		"TotalInvoiceAccounting": "62100001",
		"TotalInvoiceAuxapu": "0",
		"TotalInvoiceAuxcod": "",
		"TotalInvoiceAuxtip": "",
		"TotalInvoiceCurrency": "EUR"
	}
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://library.captodocs.com/connect/python-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
