Request authorization
The authorization code is provided through the Tray Commerce authentication server.
To allow access to the information and resources of the account, the client must be redirected to the browser-based url. (****** WILL HOW TO HOW TO DO NOT OPEN THE BROWSER *****)
Tray Commerce is responsible for receiving confirmation of the customer's authorization and providing the authorization code to the application.
Url for authentication: https: // {host_domain} /auth.php
Supported HTTP "GET" Parameters for Authentication:
response_type: Request type (Default value code)
consumer_key: Identification of the application with Tray Commerce.
callback: Callback URL that will be redirected after authorization
Then get the return of the url to return, according to the Tray tutorial:
After authorization, the client is redirected to the URL specified in the callback parameter passed at the time of authorization (in the example above it is the URL http: // localhost / tray / callback / auth /), where it would be, following the previous examples, the following form this URL:
https: // {domain_database} /auth.php?response_type=code&consumer_key=2r9dg7sgdb&callback=https:// {url_de_callback}
So you can capture the information from this URL and use it to configure it in your application, with the code and api_address parameters most important in the integration process.
With the code and api_address, you must use the Generate Access Key API to generate the value of the access_token used in the other APIs. It is extremely important to store all the return information of this API as it will be used constantly during communication with the API. Tray
- Code: Select all Expand view RUN
cUrl := 'https://trayparceiros.commercesuite.com.br/auth.php?'+'response_type=code&consumer_key='+consumerkey+'&callback='+wcallback
aResult:= ""
cXml:= [{"usuario":"conta_teste","senha":"senha"}]
oHttp:= CreateObject( 'MSXML2.ServerXMLHTTP.6.0' )
oHttp:Open( "GET" , cUrl, .F. )
oHttp:setRequestHeader("Content-Type","application/json")
oHttp:Send(cXml)
IF oHttp:status <> 200 // COM ERRO
MsgStop( Alltrim(Str(oHttp:status)) +" - "+ Alltrim(oHttp:ResponseText) , "Erro na requisição")
HB_MemoWrit('erro.html', oHttp:ResponseText) // coloquei apenas para visualizar o retorno em caso de erro
RETURN NIL
ENDIF
x:= oHttp:ResponseText
MSGINFO(x,"OK")