1

I am creating an Invoice through Magento REST API with the below request:

POST "https://<magento-domain>/mg2/rest/V1/order/9/invoice"

Request Headers:

{
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": "Bearer jnsptpdgsvmk5mrbctisi3e0yml7k6iu"
}

Request Body:

{
    "capture": true,
    "order_id": 9,
    "items": [{
        "order_item_id": 33,
        "qty": 3,
        "extension_attributes": {}
    }],
    "notify": true,
    "appendComment": true,
    "comment": {
        "extension_attributes": {},
        "comment": "Invoice#: 22",
        "is_visible_on_front": 0
    },
    "arguments": {
        "extension_attributes": {}
    }
}

But I consistently get this error:

{
    "message": "Consumer is not authorized to access %resources",
    "parameters": {
        "resources": "Magento_Sales::sales"
    }
}

I am certain that the token I use works, because I am able to search orders and customers using the same token. The token is automatically renewed when I get a 401 error code in the response.

Also, the user I set up in Magento is an Administrator, which (I believe) has a full access on all objects (Sales Orders, Invoice, Shipments, etc.).

I have already configured the Integrations as well. So I am not sure what else I am missing?

Thanks in advance.

1 Answer 1

0

You should try with the Admin User Token Authentication and with the POST Method pass values like these:

{
  "capture": true,
  "items": [
    {
      "extension_attributes": {},
      "order_item_id": xxx,
      "qty": xxx
    }
  ],
  "notify": true,
  "appendComment": true,
  "comment": {
    "extension_attributes": {},
    "comment": "string",
    "is_visible_on_front": 0
  },
  "arguments": {
    "extension_attributes": {}
  }
}
1
  • Hmm, I don't see any difference from the original JSON that I post.
    – Jeffy J
    Mar 9, 2019 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.