> For the complete documentation index, see [llms.txt](https://docs.afipsdk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.afipsdk.com/siguientes-pasos/web-services/carta-de-porte-electronica.md).

# Carta de Porte Electrónica

### Requisitos previos

Para poder usar esta guía, primero necesitarás:

* [Integrar Afip SDK en tu proyecto](/readme.md#integracion)

***

<https://www.afip.gob.ar/ws/documentos/manual_wscpe_version-2-0-3.pdf>

<details>

<summary>Identificador <kbd>wscpe</kbd></summary>

Producción <img src="/files/43hahnuGWTKVgLg13RRq" alt="Produccion" data-size="line">

Desarrollo <img src="/files/uvk4aCziYkKMPDX5Ku1M" alt="Desarrollo" data-size="original">

</details>

### **Paso 1 - Crear una instancia del web service**

{% tabs %}
{% tab title="Node" %}

```js
const ws = afip.WebService('wscpe');
```

{% endtab %}

{% tab title="PHP" %}

```php
$ws = $afip->WebService('wscpe');
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
ws = afip.webService("wscpe")
```

{% endtab %}

{% tab title="Python" %}

```python
ws = afip.webService("wscpe")
```

{% endtab %}

{% tab title=".NET" %}

```csharp
AfipWebService ws = afip.WebService("wscpe");
```

{% endtab %}

{% tab title="Java" %}

```java
AfipWebService ws = afip.webService("wscpe");
```

{% endtab %}

{% tab title="API" %}
No se requiere ninguna acción adicional.
{% endtab %}
{% endtabs %}

### **Paso 2 - Preparar los datos para la solicitud**

En la [Referencia de API de Carta de Porte Electrónica](https://afipsdk.com/docs/api-reference/web-services/wscpe/) pueden encontrar los métodos disponibles.

En este ejemplo vamos a usar los datos para el método `consultarUltNroOrden`

{% tabs %}
{% tab title="Node" %}

```js
// Obtenemos el TA
const ta = await ws.getTokenAuthorization();
	
// Preparamos los datos
const data = {
	'auth': { 
		'token': ta.token,
		'sign': ta.sign,
		'cuitRepresentada': afip.CUIT
	},
	'solicitud': {
		'sucursal': 195,
		'tipoCPE': 1
	}
};
```

{% endtab %}

{% tab title="PHP" %}

```php
// Obtenemos el TA
$ta = $ws->GetTokenAuthorization();
	
// Preparamos los datos
$data = array(
	'auth' => array( 
		'token' => $ta->token,
		'sign' => $ta->sign,
		'cuitRepresentada' => $afip->CUIT
	),
	'solicitud' => array(
		'sucursal' => 195,
		'tipoCPE' => 1
	)
);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
# Obtenemos el TA
ta = ws.getTokenAuthorization

# Preparamos los datos
data = {
  "auth": { 
    "token": ta["token"],
    "sign": ta["sign"],
    "cuitRepresentada": afip.CUIT
  },
  "solicitud": {
    "sucursal": 195,
    "tipoCPE": 1
  }
}
```

{% endtab %}

{% tab title="Python" %}

```python
# Obtenemos el TA
ta = ws.getTokenAuthorization()

# Preparamos los datos
data = {
  "auth": { 
    "token": ta["token"],
    "sign": ta["sign"],
    "cuitRepresentada": afip.CUIT
  },
  "solicitud": {
    "sucursal": 195,
    "tipoCPE": 1
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
// Obtenemos el TA
var ta = await ws.GetTokenAuthorizationAsync();

// Preparamos los datos
var data = new Dictionary<string, object?>
{
    ["auth"] = new Dictionary<string, object?>
    {
        ["token"] = ta["token"],
        ["sign"] = ta["sign"],
        ["cuitRepresentada"] = afip.CUIT
    },
    ["solicitud"] = new Dictionary<string, object?>
    {
        ["sucursal"] = 195,
        ["tipoCPE"] = 1
    }
};
```

{% endtab %}

{% tab title="Java" %}

```java
// Obtenemos el TA
GetServiceTAResponse ta = ws.getTokenAuthorization();

// Preparamos los datos
Map<String, Object> auth = new HashMap<>();
auth.put("token", ta.getToken());
auth.put("sign", ta.getSign());
auth.put("cuitRepresentada", afip.getOptions().getCuit());

Map<String, Object> solicitud = new HashMap<>();
solicitud.put("sucursal", 195);
solicitud.put("tipoCPE", 1);

Map<String, Object> data = new HashMap<>();
data.put("auth", auth);
data.put("solicitud", solicitud);
```

{% endtab %}

{% tab title="API" %}
No se requiere ninguna acción adicional.
{% endtab %}
{% endtabs %}

### **Paso 3 - Ejecutamos la solicitud**

{% tabs %}
{% tab title="Node" %}

```js
const res = await ws.executeRequest('consultarUltNroOrden', data);

console.log(res);
```

{% endtab %}

{% tab title="PHP" %}

```php
$res = $ws->ExecuteRequest('consultarUltNroOrden', $data);

var_dump($res);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
res = ws.executeRequest("consultarUltNroOrden", data)

puts res
```

{% endtab %}

{% tab title="Python" %}

```python
res = ws.executeRequest("consultarUltNroOrden", data)

print(res)
```

{% endtab %}

{% tab title=".NET" %}

```csharp
var res = await ws.ExecuteRequestAsync<Dictionary<string, object?>>("consultarUltNroOrden", data);

Console.WriteLine(JsonSerializer.Serialize(res));
```

{% endtab %}

{% tab title="Java" %}

```java
Map<String, Object> res = ws.executeRequest("consultarUltNroOrden", data);

System.out.println(res);
```

{% endtab %}

{% tab title="API" %}
**Endpoint**

<mark style="color:blue;">`POST`</mark> `https://app.afipsdk.com/api/v1/afip/requests`

**Ejemplo**

```json
{
    "environment": "dev",
    "method": "consultarUltNroOrden",
    "wsid": "wscpe",
    "params": {
            "auth": { 
                    "token": "{{token}}",
                    "sign": "{{sign}}",
                    "cuitRepresentada": "20409378472"
            },
            "solicitud": {
                    "sucursal": 195,
                    "tipoCPE": 1
            }
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.afipsdk.com/siguientes-pasos/web-services/carta-de-porte-electronica.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
