Hi all,
am developing an application using C# and RestSharp to integrate Magento 2 with an ERP using Magento 2 REST API.
At this time, I've been able to.
- Send Products and Customers from ERP to Magento.
- Download Magento orders to ERP.
- Change Products Stocks in Magento.
- Ship Magento Orders (create Shipments).
Now It's time to invoice shipped orders. I'm using:
salesInvoiceOrderV1
POST /V1/order/{orderId}/invoice
detailed in http://devdocs.magento.com/swagger/index_20.html#/
I tried it 2 ways:
- Sending JSON directly:
string orderInvoice = this.txtOrderToInvoice.Text;
var client = new RestClient(magento_url);
var request = new RestRequest("/rest/default/V1/order/{orderId}/invoice", Method.POST);
request.AddParameter("Authorization",
string.Format("Bearer " + magento_auth),
ParameterType.HttpHeader);
request.AddUrlSegment("orderId", "10"); // order to Invoice
request.AddJsonBody(new { items = new { orderItemId = 12, qty = 1} }); // order_item and qty to Invoice
IRestResponse response = client.Execute(request);
- Creating a class with JSON2C# and using the class:
string orderInvoice = this.txtOrderToInvoice.Text;
var client = new RestClient(magento_url);
var request = new RestRequest("/rest/default/V1/order/{orderId}/invoice", Method.POST);
request.AddParameter("Authorization",
string.Format("Bearer " + magento_auth),
ParameterType.HttpHeader);
request.AddUrlSegment("orderId", "10");
Classes.ordertoinvoice.RootObject newOrderToInvoice = new ordertoinvoice.RootObject();
newOrderToInvoice.capture = true;
newOrderToInvoice.items = new List<ordertoinvoice.Item>();
newOrderToInvoice.items.Add(new ordertoinvoice.Item());
newOrderToInvoice.items[0].orderItemId = 12;
newOrderToInvoice.items[0].qty = 1;
var json = request.JsonSerializer.Serialize(newOrderToInvoice);
request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
--
I always GET a 404 Error with the message "Request does not match any route."...
I'm very confused about this. It seems no dificult comparing with the other things I've done (same way).
I've making several tests with Magento 2 (I'm not a Magento expert) and I know:
- I can Invoice an Order (totally or partially) without create a Shipment.
- I create my order with value 1 in field named forced_shipment_with_invoice of sales_order table, it creates Shipment automatically when I create Invoice.
But this method to create Invoice seems not work...
Does anyone know what I'm doing wrong?? Does this method really works in Magento 2?? Any help, please!! : ))
Thanks a lot!