FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Autentication issue with cUrl
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Autentication issue with cUrl

Posted: Fri Oct 28, 2022 08:40 AM
In some sites I can retrieve webdata with this :

cLink = "https://site/api/v2/products/"+alltrim(cCode)+"?search=sku&token=token"
MsgRun( cLink, "READING FORUM PAGE", { || uResponse := WebPageContents( cLink, .t. ) } )

Now the new site is giving a :

"message":"Unauthorized"

I tried a sample from Tim : (changed real token to text token just for forum )
I don't know with data is needed in cData ? Tim ??

If I use the API on there test site, it works, and I get this information :

curl -X GET "https://site/v3/products/inventory?catalog_reference=B10" -H "accept: application/json" -H "x-site-authorization: token" -H "x-api-key: apikey here"

Tim's code (Thanks)
Code (fw): Select all Collapse
  local cUrl := "https://siteo/v3/products/inventory?catalog_reference=Gi6400B?token=token"
  local cData := ""
  local cContentType := "application/json"
  local cAuthorization := cToken //  cToken is only the token and not "x-site-authorization: token" ???  is this the issue ?

  PostTo360( cUrl, cData, cContentType,cAuthorization )

Function PostTo360( cUrl, cData, cContentType,cAuthorization )

    Local oOle,cRet:='',uRet
    default cContentType:="application/json"
    default cAuthorization:=""
    oOle   := CreateObject( "MSXML2.XMLHTTP" )
    oOle:Open( 'GET', cUrl, .f. )
    oOle:SetRequestHeader( "Content-Type", cContentType)
    oOle:SetRequestHeader( "Authorization",cAuthorization)
    oOle:Send( cData )
    cRet := oOle:ResponseBody
    msginfo(cRet)
RETURN( cRet )
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: Autentication issue with cUrl

Posted: Fri Oct 28, 2022 09:33 AM

I'm also interested in having a working test sample

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Re: Autentication issue with cUrl

Posted: Fri Oct 28, 2022 10:16 AM
Houston... I get some data ... :D :D

With this updated code, I get some more data, but not the good once.
Code (fw): Select all Collapse
Function PostTo360( cUrl, cData, cContentType,cAuthorization )

    Local oOle,cRet:='',uRet

    default cContentType:="application/json"
    default cAuthorization:=""

    oOle   := CreateObject( "MSXML2.XMLHTTP" )
    oOle:Open( 'GET', cUrl, .f. )
    oOle:SetRequestHeader("content-type", "application/json" )
    oOle:SetRequestHeader( "Authorization","Bearer"+cAuthorization)

    TRY
        oOle:Send( cData )
        cRet := oOle:ResponseBody

    CATCH

        //NOS GUSTARIA PODER CAPTURAR EL ERROR Y SABER EL MOTIVO POR EL QUE NO SE PUDO ENVIAR
        msginfo("Fout - Error URL","error url")
        ? "Return : "+cRet
    END
    FW_memoEdit(cRet)

RETURN( cRet )
The response :

{"message":"Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header. Authorization=token"}
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM

Re: Autentication issue with cUrl

Posted: Fri Oct 28, 2022 10:18 AM

Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header. Authorization=allow

indicates that the resource path doesn't exist. Check your url and make sure you're accessing the correct endpoint.

Sorry, I have to look further...

Marc Venken

Using: FWH 23.08 with Harbour

Continue the discussion