{"tutorial":{"algolia":{"publishPending":false,"recordCount":11,"updatedAt":"2026-06-12T01:28:48.392Z"},"_id":"65f9f363341e8b005fd5fdf1","title":"Get Shipping Label","description":"Learn how to fetch the shipping label for the order by calling the `createShippingLabel` operation.\n\nFind the full code here:\n[C#](https://github.com/amzn/selling-partner-api-samples/blob/main/use-cases/vendor-direct-fulfillment/code/csharp/src/sp-api-csharp-app/lambda/getShippingLabel.cs)\n\n${VDF}$","emoji":"🛳️","backgroundColor":"#232f3d","referenceDisplay":[],"published":true,"hero":false,"slug":"get-shipping-label","response":"","previousSlug":"","slugUpdatedAt":"2024-03-19T18:15:06.384Z","revision":10,"steps":[{"title":"Update the order status in the Orders database table","body":"If the order acknowledgment transaction status is successful, update the order status to `ACKNOWLEDGED` in the Orders database table by calling the `UpdateOrder` function.","lineNumbers":["1"]},{"title":"Initialize the Shipping Label API client","body":"Initialize the Shipping Label API client by providing the region code.","lineNumbers":["4"]},{"title":"Build the CreateShippingLabel request","body":"Build the `CreateShippingLabelRequest` object from the order details.","lineNumbers":["6-9"]},{"title":"Build and execute the restricted resource path","body":"Since `CreateShippingLabel` is a restricted operation, it requires a Restricted Data Token to be used in the `x-amz-access-token` of the API call. The Restricted Resource Path needs to be passed on the method that executes the call.\n \n Pass the following as arguments to the method that calls the API:\n - region\n - `RestrictedResourcePath`\n - REST Method\n - JSON `CreateShippingLabelRequest` body\n - order ID","lineNumbers":["14"]},{"title":"Deserialize the Shipping Label API response","body":"Deserialize the Ship Label API response into a `ShippingLabel` object if the API response is successful.","lineNumbers":["16-18"]},{"title":"Extract shipping information from the Shipping Label","body":"Iterate over labels in the `ShippingLabel` object and create a list of tracking numbers and ship methods to store in the Orders DB table.","lineNumbers":["29-32"]},{"title":"Decode the label content","body":"Decode the shipping label content from Base64 encoding to its original byte array format with the `decodeLabelContent` function.","lineNumbers":["34-36"]},{"title":"Store the label in an Object Storage Service","body":"Store the label in an Object Storage Service with the `storeLabelAsync` function.","lineNumbers":["37-38"]},{"title":"Generate a presigned URL","body":"Use the `generatePreSignedURL` function to generate a presigned URL for the label.","lineNumbers":["42"]},{"title":"Update shipping information for the order in Orders database table","body":"Update the ship methods, tracking numbers, and presigned URLs of the shipping labels for the order in the Orders DB table.","lineNumbers":["49-59"]},{"title":"Send an email with the presigned URL of the shipping labels","body":"Send an email message with presigned label URLs of the shipping labels.","lineNumbers":["62-63"]}],"snippet":{"endpoint":{"method":"","slug":"","title":""},"codeOptions":[{"code":"UpdateOrder(DFOrdersTableName, orderId, \"orderStatus\", Constants.ACKNOWLEDGED_ORDER_STATUS);\nLambdaLogger.Log(\"Order Status updated to \" + Constants.ACKNOWLEDGED_ORDER_STATUS + \" in \" + DFOrdersTableName + \" DynamoDB table for Order: \" + orderId);\n\nVendorShippingLabelsApi vendorShippingLabelsApi = ApiUtils.getVendorShippingLabelApi(regionCode);\n\nPartyIdentification sellingPartyId = new PartyIdentification(input.dfOrder.sellingPartyId.ToString());\nPartyIdentification shipFromPartyId = new PartyIdentification(input.dfOrder.shipFromPartyId.ToString());\nCreateShippingLabelsRequest createShippingLabelsRequest = new CreateShippingLabelsRequest(sellingPartyId, shipFromPartyId);\nString createShippingLabelsRequestJSONBody = JsonConvert.SerializeObject(createShippingLabelsRequest);                \n\nvar localVarPathParams = new Dictionary<String, String>();\nlocalVarPathParams.Add(\"orderNumber\", orderId);\n\nIRestResponse shippingLabelResponse = (IRestResponse)ApiUtils.buildAndExecuteRestrictedRequest(regionCode, Constants.SHIP_LABEL_API_RESTRICTED_RESOURCE_PATH, RestSharp.Method.POST, createShippingLabelsRequestJSONBody, localVarPathParams);\n\nif (shippingLabelResponse.StatusCode == System.Net.HttpStatusCode.OK)\n{\n    ShippingLabel shippingLabel = (ShippingLabel)JsonConvert.DeserializeObject(shippingLabelResponse.Content, typeof(ShippingLabel));\n\n    //---START---Store the label in S3 and generate a presignedURL --> Has to be looped based on the number of labels returned\n    AWSConfigsS3.UseSignatureVersion4 = true;\n    AmazonS3Client s3Client = new AmazonS3Client();\n\n    List<String> trackingNumbersList = new List<String>();\n    List<String> shipMethodsList = new List<String>();\n    List<String> preSignedUrlList = new List<String>();\n\n    //Store each of the labels returned by the API for the Order in S3 and generate pre-signed URL\n    foreach (LabelData labelData in shippingLabel.LabelData)\n    {\n        trackingNumbersList.Add(labelData.TrackingNumber);\n        shipMethodsList.Add(labelData.ShipMethod);\n\n        //Store the label in S3 bucket\n        String objectKey = orderId + Guid.NewGuid();\n        byte[] decodedLabelContent = decodeLabelContent(labelData.Content);\n        MemoryStream labelContentMS = new MemoryStream(decodedLabelContent);\n        storeLabelAsync(s3Client, s3BucketName, objectKey, labelContentMS);\n        LambdaLogger.Log(\"Label successfully stored in S3 bucket: \" + s3BucketName + \" for Order: \" + orderId);\n\n        //Generate presigned URL and add it to preSignedUrlList            \n        presignedUrl = generatePreSignedURL(s3Client, s3BucketName, objectKey, 1);\n        preSignedUrlList.Add(presignedUrl);\n        LambdaLogger.Log(\"Presigned URL successfully generated for Shipping label for Order: \" + orderId);\n    }\n\n    //---END---Store the label in S3 and return a presignedURL\n\n    //Update the Shipping Information for the order in Orders Dynamo DB table\n    String actualShipMethods = String.Join(\",\", shipMethodsList);\n    String trackingNumbers = String.Join(\",\", trackingNumbersList);\n    String preSignedUrlLabels = String.Join(\"     ,     \", preSignedUrlList);\n\n    if ((UpdateOrder(DFOrdersTableName, orderId, \"actualShipMethod\", actualShipMethods)) \n        && (UpdateOrder(DFOrdersTableName, orderId, \"trackingNumber\", trackingNumbers))\n        && (UpdateOrder(DFOrdersTableName, orderId, \"labelPreSignedURL\", preSignedUrlLabels)))\n    {\n        LambdaLogger.Log(\"DFOrders Dynamo DB updated with shipping information for Order ID: \" + orderId);\n    }\n\n    //-----START---Publish message to SNSTopic\n    String emailMessage = \"Link to download the Shipping Labels for Order Number: \" + orderId + \" is: \" + preSignedUrlLabels;\n    String messageId = PublishToSNSTopic(NotificationSNSTopicARN, emailMessage);\n","highlightedSyntax":"text/x-csharp","language":"csharp","name":"C#"}]},"project":"615737a581405300f2649fbd","version":"64da85507e9e01003fb6c349","createdAt":"2024-03-19T20:19:47.591Z","updatedAt":"2026-06-12T01:28:48.392Z","order":16,"__v":4,"stepCount":11,"id":"65f9f363341e8b005fd5fdf1"}}