> 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 %}
