Airtable + Fetch API + Szamlazz.hu

Fórumok

Sziasztok!

Airtable-bol szeretnem JS + Fetch API-val megivni a Szamlazz.hu Szamla Agent API-jat, ami elvileg XML-t szeretne kapni.

Neztem par mintapeldat, de valahogy sehogy se all ossze. Csinalt mar ilyet valaki? 

Koszi!

Hozzászólások

Probalkozz a legrovidebb api hivassal, drotozz bele fix ertekeket. Aztan lepesrol lepesre haladj. 

Egyebkent mi a jelenseg, amit tapasztalsz? A nem megy az nem valasz.

Szia!

Sok mas mellett, a kovetkezot probaltam:

 

---

const szamlazzUrl = 'https://www.szamlazz.hu/szamla/';

const xmlData = `

<xmlszamla xmlns="http://www.szamlazz.hu/xmlszamla" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.szamlazz.hu/xmlszamla https://www.szamlazz.hu/szamla/docs/xsds/agent/xmlszamla.xsd">

    <beallitasok>

        <!-- settings -->

        <!-- a Számlázz.hu’s user password -->

        <szamlaagentkulcs>  ---  IDE JON A SZAMLAAGENT KULCS --- </szamlaagentkulcs>



...

EZ ITT A SZAMLA AGENT API LEIRASABOL SZARMAZO MINTA XML, FORRAS: https://docs.szamlazz.hu/#example-xml-file-with-explanation

AMIHEZ NAGYON KICSIT KELLETT HOZZANYULNI ES LEHET VELE SZAMLAT GENERALNI, ITT: https://docs.szamlazz.hu/#generating-invoices

...



</xmlszamla>

`;



const fetchResponse = await fetch(szamlazzUrl, {

  method: 'POST',

  headers: {

    'Content-Type': 'application/xml',

  },

  body: xmlData,

});



if (fetchResponse.ok) {

  console.log('Invoice sent successfully!');

} else {

  console.error('Error sending invoice:', fetchResponse.statusText);

}

---

Viszont ha Airtable-bol probalom Fetch API-val, a fenti koddal, akkor nem kerul letrehozasra szamla, annak ellenere, hogy az az output, hogy 

CONSOLE.LOG

  1. "Invoice sent successfully!"

Es az a vicces, hogy curl-el is probaltam, ugy is megy, de pl Postman-el megintcsak nem tudom mukodesre birni.

$ curl -v -F action-xmlagentxmlfile=@agent.xml -c ./cookies.txt -o response.pdf https://www.szamlazz.hu/szamla/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 195.228.16.193:443...
* Connected to www.szamlazz.hu (195.228.16.193) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [122 bytes data]
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
{ [25 bytes data]
* TLSv1.3 (IN), TLS handshake, Certificate (11):
{ [4210 bytes data]
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
{ [264 bytes data]
* TLSv1.3 (IN), TLS handshake, Finished (20):
{ [52 bytes data]
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.3 (OUT), TLS handshake, Finished (20):
} [52 bytes data]
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=HU; L=Budapest; O=KBOSS.hu Kft.; CN=www.szamlazz.hu
*  start date: Feb 11 14:58:19 2023 GMT
*  expire date: Jan  2 14:58:19 2024 GMT
*  subjectAltName: host "www.szamlazz.hu" matched cert's "*.szamlazz.hu"
*  issuer: C=HU; L=Budapest; O=NetLock Kft.; OU=Tansvykiad (Certification Services); CN=NetLock Expressz (Class C) Tansvykiad
                                                                                                                             *  SSL certificate verify ok.
} [5 bytes data]
> POST /szamla/ HTTP/1.1
> Host: www.szamlazz.hu
> User-Agent: curl/7.74.0
> Accept: */*
> Content-Length: 7084
> Content-Type: multipart/form-data; boundary=------------------------XXXX
> 
} [5 bytes data]
* We are completely uploaded and fine
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [57 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [57 bytes data]
* old SSL session ID is stale, removing
100  7084    0     0  100  7084      0   5560  0:00:01  0:00:01 --:--:--  5560{ [5 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 16 Nov 2023 20:19:16 GMT
< Server: Apache/2.4.38 (Debian)
* Added cookie JSESSIONID="XXXX.sas2" for domain www.szamlazz.hu, path /szamla, expire 0
< Set-Cookie: JSESSIONID=XXXX.sas2; Path=/szamla; Secure; HttpOnly
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=600
< Pragma: public
* Added cookie cookie_is_member="true" for domain www.szamlazz.hu, path /, expire 1731701958
< Set-Cookie: cookie_is_member=true; Max-Age=31536000; Expires=Fri, 15-Nov-2024 20:19:18 GMT; Path=/; Secure
< szlahu_kintlevoseg: 38100
< szlahu_vevoifiokurl: https%3A%2F%2Fwww.szamlazz.hu%2Fszamla%2F%3Fpage%3Dvevoifiokpay%26partguid%XXXX
< szlahu_id: 434555920
< szlahu_nettovegosszeg: 30000
< szlahu_szamlaszam: PZ-2023-9
< szlahu_bruttovegosszeg: 38100
< Content-Disposition: attachment; filename=response.pdf
< Content-Type: application/pdf
< Content-Length: 20315
< Expires: Thu, 16 Nov 2023 20:29:16 GMT
< 
 25 27399    0     0  100  7084      0   3294  0:00:02  0:00:02 --:--:--  3296{ [5 bytes data]
100 27399  100 20315  100  7084   9357   3263  0:00:02  0:00:02 --:--:-- 12620
* Connection #0 to host www.szamlazz.hu left intact

Kozben kiderult (mar ha jol ertem), hogy az Airtable csak egy, a Fetch API-hoz hasonlo, de limitalt kepessegu Fecth function-t tamogat, ami ha jol ertem, nem tamogatja a multipart/form-data kezelest.

Ha ez valoban igy van, akkor nem nagyon marad mas lehetoseg, mint json formatumban tovabbpasszolni az adatokat valami API proxy megoldasnak (pl egy erre a celra irt Google Cloud Function), ami atalakitja es multipart/form-data formaban kuldi tovabb a Szamlazz.hu API-nak.