How use cUrl?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
dragancesu
Posts: 930
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

How use cUrl?

Post 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
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How use cUrl?

Post 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")
User avatar
nekbmm
Posts: 122
Joined: Sat Jul 16, 2016 3:16 am
DBs Used: DBF,SQLite
Location: Ivanjica, Serbia

Re: How use cUrl?

Post 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.
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: How use cUrl?

Post 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
All The Best,
Franco
Canada
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How use cUrl?

Post 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
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: How use cUrl?

Post 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.
All The Best,
Franco
Canada
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How use cUrl?

Post 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.
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: How use cUrl?

Post 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
All The Best,
Franco
Canada
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How use cUrl?

Post 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.
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: How use cUrl?

Post 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.
All The Best,
Franco
Canada
Post Reply