cancel
Showing results for 
Search instead for 
Did you mean: 

In Magento2 how to print the shipping label and what things are necessary for this?

In Magento2 how to print the shipping label and what things are necessary for this?

Hello there,

I integrate the API for 

GET /V1/shipment/{id}/label         (shipment label id)

So,here my question is that from where I get the shipping label id.

Thank you

13 REPLIES 13

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hi @harshita_chouhan

 

When you generate shipment of order using rest api , in response it returns the shipping id.

 

So here first you need to generate shipping for that order - for that you need to call below api

 

 

Endpointhttp://<host>/rest/default/V1/order/3/ship

 

So here for order no - 3 you are generating shipment ! and it returns that shipment id 

 

so further you can use that shipment id for label generation !

 

You can refer this link -  https://devdocs.magento.com/guides/v2.1/get-started/order-tutorial/order-create-shipment.html

if issue solved,Click Kudos & Accept as Solution

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hello @Manthan Dave,

Yes you are write that if I integrate the API 

Endpoint http://<host>/rest/default/V1/order/3/ship

From above API I get the shipment ID. This shipment ID is to Integrate API like:

GET  /V1/shipment/{id}   [Loads a specified shipment.] here id = shipment id

the above API works fine and give me the result.

But GET /V1/shipment/{id}/label  [Gets a specified shipment label] Here id = shipment label id.

When I integrate this shipment label id  API it returns nothing.

Give me a suggestion by which i get the shipping label.

 

Thank You.

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hello @harshita_chouhan

 

As per  magento coding you need to pass shipment id

 

https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Sales/Model/Service/ShipmentSe...

 public function getLabel($id)
    {
        return (string)$this->repository->get($id)->getShippingLabel();
    }

Here it is trying to get shipment object.

 

hope it will help you.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hello @Sunil Patel,

First of all thank for response,

Yes may be it works but I want to integrate the API in Node JS not in PHP. So if it possible you give me suggestion by which I find the shipping label id. to integrate the API : 

GET /V1/shipment/{id}/label  

 

Thank You

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hi @harshita_chouhan

 

looks like you haven't integrated your magento 2 setup with any courier partner and that is the reason , shipping label is not generated !!

 

Do one thing refer this link , how to generate shipping label from magento 2 backend -  https://www.mageplaza.com/kb/how-to-create-shipping-labels-magento-2.html

 

if it helpful to you click on kudos and accept as solution !!

 

hope it helps to you !!

if issue solved,Click Kudos & Accept as Solution

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hello @harshita_chouhan

 

Can you please send me original shipment response?

 

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hello @Manthan Dave,

Could you please give me suggestion, Which API is integrate to create the Invoice of new order whose status is in pending.

 

Thank You

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hi @harshita_chouhan

 

Yes sure below is the end point URL to generate invoice for pending order :

 

POST /V1/order/{orderId}/invoice

 

Where you need to pass order id and Method Name should be POST

 

Also you can take a reference from this api url - https://devdocs.magento.com/swagger/#!/salesInvoiceOrderV1

 

Also take a reference from this -  salesInvoiceOrderV1  from swagger ! you will get exact idea 

 

Hope it helps !!

 

if issue solved,Click Kudos & Accept as Solution

Re: In Magento2 how to print the shipping label and what things are necessary for this?

Hello @Manthan Dave,

Yes, I have to integrate this API "http://url path/V1/order/{{orderId}}/invoice" and in body {
"capture": true,
"items": [
{
"extension_attributes": {},
"order_item_id": 3,
"qty": 1
}
],
"notify": true,
"appendComment": true,
"comment": {
"extension_attributes": {},
"comment": "string",
"is_visible_on_front": 0
},
"arguments": {
"extension_attributes": {}
}
}

but i got the message 

message: 'Invoice Document Validation Error(s):\n You can\'t create an invoice without products.

Thank You