ERROR!
------------------- GenerateCode ----------------------
ImpliedContentType: application/x-www-form-urlencoded
---- begin chilkat script ----
// This example assumes the Chilkat API to have been previously unlocked.
// See {{-global_unlock:::Global Unlock Sample-}} for sample code.
new Http http;
ckbool success;
new HttpRequest req;
call req.AddParam("grant_type","password");
call req.AddParam("scope","https://api-cpe.sunat.gob.pe");
call req.AddParam("client_id","99993656-9999-9999-90ad-9999d06d9999");
call req.AddParam("client_secret","u3Hhp5vbb5GubHPdQ161sQ==");
call req.AddParam("username","20307150981SOPORTE1");
call req.AddParam("password","12345678");
new HttpResponse resp;
req.HttpVerb = "POST";
req.ContentType = "application/x-www-form-urlencoded";
success = http.PostUrlEncoded("https://api-seguridad.sunat.gob.pe/v1/clientessol/99993656-9999-9999-90ad-9999d06d9999/oauth2/token/", req,resp);
if (success == ckfalse) {
println http.LastErrorText;
return;
}
println resp.StatusCode;
println resp.BodyStr;
---- end chilkat script ----
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Req
oleobject loo_Resp
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")
loo_Req.AddParam("grant_type","password")
loo_Req.AddParam("scope","https://api-cpe.sunat.gob.pe")
loo_Req.AddParam("client_id","99993656-9999-9999-90ad-9999d06d9999")
loo_Req.AddParam("client_secret","u3Hhp5vbb5GubHPdQ161sQ==")
loo_Req.AddParam("username","20307150981SOPORTE1")
loo_Req.AddParam("password","12345678")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
loo_Req.HttpVerb = "POST"
loo_Req.ContentType = "application/x-www-form-urlencoded"
ERROR: Assignment type mismatch. ExpressionType=HttpResponse, atgType=ckbool
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Req
destroy loo_Resp
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Http
destroy loo_Req
destroy loo_Resp
Curl Command
curl -X POST
--data-urlencode 'grant_type=password'
--data-urlencode 'scope=https://api-cpe.sunat.gob.pe'
--data-urlencode 'client_id=99993656-9999-9999-90ad-9999d06d9999'
--data-urlencode 'client_secret=u3Hhp5vbb5GubHPdQ161sQ=='
--data-urlencode 'username=20307150981SOPORTE1'
--data-urlencode 'password=12345678'
https://api-seguridad.sunat.gob.pe/v1/clientessol/99993656-9999-9999-90ad-9999d06d9999/oauth2/token/
Postman Collection Item JSON
{
"name": "Get Token",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "grant_type",
"value": "password",
"type": "text"
},
{
"key": "scope",
"value": "https://api-cpe.sunat.gob.pe",
"type": "text"
},
{
"key": "client_id",
"value": "99993656-9999-9999-90ad-9999d06d9999",
"type": "text"
},
{
"key": "client_secret",
"value": "u3Hhp5vbb5GubHPdQ161sQ==",
"type": "text"
},
{
"key": "username",
"value": "20307150981SOPORTE1",
"type": "text"
},
{
"key": "password",
"value": "12345678",
"type": "text"
}
]
},
"url": {
"raw": "https://api-seguridad.sunat.gob.pe/v1/clientessol/99993656-9999-9999-90ad-9999d06d9999/oauth2/token/",
"protocol": "https",
"host": [
"api-seguridad",
"sunat",
"gob",
"pe"
],
"path": [
"v1",
"clientessol",
"99993656-9999-9999-90ad-9999d06d9999",
"oauth2",
"token",
""
]
}
},
"response": [
]
}