Autentication issue with cUrl

Autentication issue with cUrl

Postby Marc Venken » Fri Oct 28, 2022 8: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: Select all  Expand view

  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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Autentication issue with cUrl

Postby Silvio.Falconi » Fri Oct 28, 2022 9: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: Autentication issue with cUrl

Postby Marc Venken » 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: Select all  Expand view


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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Autentication issue with cUrl

Postby Marc Venken » 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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 27 guests