cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 REST API - Cannot Invoice and Order - {"message":"Request does not match any route."}-404

SOLVED

Magento 2 REST API - Cannot Invoice and Order - {"message":"Request does not match any route."}-404

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!

6 REPLIES

[SOLVED]Re: Magento 2 REST API - Cannot Invoice and Order - {"message":"Request does not matc

Solved! I did it using:

 

salesInvoiceRepositoryV1

POST /rest/default/V1/invoices

 

This generate a new invoice with items.

I used a C# class generated with JSON2C# (2nd way above)

Re: [SOLVED]Re: Magento 2 REST API - Cannot Invoice and Order - {"message":"Request d

Hi @CSRABC,

 


Thanks for sharing your solution in your own post, we really appreciate that.



Best regards.
Gabriel

If my answer was useful, please give "Kudos" to this post.
If my answer helps you to resolve the problem, click on "Accept as Solution".

Re: [SOLVED]Re: Magento 2 REST API - Cannot Invoice and Order - {"message":"Request d

The issue of your solution is that you have to fill many information by yourself to generate an invoice.

 

I suppose you should use 

curl -X POST --insecure "<Magento URL>/index.php/rest/V1/order/{orderId}/invoice" -H "Content-Type:application/json" -H "Authorization: Bearer <token>" -d "" 

 

to create an invoice according to the order information which you don't have invent again.

 

There I mean that there after "-d" the json content is empty string "".

Re: [SOLVED]Re: Magento 2 REST API - Cannot Invoice and Order - {"message":"Request d

can you tell me the base url 

i got the same error 

i am using 0auth 

Re: [SOLVED]Re: Magento 2 REST API - Cannot Invoice and Order - {"message":"Request d

try this:

 

http://[your_domain]/rest/default/V1/invoices

 

hope this will help you.

 

Good luck! 

Re: [SOLVED]Re: Magento 2 REST API - Cannot Invoice and Order - {"message":"Request d

Thanks 

its working