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
#include <CkHttpW.h>
#include <CkHttpRequestW.h>
#include <CkHttpResponseW.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
bool success;
CkHttpRequestW req;
req.AddParam(L"grant_type",L"password");
req.AddParam(L"scope",L"https://api-cpe.sunat.gob.pe");
req.AddParam(L"client_id",L"99993656-9999-9999-90ad-9999d06d9999");
req.AddParam(L"client_secret",L"u3Hhp5vbb5GubHPdQ161sQ==");
req.AddParam(L"username",L"20307150981SOPORTE1");
req.AddParam(L"password",L"12345678");
CkHttpResponseW resp;
req.put_HttpVerb(L"POST");
req.put_ContentType(L"application/x-www-form-urlencoded");
ERROR: Assignment type mismatch. ExpressionType=HttpResponse, atgType=ckbool
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
wprintf(L"%d\n",resp.get_StatusCode());
wprintf(L"%s\n",resp.bodyStr());
}
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": [
]
}