Page 1 of 1

How use cUrl?

Posted: Sat Oct 21, 2023 5:28 pm
by dragancesu

Code: Select all

use api new
_api = alltrim(key)
dbcloseall()
 
 _od = date() - 7
 _do = date() - 1
  
for _i = _od to _do 
  
 _datum = strzero(year(_i),4) + '-' + strzero(month(_i),2) + '-' + strzero(day(_i),2)
  
_komanda = 'curl -X POST "https://efaktura.mfin.gov.rs/api/publicApi/purchase-invoice/changes?date=' + _datum + '" -H "accept: text/plain" -H "ApiKey: ' + _api + '" -d "" > uf.txt'
  
run (_komanda )

// some procedure

next
How I can write using curl from hmg

Examples is for email, ftp, but not for this ccase

Re: How use cUrl?

Posted: Sun Oct 22, 2023 12:09 pm
by edk
Try this way:

Code: Select all

/*
curl -X POST "https://efaktura.mfin.gov.rs/api/publicApi/purchase-invoice/changes?date=' + _datum + '" -H "accept: text/plain" -H "ApiKey: ' + _api + '" -d "" > uf.txt'
*/

cURL := "https://efaktura.mfin.gov.rs/api/publicApi/purchase-invoice/changes?date=" + _datum

aHeaders := { "accept: text/plain", ;
              "ApiKey: " + _api }

cFormBody := ""

curlHandle := curl_easy_init()

curl_easy_reset( curlHandle )

/* Specify the Header  data */
curl_easy_setopt( curlHandle, HB_CURLOPT_HTTPHEADER, aHeaders)

curl_easy_setopt( curlHandle, HB_CURLOPT_URL, cUrl )
curl_easy_setopt( curlHandle, HB_CURLOPT_FOLLOWLOCATION, .T. )
curl_easy_setopt( curlHandle, HB_CURLOPT_SSL_VERIFYPEER, .F. )

curl_easy_setopt( curlHandle, HB_CURLOPT_DOWNLOAD )
curl_easy_setopt( curlHandle, HB_CURLOPT_DL_BUFF_SETUP )
	
curl_easy_setopt( curlHandle, HB_CURLOPT_POST, .T. )
curl_easy_setopt( curlHandle, HB_CURLOPT_POSTFIELDSIZE, LEN( cFormBody ) )
curl_easy_setopt( curlHandle, HB_CURLOPT_POSTFIELDS, cFormBody )

curlErr := curl_easy_perform( curlHandle )		/* Do everything */

IF !EMPTY( curlErr )	/* Report any errors */
	cReturn := "Error" + CRLF + curl_easy_strerror( curlErr )
ELSE
	cReturn := curl_easy_dl_buff_get( curlHandle )
ENDIF

StrFile ( cReturn, "uf.txt")

Re: How use cUrl?

Posted: Mon Oct 23, 2023 11:35 am
by nekbmm
dragancesu wrote: Sat Oct 21, 2023 5:28 pm

Code: Select all

use api new
_api = alltrim(key)
dbcloseall()
 
 _od = date() - 7
 _do = date() - 1
  
for _i = _od to _do 
  
 _datum = strzero(year(_i),4) + '-' + strzero(month(_i),2) + '-' + strzero(day(_i),2)
  
_komanda = 'curl -X POST "https://efaktura.mfin.gov.rs/api/publicApi/purchase-invoice/changes?date=' + _datum + '" -H "accept: text/plain" -H "ApiKey: ' + _api + '" -d "" > uf.txt'
  
run (_komanda )

// some procedure

next
How I can write using curl from hmg

Examples is for email, ftp, but not for this ccase
U svakom slučaju treba ti pauza između API poziva !!!

NEX.

Re: How use cUrl?

Posted: Mon Oct 23, 2023 9:09 pm
by franco
I still use gmail. Can I use this to directly send invoices from my pos system.
If so I know nothing how would I learn and set it up.
What is the best way to send emails.
Any help much appreciated.
Franco

Re: How use cUrl?

Posted: Mon Oct 23, 2023 11:01 pm
by edk
Hi Franco.
A long time ago I gave you a solution based on CDO.Message viewtopic.php?p=51497#p51497. I use a Gmail account to send logs from my applications and I successfully use CDO.Message for this purpose. It stopped working for you? You can check if this Curl and Imap/SMTP based email client works with your Gmail account: https://www.hmgforum.com/viewtopic.php?p=69218#p69218

Re: How use cUrl?

Posted: Wed Oct 25, 2023 10:06 pm
by franco
Thanks Edward,
I will check out again. My old gmail works good now as google set up 2 step verification instead of turn security down.
My current problem is google sets the app password and sometimes my clients go in and change it then email will not work.
My simplest way may be to figure a way to stop them from randomly changing the program email address.
I will look at the curl again. If I remember rightly It looked complicated.
Franco.

Re: How use cUrl?

Posted: Thu Oct 26, 2023 6:07 am
by edk
I understand Franco, but unfortunately my app based on imap and curl will not solve your problem because Google requires a new type of authorization oAuth2, which I have not done yet.
Unfortunately, I won't have time to look at it any time soon because I have two big projects to do.

Re: How use cUrl?

Posted: Fri Oct 27, 2023 3:56 pm
by franco
Edward,
Google works good and is easy to set up. It has 2 step verification which means you set up your account normally with a password
then turn on 2 step verification which google sets up an app password. In your email account you send them the exe file name you want the password for and they send you an app password which is registered with google. It then works good. If you loose password or change it manually the email account will not work and you have to go into email and ask for app password again.
Franco

Re: How use cUrl?

Posted: Fri Oct 27, 2023 6:02 pm
by edk
Franco, I am familiar with this mechanism for authorizing applications to a Gmail account, but I think I read an article somewhere that said this mechanism is to be disabled in the fall of 2024 and applications should be migrated to the oAuth authorization method.

Re: How use cUrl?

Posted: Mon Oct 30, 2023 7:00 pm
by franco
Edward, yes, I can not turn down security down any more but can not see where or when 2 step verification will end.