Credenciales de guías (GRE)
Registra las credenciales de la empresa para emitir guías de remisión en producción.
Autenticación: token Bearer de cuenta (empresas:manage).
Ejemplo
Copiar
curl -X PATCH https://api.xmlperu.dev/v1/companies/20123456789/gre-credentials \
-H "Authorization: Bearer $TOKEN_CUENTA" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{
"client_id": "a1b2c3d4-…",
"client_secret": "…"
}'Copiar
<?php
$token_cuenta = 'pega-aqui-tu-token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.xmlperu.dev/v1/companies/20123456789/gre-credentials');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token_cuenta,
'Accept: application/json',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, <<<JSON
{
"client_id": "a1b2c3d4-…",
"client_secret": "…"
}
JSON);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);Copiar
const TOKEN_CUENTA = 'pega-aqui-tu-token';
const res = await fetch('https://api.xmlperu.dev/v1/companies/20123456789/gre-credentials', {
method: 'PATCH',
headers: {
Authorization: `Bearer ${TOKEN_CUENTA}`,
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"client_id": "a1b2c3d4-…",
"client_secret": "…"
}),
});
const data = await res.json();Copiar
import requests
TOKEN_CUENTA = "pega-aqui-tu-token"
headers = {
"Authorization": f"Bearer {TOKEN_CUENTA}",
"Accept": "application/json",
}
payload = {
"client_id": "a1b2c3d4-…",
"client_secret": "…"
}
res = requests.patch("https://api.xmlperu.dev/v1/companies/20123456789/gre-credentials", json=payload, headers=headers)
data = res.json()Copiar
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
var tokenCuenta = "pega-aqui-tu-token";
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Patch, "https://api.xmlperu.dev/v1/companies/20123456789/gre-credentials");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokenCuenta);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var json = """
{
"client_id": "a1b2c3d4-…",
"client_secret": "…"
}
""";
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
using var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();Respuesta
200 Registradasapplication/json
{
"success": true,
"message": "Credenciales de guías registradas.",
"data": {
"gre_credentials": {
"client_id": "a1b2c3d4-…",
"client_secret_set": true,
"uses_own": true
}
}
}200 Desactivadasapplication/json
Enviando ambos campos vacíos. Las guías vuelven a salir con las credenciales del proveedor.
{
"success": true,
"message": "Credenciales de guías desactivadas.",
"data": {
"gre_credentials": {
"client_secret_set": false,
"uses_own": false
}
}
}Parámetros
En la URL
| Nombre | Tipo | Descripción |
|---|---|---|
| ruc* | string | RUC de la empresa (11 dígitos). |
En el cuerpo (JSON)
| Nombre | Tipo | Descripción |
|---|---|---|
| client_id | string | Client ID de OAuth2 emitido en SOL. |
| client_secret | string | Client secret de OAuth2. Se guarda cifrado. |
* Obligatorio.
Ten en cuenta
- Solo hacen falta para guías de remisión (
09,31) y solo en producción. - Son el
client_idy elclient_secretque SUNAT entrega en el portal SOL. - Envía los dos juntos.
- El
client_secretse guarda cifrado y nunca se devuelve.
Ejemplo
curl -X PATCH https://api.xmlperu.dev/v1/companies/$RUC/gre-credentials \
-H "Authorization: Bearer $TOKEN_CUENTA" \
-H "Content-Type: application/json" \
-d '{"client_id": "a1b2c3d4-…", "client_secret": "…"}'
Las facturas, boletas y notas no usan estas credenciales.
Errores
422 Incompletasapplication/json
{
"success": false,
"message": "Envía client_id y client_secret juntos, o ambos vacíos para desactivarlas."
}Casos especiales
Solo te afectan si usas esa opción.
- Demo. No configures nada: en demo usamos las credenciales de prueba de SUNAT. Las que registres se usan al pasar a producción.
- Quitarlas. Envía los dos campos vacíos.
- Ver si están cargadas. Con GET /v1/companies/{ruc}/certificate, en
gre_credentials.