Api Consulta Laravel

En los siguientes ejemplos usaremos [Guzzle] (https://github.com/guzzle/guzzle) un cliente HTTP que se instala con Laravel.

Para consultar ruc sunat usando laravel.


use GuzzleHttp\Client;

$token = '';

$client = new Client(['base_uri' => 'https://api.apis.net.pe', 'verify' => false]);

$parameters = [
    'http_errors' => false,
    'connect_timeout' => 5,
    'headers' => [
        'Authorization' => 'Bearer '.$token,
        'Referer' => 'https://apis.net.pe/api-consulta-ruc',
        'User-Agent' => 'laravel/guzzle',
        'Accept' => 'application/json',
    ],
    'query' => ['numero' => $number]
];
$res = $client->request('GET', '/v2/sunat/ruc', $parameters);
$response = json_decode($res->getBody()->getContents(), true);
var_dump($response);

Para consultar DNI usando laravel (GuzzleHttp)


use GuzzleHttp\Client;
$token = '';
$numero = '46027897';
$client = new Client(['base_uri' => 'https://api.apis.net.pe', 'verify' => false]);
$parameters = [
    'http_errors' => false,
    'connect_timeout' => 5,
    'headers' => [
        'Authorization' => 'Bearer '.$token,
        'Referer' => 'https://apis.net.pe/api-consulta-dni',
        'User-Agent' => 'laravel/guzzle',
        'Accept' => 'application/json',
    ],
    'query' => ['numero' => $number]
];
$res = $client->request('GET', '/v2/renec/dni', $parameters);
$response = json_decode($res->getBody()->getContents(), true);
var_dump($response);

Para consultar Tipo de cambio sunat usando laravel (GuzzleHttp), Puedes leer más sobre api sunat tipo de cambio


use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://api.apis.net.pe', 'verify' => false]);
$parameters = [
    'http_errors' => false,
    'connect_timeout' => 5,
    'headers' => [
        'Authorization' => 'Bearer '.$token,
        'Referer' => 'https://apis.net.pe/api-sunat-tipo-de-cambio',
        'User-Agent' => 'laravel/guzzle',
        'Accept' => 'application/json',
    ],
    'query' => ['fecha' => '2023-06-03']
];
$res = $client->request('GET', '/v2/sunat/tipo-cambio', $parameters);
$response = json_decode($res->getBody()->getContents(), true);
var_dump($response);

Para obtener el tipo de cambio de un mes completo revisa la documentación.