PHPackages                             leandrorosa/cnova-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. leandrorosa/cnova-sdk

ActiveLibrary[API Development](/categories/api)

leandrorosa/cnova-sdk
=====================

Market Places API

112

Since Nov 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/leandro-rosa/cnova-sdk)[ Packagist](https://packagist.org/packages/leandrorosa/cnova-sdk)[ RSS](/packages/leandrorosa-cnova-sdk/feed)WikiDiscussions develop Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

SDK PHP para API V2 de Lojistas
===============================

[](#sdk-php-para-api-v2-de-lojistas)

Provê os componentes PHP para uso da API V2 de lojistas, disponibilizada pela CNova.

[![Vantagens na utilização de SDKs](https://camo.githubusercontent.com/15adb606bd4e913494d0d6c396094cafcf91ac9a4b5c1094cd76f641ddcb6608/68747470733a2f2f646573656e766f6c7665646f7265732e636e6f76612e636f6d2f6170692d706f7274616c2f73697465732f64656661756c742f66696c65732f696d616765732f73646b5f6465762e706e67)](https://camo.githubusercontent.com/15adb606bd4e913494d0d6c396094cafcf91ac9a4b5c1094cd76f641ddcb6608/68747470733a2f2f646573656e766f6c7665646f7265732e636e6f76612e636f6d2f6170692d706f7274616c2f73697465732f64656661756c742f66696c65732f696d616765732f73646b5f6465762e706e67)

Criando um API Client
---------------------

[](#criando-um-api-client)

Antes de utilizar as APIs, é necessário a criação de um client com as configurações de *base path* e também as credenciais para acesso.

Abaixo segue o código de exemplo:

```
require 'vendor/autoload.php';

use CNovaApiLojistaV2\client\Configuration;
use CNovaApiLojistaV2\client\ApiClient;
use CNovaApiLojistaV2\LoadsApi;
use CNovaApiLojistaV2\model\Product;
use CNovaApiLojistaV2\model\ProductLoadPrices;
use CNovaApiLojistaV2\model\ProductLoadStock;
use CNovaApiLojistaV2\model\Dimensions;
use CNovaApiLojistaV2\model\ProductAttribute;
use CNovaApiLojistaV2\client\ApiException;

Configuration::$apiKey['client_id'] = 'll0rQx9SSshr';
Configuration::$apiKey['access_token'] = 'nllKgtXTMv0G';

$api_client = new ApiClient('https://sandbox.cnova.com/api/v2');
```

Operações auxiliares
--------------------

[](#operações-auxiliares)

Tratamento de estruturas de erros recebidas nas chamadas à API:

```
function deserializeErrors($errorsJson, $apiClient) {

	$errors = null;

	try {
		$errors = $apiClient->deserialize(json_decode($errorsJson), 'Errors');
	} catch (\Exception $e) {}

	return $errors;

}
```

Formatação de datas para consultas em períodos específicos:

```
function formatDateRange($initialDate, $finalDate, $apiClient) {

	$dtIni = '*';
	$dtEnd = '*';

	if ($initialDate != null && $initialDate instanceof \DateTime) {
		$dtIni = $initialDate->format(\DateTime::ISO8601);
	}

	if ($finalDate != null && $finalDate instanceof \DateTime) {
		$dtEnd = $finalDate->format(\DateTime::ISO8601);
	}

	return $dtIni . ',' . $dtEnd;

}
```

APIs Disponíveis
----------------

[](#apis-disponíveis)

A seguir, são apresentadas as APIs e exemplos com as as principais operações do Marketplace.

### Loads API

[](#loads-api)

API utilizada para operações de carga.

Carga de produtos:

```
$loads = new LoadsApi($api_client);

// Criação de um novo produto

$product = new Product();

$product->sku_seller_id = 'CEL_LGG4';
$product->product_seller_id = 'CEL';
$product->title = 'Produto de testes LG G4';
$product->description = 'O novo produto de testes, LG G4';
$product->brand = 'LG';
$product->gtin = array('123456ft');
$product->categories = array (
		'Teste>API'
);
$product->images = array (
		'http://img.g.org/img1.jpeg'
);

$price = new ProductLoadPrices();
$price->default = 1999.0;
$price->offer = 1799.0;

$product->price = $price;

$stock = new ProductLoadStock();
$stock->quantity = 100;
$stock->cross_docking_time = 0;

$product->stock = $stock;

$dimensions = new Dimensions();
$dimensions->weight = 10;
$dimensions->length = 10;
$dimensions->width = 10;
$dimensions->height = 10;

$product->dimensions = $dimensions;

$product_attr = new ProductAttribute();
$product_attr->name = 'cor';
$product_attr->value = 'Verde';

$product->attributes =  array($product_attr);

// Adiciona o novo produto na lista a ser enviada
$products = array($product);

try {

	// Envia a carga de produtos
	$loads->postProducts($products);

} catch (ApiException $e) {

	$errors = deserializeErrors($e->getResponseBody(), $api_client);

	if ($errors != null) {
		foreach ($errors->errors as $error) {
			echo ($error->code . ' - ' . $error->message . "\n");
		}
	} else {
		echo ($e->getMessage());
	}

}
```

Consulta de cargas enviadas:

```
$loads_api = new LoadsApi($api_client);

try {

	$get_products_response = $loads_api->getProducts(null, null, 0, 10);
	var_dump($get_products_response);

} catch (ApiException $e) {

	$errors = deserializeErrors($e->getResponseBody(), $api_client);

	if ($errors != null) {
		foreach ($errors->errors as $error) {
			echo ($error->code . ' - ' . $error->message . "\n");
		}
	} else {
		echo ($e->getMessage());
	}

}
```

Consulta um produto específico da carga enviada:

```
$loads_api = new LoadsApi($api_client);

try {

	$get_product_with_errors_response = $loads_api->getProduct('CEL_LGG4');
	var_dump($get_product_with_errors_response);

} catch (ApiException $e) {

	$errors = deserializeErrors($e->getResponseBody(), $api_client);

	if ($errors != null) {
		foreach ($errors->errors as $error) {
			echo ($error->code . ' - ' . $error->message . "\n");
		}
	} else {
		echo ($e->getMessage());
	}

}
```

Modificação do tracking de uma ou mais ordens, utilizando a API Loads:

```
$loads_api = new LoadsApi($api_client);

$orders_trackings = new OrdersTrackings();

$order_tracking = new OrderTracking();

$order_id = new OrderId();
$order_id->id = 123;
$order_tracking->order = $order_id;

$order_tracking->control_point = 'ABC';
$order_tracking->cte = '123';

$oif = new OrderItemReference();
$oif->sku_seller_id = '123456';
$oif->quantity = 1;

$order_tracking->items = array($oif);

$order_tracking->occurred_at = new \DateTime('NOW');
$order_tracking->seller_delivery_id = '99995439701';
$order_tracking->number = '01092014';
$order_tracking->url = 'servico envio2';

$carrier = new Carrier();
$carrier->cnpj = '72874279234';
$carrier->name = 'Sedex';

$order_tracking->carrier = $carrier;

$invoice = new Invoice();
$invoice->cnpj = '72874279234';
$invoice->number = '123';
$invoice->serie = '456';
$invoice->issued_at = new \DateTime('NOW');
$invoice->access_key = '01091111111111111111111111111111111111101092';
$invoice->link_xml = 'link xlm teste5';
$invoice->link_danfe = 'link nfe teste5';

$order_tracking->invoice = $invoice;

$orders_trackings->trackings = array($order_tracking);

try {

	$loads_api->postOrdersTrackingSent($orders_trackings);

} catch (ApiException $e) {

	$errors = deserializeErrors($e->getResponseBody(), $api_client);

	if ($errors != null) {
		foreach ($errors->errors as $error) {
			echo ($error->code . ' - ' . $error->message . "\n");
		}
	} else {
		echo ($e->getMessage());
	}

}
```

### Seller Items API

[](#seller-items-api)

API utilizada para gerenciamento dos recursos enviados pelo lojista.

Consulta de seller items:

```
$seller_items_Api = new SellerItemsApi($api_client);

try {

	$get_seller_items_response = $seller_items_Api->getSellerItems('EX', 0, 100);
	var_dump($get_seller_items_response);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

Alteração de preço:

```
$seller_items_api = new SellerItemsApi($api_client);

try {

	$prices = new Prices();
	$prices->default = 100;
	$prices->offer = 100;

	$seller_items_api->putSellerItemPrices('31.0019', $prices);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

Alteração de estoque:

```
$seller_items_api = new SellerItemsApi($api_client);

try {

	$stock = new Stock();
	$stock->quantity = 200;
	$stock->cross_docking_time = 0;

	$seller_items_api->putSellerItemStock('31.0019', $stock);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

### Orders API

[](#orders-api)

API utilizada para gerenciamento de pedidos.

Consulta todas as ordens:

```
$orders_api = new OrdersApi($api_client);

try {
	$get_orders_response =  $orders_api->getOrders(0, 100);
	var_dump($get_orders_response);
} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

Consulta todas as ordens com status "novo":

```
$orders_api = new OrdersApi($api_client);

try {

	$purchased_at = formatDateRange(null, new \DateTime('NOW'), $api_client);

	$get_orders_response =  $orders_api->getOrdersByStatusNew($purchased_at, null, null, 0, 100);
	var_dump($get_orders_response);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

Criação de um novo tracking, notificando o envio da ordem:

```
$orders_api = new OrdersApi($api_client);

$new_tracking = new NewTracking();

$new_tracking->items = array('23258312-1', '23258312-2');

$new_tracking->occurred_at = new \DateTime('NOW');

$new_tracking->seller_delivery_id = '99995439701';
$new_tracking->number = '"01092014';
$new_tracking->url = 'servico envio2';

$carrier = new Carrier();
$carrier->cnpj = '72874279234';
$carrier->name = 'Sedex';

$new_tracking->carrier = $carrier;

$invoice = new Invoice();
$invoice->cnpj = '72874279234';
$invoice->number = '123';
$invoice->serie = '456';
$invoice->issued_at = new \DateTime('NOW');
$invoice->access_key = '01091111111111111111111111111111111111101092';
$invoice->link_xml = 'link xlm teste5';
$invoice->link_danfe = 'link nfe teste5';

$new_tracking->invoice = $invoice;

try {
	$orders_api->postOrderTrackingSent($new_tracking, '1024101');
} catch (ApiException $e) {

	$errors = deserializeErrors($e->getResponseBody(), $api_client);

	if ($errors != null) {
		foreach ($errors->errors as $error) {
			echo ($error->code . ' - ' . $error->message . "\n");
		}
	} else {
		echo ($e->getMessage());
	}

}
```

Consulta de ordens com status "enviado":

```
$orders_api = new OrdersApi($api_client);

try {

	$get_orders_response = $orders_api->getOrdersByStatusSent(null, null, null, 0, 100);
	var_dump($get_orders_response);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

### Tickets API

[](#tickets-api)

API utilizada para gerenciamento de tickets.

Criação de um novo ticket:

```
$tickets_api = new TicketsApi($api_client);

$new_ticket = new NewTicket();
$new_ticket->to = 'atendimento+OS_706000500000@mktp.extra.com.br';
$new_ticket->body = 'Corpo da mensagem do ticket';

try {
	$tickets_api->postTicket($new_ticket);
} catch (ApiException $e) {

	$errors = deserializeErrors($e->getResponseBody(), $api_client);

	if ($errors != null) {
		foreach ($errors->errors as $error) {
			echo ($error->code . ' - ' . $error->message . "\n");
		}
	} else {
		echo ($e->getMessage());
	}

}
```

Consulta ticket com status "Aberto":

```
$tickets_api = new TicketsApi($api_client);

try {

	$tickets = $tickets_api->getTickets('opened', '439211092852', null, null, null, 0, 5);
	var_dump($tickets);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

Alteração do status do ticket:

```
$tickets_api = new TicketsApi($api_client);

try {

	$ticket_status = new TicketStatus();
	$ticket_status->ticket_status = 'Em Acompanhamento';

	$tickets_api->putTicketStatus('123123', $ticket_status);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

### Categories API

[](#categories-api)

API utilziada na obtenção da árvore de categorias disponível.

Consulta as categorias disponíveis:

```
$categories_api = new CategoriesApi($api_client);

try {

	$get_categories_response = $categories_api->getCategories(0, 5);

	foreach ($get_categories_response->categories as $categorie) {
		echo ($categorie->id . ' - ' . $categorie->name . "\n");
	}

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

### Sites API

[](#sites-api)

API utilizada na obtenção da lista de sites.

Consulta os sites disponíveis:

```
$sites_api = new SitesApi($api_client);

try {

	$get_sites_response = $sites_api->getSites();
	var_dump($get_sites_response);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

### Warehouses API

[](#warehouses-api)

API utilizada na obtenção da lista de warehouses (armazéns).

Consulta as warehouses disponíveis:

```
$warehouses_api = new WarehousesApi($api_client);

try {

	$get_warehouses_response = $warehouses_api->getWarehouses();
	var_dump($get_warehouses_response);

} catch (ApiException $e) {
	echo ($e->getMessage());
}
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8531f1435f3f0dafad650ab5e58e6e6948f5df083a67ae8abdddea7e84c2e059?d=identicon)[leandro.rosa](/maintainers/leandro.rosa)

---

Top Contributors

[![leandro-rosa](https://avatars.githubusercontent.com/u/5132648?v=4)](https://github.com/leandro-rosa "leandro-rosa (1 commits)")

### Embed Badge

![Health badge](/badges/leandrorosa-cnova-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/leandrorosa-cnova-sdk/health.svg)](https://phpackages.com/packages/leandrorosa-cnova-sdk)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
