public async Task CreateShipmentTest() { var client = new EasyPostClient(Configuration.GetSetting("EasyPostToken")); var request = new CreateShipmentRequest { shipment = new Shipment { options = new Options { invoice_number = "17729NVXPBDK" }, from_address = new Address { id = "adr_c2004b0f3e864571823f955f5d421b33" }, to_address = new Address { id = "adr_db2c673615994177ae9ba5915d562a69" }, parcel = new Parcel { weight = 34.0f }, reference = "17729NVXPBDK", carrier_accounts = new List <string> { "ca_da797b3cd75a46eb9fdecf633be774fe", "ca_cc0e5d15e7954effbb62f858619588a3" } } }; var shipment = await client.CreateShipmentAsync(request); Assert.NotNull(shipment); }
public CreateShipmentResponse InvokeCreateShipment() { // Create a request. CreateShipmentRequest request = new CreateShipmentRequest(); string sellerId = "example"; request.SellerId = sellerId; string mwsAuthToken = "example"; request.MWSAuthToken = mwsAuthToken; ShipmentRequestDetails shipmentRequestDetails = new ShipmentRequestDetails(); request.ShipmentRequestDetails = shipmentRequestDetails; string shippingServiceId = "example"; request.ShippingServiceId = shippingServiceId; string shippingServiceOfferId = "example"; request.ShippingServiceOfferId = shippingServiceOfferId; string hazmatType = "example"; request.HazmatType = hazmatType; LabelFormatOptionRequest labelFormatOption = new LabelFormatOptionRequest(); request.LabelFormatOption = labelFormatOption; List <AdditionalSellerInputs> shipmentLevelSellerInputsList = new List <AdditionalSellerInputs>(); request.ShipmentLevelSellerInputsList = shipmentLevelSellerInputsList; return(client.CreateShipment(request)); }
public async Task <CreateShipmentResponse> CreateShipment(CreateShipmentRequest request) { var validator = new Validators.CreateShipmentRequestValidator(); var validateRequest = validator.Validate(request); if (!validateRequest.IsValid) { throw new Exceptions.WeAreWuunderApiException(String.Join("\n", validateRequest.Errors.Select(dl => $"{dl.PropertyName} [{dl.ErrorCode}] - {dl.ErrorMessage}").ToList())); } CreateShipmentResponse response; try { response = await apiClient.CreateShipment(request); } catch (ApiException ex) { if (((int)ex.StatusCode) == 422) { var errors = WuunderApiHelpers.FlattenErrors(ex.Content); throw new WeAreWuunderApiException(String.Join("\n", errors)); } if ((int)ex.StatusCode >= 500) { throw new WeAreWuunderApiException("Try again later. "); } throw; } return(response); }
public CreateShipmentResponse CreateInboundShipment(CreateShipmentRequest createShipmentRequest) { Address shipsFromAddress = AddressUtility.GetShipFromAddress(); CreateShipmentResponse createShipmentResponse = null; List <InboundShipmentPlanRequestItem> shipmentPlanRequestItems = createShipmentRequest .ShipmentItems .Select(s => new InboundShipmentPlanRequestItem { ASIN = s.Asin, SellerSKU = s.Sku, Quantity = s.Quantity, Condition = ItemCondition.NewItem.ToString(), QuantityInCase = s.QuantityInCase ?? 0 }) .ToList(); InboundShipmentPlanRequestItemList inboundShipmentPlanRequestItemList = new InboundShipmentPlanRequestItemList { member = shipmentPlanRequestItems }; CreateInboundShipmentPlanRequest createInboundShipmentPlanRequest = new CreateInboundShipmentPlanRequest { InboundShipmentPlanRequestItems = inboundShipmentPlanRequestItemList, Marketplace = m_marketPlaceId, SellerId = m_sellerId, ShipFromAddress = shipsFromAddress }; CreateInboundShipmentPlanResponse createInboundShipmentPlanResponse = m_fbaInboundServiceMwsClient.CreateInboundShipmentPlan(createInboundShipmentPlanRequest); CreateInboundShipmentPlanResult createInboundShipmentPlanResult = createInboundShipmentPlanResponse.CreateInboundShipmentPlanResult; if (createInboundShipmentPlanResult.InboundShipmentPlans.member.Any()) { List <InboundShipmentPlan> inboundShipmentPlans = createInboundShipmentPlanResult .InboundShipmentPlans .member .ToList(); Dictionary <string, ShipmentItem> itemsToBeAddedToShipment = createShipmentRequest .ShipmentItems.ToDictionary(k => k.Sku, v => v); DateTime today = DateTime.UtcNow.Date; List <CreatedShipment> createdShipments = inboundShipmentPlans .Select(inboundShipmentPlan => CreateShipment(inboundShipmentPlan, itemsToBeAddedToShipment, shipsFromAddress, createShipmentRequest.ShipmentName, createShipmentRequest.AreCasesRequired, today)) .ToList(); createShipmentResponse = new CreateShipmentResponse(createdShipments); } return(createShipmentResponse); }
public async Task <CreateShipmentResponse> CreateShipment(CreateShipmentRequest request) { var createShipmentRequest = _mapper.Map <ServiceAgent.CreateShipmentRequest>(request); var createShipmentResponse = await _mpServiceAgent.CreateShipment(createShipmentRequest); var response = _mapper.Map <CreateShipmentResponse>(createShipmentResponse); return(response); }
public void CreateShipmentResult(CreateShipmentFile createShipmentFile) { DataTable dt = ExcelUtility.ConvertExcelFileToDataTable(createShipmentFile.File); List <ShipmentItem> shipmentItems = dt.FromDataTableToList <ShipmentItem>() .Where(w => w.Quantity > 0) .ToList(); if (shipmentItems.Any(a => a.QuantityInCase.HasValue) && !shipmentItems.All(a => a.QuantityInCase.HasValue)) { throw new InvalidOperationException("All, or none items in the shipment must have a QuantityInCase set."); } bool areCasesRequired = shipmentItems.Any(a => a.QuantityInCase.HasValue); CreateShipmentRequest createShipmentRequest = new CreateShipmentRequest( shipmentItems, createShipmentFile.ShipmentName, areCasesRequired); CreateShipmentResponse createShipmentResponse = m_mwsProductsApi.CreateInboundShipment(createShipmentRequest); using (ExcelPackage excel = new ExcelPackage()) { foreach (CreatedShipment createdShipment in createShipmentResponse.CreatedShipments) { string worksheetName = createdShipment.ShipmentId; DataTable dtShipmentItems; if (areCasesRequired) { dtShipmentItems = createdShipment.ItemsInShipment .Select(s => new { s.Name, s.ItemNumber, s.Asin, s.Quantity, s.Cost, s.QuantityInCase, Extension = s.Cost * s.Quantity }) .ToDataTable(); } else { dtShipmentItems = createdShipment.ItemsInShipment .Select(s => new { s.Name, s.ItemNumber, s.Asin, s.Quantity, s.Cost, Extension = s.Cost * s.Quantity }) .ToDataTable(); } ExcelWorksheet wsCreatedShipment = excel.Workbook.Worksheets.Add(worksheetName); wsCreatedShipment.Cells["A1"].LoadFromDataTable(dtShipmentItems, true); } ExcelUtility.CreateExcelResponse(Response, excel, createShipmentFile.ShipmentName); } }
public async Task <CreateShipmentResponse> CreateShipment(CreateShipmentRequest request) { try { using var client = _clientFactory.CreateClient("MultiParcel"); var agentResponse = await client.PostAsync <CreateShipmentResponse>("shipments", request); return(agentResponse); } catch (HttpRequestException ex) { throw new MultiParcelException(ex.Message); } }
public CreateShipmentResponse RequestShipment(CreateShipmentRequest req) { // First generate the JSON request (for possible use by the developer later) LastJSONRequest = JsonConvert.SerializeObject(req, Formatting.Indented); LastShipJSONRequest = LastJSONRequest; // Validate the request List <ValidationResult> validationResult = Common.Validate(ref req); if (validationResult.Any()) { string errors = MyDHLAPIValidationException.PrintResults(validationResult); throw new MyDHLAPIValidationException(validationResult); } // Send the request and capture the response LastJSONResponse = SendRequestAndReceiveResponse(LastJSONRequest, "ShipmentRequest"); LastShipJSONResponse = LastJSONResponse; CreateShipmentResponse retval; try { // Deserialize the result back to an object. List <string> errors = new List <string>(); retval = JsonConvert.DeserializeObject <CreateShipmentResponse>(LastJSONResponse, new JsonSerializerSettings() { Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) { errors.Add(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }); } catch { retval = new CreateShipmentResponse(); } return(retval); }
public CreateShipmentResponse InvokeCreateShipment() { // Create a request. CreateShipmentRequest request = new CreateShipmentRequest(); string sellerId = "example"; request.SellerId = sellerId; string mwsAuthToken = "example"; request.MWSAuthToken = mwsAuthToken; ShipmentRequestDetails shipmentRequestDetails = new ShipmentRequestDetails(); request.ShipmentRequestDetails = shipmentRequestDetails; string shippingServiceId = "example"; request.ShippingServiceId = shippingServiceId; string shippingServiceOfferId = "example"; request.ShippingServiceOfferId = shippingServiceOfferId; string hazmatType = "example"; request.HazmatType = hazmatType; return(client.CreateShipment(request)); }
public async Task <Shipment> CreateShipmentAsync(CreateShipmentRequest request) { const string resource = "/shipments"; return(await PostAsync <Shipment>(resource, request)); }
public Task <CreateShipmentResponse> RequestShipmentAsync(CreateShipmentRequest req) { return(Task.Run(() => RequestShipment(req))); }
private void BtnShip_Click(object sender, EventArgs e) { ClearInputErrors(); // Validate all our inputs if (!ValidateInputs()) { MessageBox.Show("Please fix the issues on the inputs marked in red."); return; } // All validation done, send the data to GloWS. #pragma warning disable IDE0017 // Simplify object initialization try { this.Enabled = false; // Reset AWB link label llblAWB.Tag = null; llblAWB.LinkBehavior = LinkBehavior.NeverUnderline; llblAWB.ForeColor = Color.Black; llblAWB.Font = new Font(llblAWB.Font, FontStyle.Regular); // Determine if this is a dox or non-dox shipment bool isDox = !(new[] { "3", "4", "8", "E", "F", "H", "J", "M", "P", "Q", "V", "Y" }).Contains(cmbProductCode.SelectedValue.ToString()); bool isDomestic = "N" == cmbProductCode.Text; CreateShipmentRequest req = new CreateShipmentRequest(); #pragma warning restore IDE0017 // Simplify object initialization if (cbxShipmentRequestPickup.Checked) { req.Data.ShipmentInfo.DropOffType = Enums.DropOffType.RequestCourier; } else { req.Data.ShipmentInfo.DropOffType = Enums.DropOffType.RegularPickup; } string[] pltCountries = new string[] { "AE", "SA", "US" }; bool isPLT = false; /*** PLT ***/ if (!isDomestic && !isDox && _invoiceAvailable && (pltCountries.Contains(txtShipperCountry.Text) || pltCountries.Contains(txtConsigneeCountry.Text)) ) { req.Data.ShipmentInfo.PaperlessTradeEnabled = true; req.Data.ShipmentInfo.PaperlessTradeImage = _invoiceData; isPLT = true; } req.Data.ShipmentInfo.ProductCode = cmbProductCode.SelectedValue.ToString(); // SU = Standard (american) Units (LB, IN); SI = Standard International (KG, CM) if ("KG" == cmbShipmentWeightUOM.SelectedValue.ToString()) { req.Data.ShipmentInfo.UnitOfMeasurement = Enums.UnitOfMeasurement.SI; } else { req.Data.ShipmentInfo.UnitOfMeasurement = Enums.UnitOfMeasurement.SU; } // If the billing element is defined (it should be used anyway) then there is no need for the // generic shipmentInfo.Account element to be populated. //shipmentInfo.Account = txtShipperAccountNumber.Text; req.Data.ShipmentInfo.Billing = new BillilngInfo(txtShipperAccountNumber.Text, txtShipperAccountNumber.Text, Enums.AccountRole.Shipper); if (!isDomestic && !isDox) { // We have a non-dox shipment req.Data.ShipmentInfo.CurrencyCode = txtShipmentDeclaredValueCurrency.Text; } req.Data.ShipmentInfo.LabelFormat = Enums.LabelFormat.PDF; req.Data.ShipmentInfo.NumberOfPieces = 1; DateTime timestamp; if (DateTime.Now.TimeOfDay > new TimeSpan(18, 00, 00)) { timestamp = DateTime.Now.AddDays(1); timestamp = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, 10, 0, 0); } else { timestamp = DateTime.Now.AddMinutes(10); } req.Data.Timestamp = timestamp; //.RequestedShipment.ShipTimestamp = $"{timestamp:s} GMT{timestamp:zzz}"; if (!IsBlank(txtDutyAccountNumber)) { req.Data.TermsOfTrade = Enums.TermsOfTrade.DDP; } else { req.Data.TermsOfTrade = Enums.TermsOfTrade.DDU; } if (!isDox && !isDomestic) { req.Data.CustomsInformation.ShipmentType = Enums.ShipmentType.NonDocuments; Commodity commodities = new Commodity(); commodities.CustomsValue = 20M; commodities.COO = "AE"; commodities.ShipmentContents = "Test Commoditiy"; commodities.NumberOfPieces = 1; commodities.UnitPrice = 10M; commodities.Quantity = "2"; req.Data.CustomsInformation.Commodities = commodities; } else { req.Data.CustomsInformation.ShipmentType = Enums.ShipmentType.Documents; } /*** SHIPPER ***/ AddressData shipper = new AddressData(); if (!IsBlank(txtShipperCompany)) { shipper.Contact.CompanyName = txtShipperCompany.Text; } else { shipper.Contact.CompanyName = txtShipperName.Text; } shipper.Contact.PersonName = txtShipperName.Text; shipper.Contact.EMailAddress = txtShipperEMailAddress.Text; shipper.Contact.PhoneNumber = txtShipperMobileNumber.Text; shipper.Address.AddressLine1 = txtShipperAddress1.Text; shipper.Address.AddressLine2 = txtShipperAddress2.Text; shipper.Address.AddressLine3 = txtShipperAddress3.Text; shipper.Address.CityName = txtShipperCity.Text; shipper.Address.USStateCode = txtShipperState.Text; shipper.Address.CountryCode = txtShipperCountry.Text; shipper.Address.PostalOrZipCode = txtShipperPostalCode.Text; req.Data.ShipmentAddresses.Shipper = shipper; /*** CONSIGNEE ***/ AddressData consignee = new AddressData(); if (!IsBlank(txtConsigneeCompany)) { consignee.Contact.CompanyName = txtConsigneeCompany.Text; } else { consignee.Contact.CompanyName = txtConsigneeName.Text; } consignee.Contact.PersonName = txtConsigneeName.Text; consignee.Contact.EMailAddress = txtConsigneeEMailAddress.Text; consignee.Contact.PhoneNumber = txtConsigneeMobileNumber.Text; consignee.Address.AddressLine1 = txtConsigneeAddress1.Text; consignee.Address.AddressLine2 = txtConsigneeAddress2.Text; consignee.Address.AddressLine3 = txtConsigneeAddress3.Text; consignee.Address.CityName = txtConsigneeCity.Text; consignee.Address.USStateCode = txtConsigneeState.Text; consignee.Address.CountryCode = txtConsigneeCountry.Text; consignee.Address.PostalOrZipCode = txtConsigneePostalCode.Text; req.Data.ShipmentAddresses.Consignee = consignee; /*** PICKUP ***/ if (cbxShipmentRequestPickup.Checked) { req.Data.ShipmentAddresses.Pickup = req.Data.ShipmentAddresses.Shipper; } /*** PIECES ***/ Package singlePackage = new Package { Number = 1, Weight = decimal.Parse($"{txtShipmentWeight.Text}") }; int height = GetDimension(ref txtShipmentHeight); int width = GetDimension(ref txtShipmentWidth); int depth = GetDimension(ref txtShipmentDepth); if (height > 0 && width > 0 && depth > 0) { // Keep the divisor at 5000.0, this forces .NET to treate the result as a float and not an integer. singlePackage.Dimensions = new Dimensions(height, width, depth); } singlePackage.PieceContents = req.Data.CustomsInformation.Commodities.ShipmentContents; singlePackage.CustomerReferences = $"{DateTime.Now.Ticks}"; req.Data.Packages.PackageList.Add(singlePackage); /*** SPECIAL SEVICES ***/ req.Data.ShipmentInfo.SpecialServices = new SpecialServices { Service = new List <SpecialService>() }; if (isPLT) { req.Data.ShipmentInfo.SpecialServices.Service.Add(new SpecialService("WY")); } if (!req.Data.ShipmentInfo.SpecialServices.Service.Any()) { req.Data.ShipmentInfo.SpecialServices = null; } /*** GENERATE SHIPMENT ***/ GloWS glows = new GloWS_REST_Library.GloWS(Common.username, Common.password, (Common.IsProduction ? Common.restProductionBaseUrl : Common.restTestingBaseUrl)); CreateShipmentResponse resp; try { resp = glows.RequestShipment(req); } catch (GloWSValidationException gvx) { MessageBox.Show(gvx.Message, "GVX"); txtResultAWB.Text = "VALIDATION ERROR!"; return; } catch (Exception ex) { MessageBox.Show(ex.Message, "EX"); txtResultAWB.Text = "ERROR!"; return; } GloWS_Request = glows.LastJSONRequest; GloWS_Response = glows.LastJSONResponse; if (null == resp || null == resp.Data) { MessageBox.Show("There was an error in generating the shipment."); return; } // Display our results txtResultAWB.Text = (resp.Data.AWB ?? String.Empty); txtResultBookingReferenceNumber.Text = (resp.Data.BookingReferenceNumber ?? string.Empty); if (null != resp.Data.Pieces && resp.Data.Pieces.Any()) { string prefix = string.Empty; string pieces = string.Empty; foreach (Piece piece in resp.Data.Pieces) { pieces += $"{prefix}{piece.LPN}"; prefix = Environment.NewLine; } txtResultPieces.Text = pieces; } else { txtResultPieces.Text = string.Empty; } if (null != resp.Data.Labels && resp.Data.Labels.Any()) { int i = 0; // Prepare our files for viewing foreach (ShipmentImage label in resp.Data.Labels) { var tempFilename = Common.GetTempFilenameWithExtension(txtResultAWB.Text, label.ImageFormat); File.WriteAllBytes(tempFilename, label.ImageData); _generatedTempFiles.Add(tempFilename); if (0 == i++) { llblAWB.Tag = tempFilename; llblAWB.LinkBehavior = LinkBehavior.AlwaysUnderline; llblAWB.ForeColor = Color.White; llblAWB.Font = new Font(llblAWB.Font, FontStyle.Bold); } } } } finally { this.Enabled = true; } }
public CreateShipmentResponse CreateShipment(CreateShipmentRequest request) { return(connection.Call( new MWSMerchantFulfillmentServiceClient.Request <CreateShipmentResponse>("CreateShipment", typeof(CreateShipmentResponse), servicePath), request)); }
static async Task Main(string[] args) { var username = "******"; var password = "******"; var loginURL = "https://sandbox-api-applet.shipprimus.com/api/v1/login"; var quoteURL = "https://sandbox-api-applet.shipprimus.com/applet/v1/rate/multiple"; var quoteSaveURL = "https://sandbox-api-applet.shipprimus.com/applet/v1/rate/save"; var createShipmentUrl = "https://sandbox-api-applet.shipprimus.com/applet/v1/book"; Console.WriteLine("Get Token"); var token = await QuoteHelper.GetBearerTokenPostAsync(username, password, loginURL); Console.WriteLine("Get Quotes"); var quoteRequest = new QuoteRequest() { originCity = "Miami", originState = "FL", originZipcode = "33142", originCountry = "US", destinationCity = "Laredo", destinationState = "TX", destinationZipcode = "78045", destinationCountry = "US", uOM = "US", pickupDate = "06/30/2020", equipment = "Van", Accessorials = new List <string>() { "LFO", "INO", "LFD", "IND" }, freightInfo = JArray.Parse("[{'qty':3,'weight':500,'weightType':'each','length':40,'width':48,'height':48,'class':50,'hazmat':0,'commodity':'','dimType':'PLT','stack':false}]") }; var quote = await QuoteHelper.GetQuotes(quoteRequest, token, quoteURL); foreach (var item in quote.data.results.rates) { Console.WriteLine("id: " + item.id); Console.WriteLine("name: " + item.name); Console.WriteLine("SCAC: " + item.SCAC); Console.WriteLine("serviceLevel: " + item.serviceLevel); Console.WriteLine("serviceLevelCode: " + item.serviceLevelCode); Console.WriteLine("transitDays: " + item.transitDays); Console.WriteLine("total: " + item.total); Console.WriteLine("rateType: " + item.rateType); Console.WriteLine("iconUrl: " + item.iconUrl); Console.WriteLine("responseTime: " + item.responseTime); Console.WriteLine("vendorId: " + item.vendorId); foreach (var item1 in item.rateBreakdown) { Console.WriteLine("Breakdown =>>> " + item1.name + ":" + item1.total); } Console.WriteLine("--------------------------------------------------------------------------------"); } Console.WriteLine("Save Quotes"); var quoteSaveRequest = new SaveQuoteRequest() { rateId = quote.data.results.rates[0].id, originShippingLocationId = 0, destinationShippingLocationId = 0, laneDistance = 0, }; JObject jrequestsavequote = JObject.FromObject(quoteSaveRequest); var quoteSave = QuoteHelper.SaveQuote(quoteSaveURL, token, jrequestsavequote); Console.WriteLine("Create Shipment"); var createShipmentRequest = new CreateShipmentRequest() { thirdPartyReferenceNumber = "", PRONmbr = "", BOLNmbr = "testmehmet12345", BOLPrefix = "", shipper = new Location() { id = 0, name = "string", referenceNumber = "1515154", address1 = "string", address2 = "string", city = "Miami", state = "FL", zipCode = "33142", country = "US", phone = "string", fax = "string", email = "string", contact = "string", contactPhone = "string" }, consignee = new Location() { id = 0, name = "string", referenceNumber = "25551", address1 = "string", address2 = "string", city = "Laredo", state = "TX", zipCode = "78045", country = "US", phone = "string", fax = "string", email = "string", contact = "string", contactPhone = "string" }, quoteNumber = quoteSave.data != null ? quoteSave.data.results.quoteNumber:"", lineItems = JArray.Parse("[{'qty':3,'weight':500,'weightType':'each','length':40,'width':48,'height':48,'volume': 200,'dimType':'PLT','class':'50','hazmat':0,'stack':false,'stackAmount': 1,'commodity':''}]"), UOM = "US", accessorialsList = new List <string>() { "LFO", "LFO" }, insuranceAmount = 0, insuranceFreight = true, insuranceAddOn = true, brokerInformation = new BrokerInformation() { name = "", contact = "", phone = "", notes = "" }, pickupInformation = new LocationInformation() { date = "2020-07-07", type = "PO", fromTime = "08:30", toTime = "10:30" }, deliveryInformation = new LocationInformation() { date = "2020-07-09", type = "DO", fromTime = "08:30", toTime = "12:30" }, BOLInstructions = "", shipmentNotes = "" }; JObject jrequestcreateshipment = JObject.FromObject(createShipmentRequest); var quoteCreateShipment = QuoteHelper.CreateShipment(createShipmentUrl, token, jrequestcreateshipment); }