Chilkat Online Tools

unicodeC / api-seguridad.sunat.gob.pe / Get Token

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkHttpRequestW req;
    HCkHttpResponseW resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    req = CkHttpRequestW_Create();
    CkHttpRequestW_AddParam(req,L"grant_type",L"password");
    CkHttpRequestW_AddParam(req,L"scope",L"https://api-cpe.sunat.gob.pe");
    CkHttpRequestW_AddParam(req,L"client_id",L"99993656-9999-9999-90ad-9999d06d9999");
    CkHttpRequestW_AddParam(req,L"client_secret",L"u3Hhp5vbb5GubHPdQ161sQ==");
    CkHttpRequestW_AddParam(req,L"username",L"20307150981SOPORTE1");
    CkHttpRequestW_AddParam(req,L"password",L"12345678");

    resp = CkHttpW_PostUrlEncoded(http,L"https://api-seguridad.sunat.gob.pe/v1/clientessol/99993656-9999-9999-90ad-9999d06d9999/oauth2/token/",req);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(req);

    }

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": [
  ]
}