22.10.2020, 11:20
(22.10.2020, 08:23)admin Wrote: Header is missing:
Code:["Content-Type"] = "application/x-www-form-urlencoded"
yes, now i get the authorization code (authCode).
Next is exchaging the authorization code for an access token, see my code try below.
Doc: https://interop.ondilo.com/docs/api/cust...n-exchange
Code:
-- exchange the authorization code for an access token
if authCode then
url = apiHost..endpointToken..'?code='..authCode..'&grant_type=authorization_code&client_id=customer_api&redirect_uri='..uri
method = "POST"
local response_body = {}
local res, code, response_headers, status = socket.http.request
{
url = url,
method = method,
headers =
{
["Content-Type"] = "application/x-www-form-urlencoded"
},
source = ltn12.source.string(''),
sink = ltn12.sink.table(response_body)
}
log(res, code, response_headers, status)
end
but as usually i received an error
Code:
* arg: 1
* number: 1
* arg: 2
* number: 400
* arg: 3
* table:
["server"]
* string: Apache/2.4.29 (Ubuntu)
["content-type"]
* string: application/json
["connection"]
* string: close
["access-control-allow-methods"]
* string: GET, POST, PUT, PATCH, DELETE, OPTIONS
["access-control-allow-headers"]
* string: X-Requested-With, Content-Type, Accept, Origin, Authorization
["cache-control"]
* string: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0
["pragma"]
* string: no-cache
["date"]
* string: Thu, 22 Oct 2020 11:14:32 GMT
["content-length"]
* string: 97
["access-control-allow-origin"]
* string: *
["access-control-allow-credentials"]
* string: true
* arg: 4
* string: HTTP/1.1 400 Bad Request