magento / devdocs

[Deprecated] Magento Developer Documentation
Open Software License 3.0
674 stars 1.76k forks source link

Couldn't save shipment data #527

Closed srinivasanithin closed 8 years ago

srinivasanithin commented 8 years ago

When were are trying to create a shipment record with tracks as part of the request it fails with could not save shipment data when parent id field is missing. Here I cannot give parent id field on tracks array as the shipment is not yet saved.

sample data { "entity": { "orderId" : 40, "items": [{ "orderItemId" : 72, "qty": 1 }],

     "tracks": [{
        "carrier_code": "custom",
        "description": "random",
        "order_id": 6,
        "title": "titile1",
        "track_number": "test1234",
        "weight": "0.1"
    }]

}
ghost commented 8 years ago

If you're asking a general technical question, we recommend stackexchange.magento.com or the Magento forum. If this is in relation to a documentation error, please clarify.

srinivasanithin commented 8 years ago

I am asking clarity on documentation as this rest api appears we can create the tracks along with shipmentData in POST shipment call but when using the api it is not allowing to do so. if cannot use the tracks in the ShipmentData to create can this tracks and Comments be removed from that api request?

cspruiell commented 8 years ago

Hi @srinivasanithin. Can you clarify which API call are you using and to which part of the documentation are you referring?

srinivasanithin commented 8 years ago

API : POST v1/shipment API

Comment : Here is the request I am using for the creating the shipment and add track or comment while creating the shipment

{ "entity": { "orderId": 54, "items": [ { "orderItemId": 99, "qty": 1 } ], "tracks": [ { "carrierCode": "UPS", "orderId": 54, "title": "ground", "trackNumber": "12345678" } ], "comments": [ { "comment": "test comment" } ] } }

srinivasanithin commented 8 years ago

Any update on this question ?

dkvashninbay commented 8 years ago

Hi @srinivasanithin,

I've tested your request and the strategy for adding new shipments is the following:

  1. Create shipping itself POST V1/shipment/
{
  "entity":{
    "orderId":1,
    "store_id":1,
   "items":[{"orderItemId":2,"qty":1}]
   }
}
  1. Read entity_id of created shipment entity, suppose it is 13
  2. Add Track POST /v1/shipment/track
{
  "entity":{
        "carrierCode":"Custom Value",
        "orderId":1,
        "parent_id":13,
        "title":"ground",
        "trackNumber":"12345678"
    }
}

The similar for comments.

srinivasanithin commented 8 years ago

@dkvashninbay I think I was not clear in issue statement. I am seeing an option to send tracking and comment information in POST/V1/Shipment API call which is why I am assuming I can use single api call to make a shipment in Magento along with tracking number information and comments. I know there is separate API call to add tracking and comments. I am asking for single confirmation if this POST/V1/Shipment api call can be used or cannot be used for all three purpose(shipment, track and comments

cspruiell commented 8 years ago

Internal ticket MAGETWO-50202 has been created for further investigation.

mujtaba2012 commented 8 years ago

Hey Guys, I am also facing the same issue. Per Shipment API documentation salesShipmentRepositoryV1, it accepts both tracking and comments array for a POST call, but when I send these on POST /V1/shipment/ , the request fails as it is expecting parentId of the shipment (which is not even created yet).

Sample Request { "entity" : { "orderId" : 123, "items" : [{ "orderItemId" : 101, "qty" : 1 } ], "tracks" : [{ "carrierCode" : "UPS", "orderId" : 123, "title" : "ground", "trackNumber" : "12345678" } ], "comments" : [{ "comment" : "Make me proud!" } ] } }

Sample Response { "message": "Could not save shipment" }

However, another bug is that if I send any other parentId, say Id# 1001 (Id of another shipment) in tracks or comments, the request is successful, and I get the response back (say Id of the shipment created is 2001) which shows tracks and comments array in the new shipment created, but still have parent Id of 1001. But when I make the call to GET v1/shipment/2001/tracks, I don't get any tracks, but instead, they get attached to 1001.

Sample Request { "entity" : { "order_id" : 52, "items" : [{ "order_item_id" : 97, "qty" : 1 } ], "tracks" : [{ "carrierCode" : "UPS", "order_id" : 52, "title" : "ground", "trackNumber" : "12345678", "parentId" : 1001 } ] } }

Sample Response: { "created_at" : "2016-03-09 11:43:51", "entity_id" : 2001, "increment_id" : "3000000052", "order_id" : 52, "packages" : [], "updated_at" : "2016-03-09 11:43:51", "items" : [{ "entity_id" : 277, "order_item_id" : 97, "parent_id" : 185, "qty" : 1 } ], "tracks" : [{ "carrier_code" : "UPS", "created_at" : "2016-03-09 11:43:51", "description" : null, "entity_id" : 46, "order_id" : 52, "parent_id" : 1001, "qty" : null, "title" : "ground", "track_number" : "12345678", "updated_at" : "2016-03-09 11:43:51", "weight" : null } ], "comments" : null }

So to conclude, it seems that the POST shipment call can add tracking and comments, but if the parentId is not present its not automatically attaching those with the shipment being created. Other issue is that if a parentId is given for another shipment its attaching those to different shipment, and still returns the info in response.

NadiyaS commented 8 years ago

Hi @mujtaba2012 , thanks for reporting additional case. It will be added to existed Internal ticket MAGETWO-50202.

tanberry commented 8 years ago

Thanks, @NadiyaS ! And agreed, thanks also to @mujtaba2012 and @srinivasanithin for idenitifying this issue; we really appreciate the community's help and contributions! @keharper on the Magento DevDocs team will be watching the internal ticket and updating the docs as needed.

mujtaba2012 commented 8 years ago

Hey @keharper , any news on this?

JaggedJax commented 8 years ago

This leads to the same issue with Magento1 where you couldn't trigger an email to be sent to the customer because the email would be sent right after the first step when there was no tracking added yet. There was an undocumented API call for Magento1 (salesOrderShipmentSendInfo) that allowed you to trigger it after the second step to work around this.

The solution for Magento2 seems to be POSTing to salesShipmentManagementV1 aka: /V1/shipment/{id}/emails

srinivasanithin commented 8 years ago

Hi @magento-team

Is it safe to assume we will need to use different API calls for shipments, tracks and comments. We cannot use single api for created shipment, track and comments ? Or this is being tracked as bug to fix?

Can you provide update on it?

andyworsley commented 8 years ago

Also interested in the plan for this. Seems trivial for M2 to save the tracking information after it has created the shipment and fill in the parent_id value itself.

leeuweriq commented 8 years ago

Hi @magento-team,

I am running into the exact same problem here when trying to add a comment when POSTing a shipment (running Magento 2.1.0). Any updates on this issue? Will this issue be fixed or should we be using three endpoints (shipment, track, comment) to add tracking info to a shipment?

keharper commented 8 years ago

@leeuweriq We'll be providing a new API in an upcoming patch (2.0.x and 2.1.x) that allows you to perform these tasks in one call. In the meantime, it looks like you'll have to use multiple calls.

keharper commented 8 years ago

Magento added POST /V1/order/{orderId}/ship in 2.0.10 and 2.1.2. Its payload is

{
  "items": [
    {
      "extension_attributes": {},
      "order_item_id": 0,
      "qty": 0
    }
  ],
  "notify": true,
  "appendComment": true,
  "comment": {
    "extension_attributes": {},
    "comment": "string",
    "is_visible_on_front": 0
  },
  "tracks": [
    {
      "extension_attributes": {},
      "track_number": "string",
      "title": "string",
      "carrier_code": "string"
    }
  ],
  "packages": [
    {
      "extension_attributes": {}
    }
  ],
  "arguments": {
    "extension_attributes": {}
  }
}
keharper commented 8 years ago

Since MAGETWO-50202 is closed and the code fixes have been published, I'm closing this issue.

eplata1991 commented 4 years ago

Hi!

Fix it!!!

Step 1: Create invoice https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-create-invoice.html

Step 2: Create ship The orderId is: entity_id from table sales_order URL: host/rest/V1/order/orderId/ship

Body { "entity": { "orderId":8961, "store_id":1, "items": [ { "order_item_id": 4723, "qty": 1 } ] } }

Postman pictures imagen

DataBase imagen