Closed mattglet closed 4 years ago
Hi Matt,
The Rates Carrier and Parcel Weights are mandatory fields and cannot be null.
Following is examples for using SDK
The API’s used in back of SDKs to create shipment is as follows:
https://shipping.pitneybowes.com/api/post-shipments.html
Regards Amit
From: Matt Gillette notifications@github.com Sent: Tuesday, February 18, 2020 12:56 AM To: PitneyBowes/pitneybowes-shipping-api-csharp pitneybowes-shipping-api-csharp@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [PitneyBowes/pitneybowes-shipping-api-csharp] Does this SDK work at all? (#31)
CAUTION: THIS EMAIL IS FROM AN EXTERNAL SOURCE. Internet links, office documents or other attachments may contain viruses. Do not click on a link, open or enable any file unless you trust the sender.
I'm getting these errors from my code:
How can Carrier and Weight be reported as null in this scenario?
var shipment = (Shipment)ShipmentFluent
.FromAddress((Address)AddressFluent<Address>.Create()
.PostalCode(fromZip)
.CountryCode(fromCountryIso2))
.ToAddress((Address)AddressFluent<Address>.Create()
.PostalCode(toZip)
.CountryCode(toCountryIso2));
var parcel = new Parcel
{
Weight = new ParcelWeight { Weight = Convert.ToDecimal(weightOz), UnitOfMeasurement = UnitOfWeight.OZ }
};
var rate = new Rates
{
Carrier = Carrier.USPS,
ServiceId = Services.FCM,
ParcelType = ParcelType.PKG
};
shipment.Parcel = parcel;
shipment.AddRates(rate);
var ratesResponse = Api.Rates(shipment).GetAwaiter().GetResult();
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FPitneyBowes%2Fpitneybowes-shipping-api-csharp%2Fissues%2F31%3Femail_source%3Dnotifications%26email_token%3DAE2BPSV57W6EG5VRJ45DMGLRDLQGDA5CNFSM4KWXJS6KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IODZ7IQ&data=02%7C01%7Camit.singh%40pb.com%7C16445a5d7a424ed678c808d7b3df4805%7C8a4925a9fd8e4866b31cf719fb05dce6%7C0%7C0%7C637175643874002260&sdata=UMFToZBbazCoQlHZFAAprfeeIlGDZ0TSg%2Fp2mPS38tA%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAE2BPSXNQ6YL2VYSYYKQQ2TRDLQGDANCNFSM4KWXJS6A&data=02%7C01%7Camit.singh%40pb.com%7C16445a5d7a424ed678c808d7b3df4805%7C8a4925a9fd8e4866b31cf719fb05dce6%7C0%7C0%7C637175643874012256&sdata=8n6p6BPi7Re9wj1iZYyVV5MAO2eSoW%2B2NLhGRxBmFnA%3D&reserved=0.
Hello Amit, thanks for the reply.
However, in my code above, I am populating the Rate Carrier and the Parcel Weight. But the error I'm receiving is that they are both null/blank.
Hi Matt,
Please try following sample
var shipment = ShipmentFluent<Shipment>.Create()
.ToAddress((Address)AddressFluent<Address>.Create()
.AddressLines("643 Greenway RD")
.PostalCode("28607")
.CountryCode("US")
.Verify()
)
.MinimalAddressValidation("true")
.FromAddress((Address)AddressFluent<Address>.Create()
.Company("Pitney Bowes Inc.")
.AddressLines("27 Waterview Drive")
.Residential(false)
.CityTown("Shelton")
.StateProvince("CT")
.PostalCode("06484")
.CountryCode("US")
.Person("Paul Wright", "203-555-1213", "john.publica@pb.com")
)
.Parcel((Parcel)ParcelFluent<Parcel>.Create()
.Dimension(12, 12, 10)
.Weight(16m, UnitOfWeight.OZ)
)
.Rates(RatesArrayFluent<Rates>.Create()
.USPSPriority<Rates, Parameter>()
.InductionPostalCode("06484")
)
.Documents((List<IDocument>)DocumentsArrayFluent<Document>.Create()
.ShippingLabel(ContentType.BASE64, Size.DOC_4X6, FileFormat.ZPL2)
)
.ShipmentOptions(ShipmentOptionsArrayFluent<ShipmentOptions>.Create()
.ShipperId(sandbox.GetConfigItem("ShipperID"))
.AddToManifest()
)
.TransactionId(Guid.NewGuid().ToString().Substring(15));
var label = Api.CreateShipment((Shipment)shipment).GetAwaiter().GetResult();
Regards Amit
Thank you Amit. It turns out I was missing this which is vital to the execution of the call.:
Model.RegisterSerializationTypes(session.SerializationRegistry);
I've added it and things seem to be working now.
I'm getting these errors from my code:
How can Carrier and Weight be reported as null in this scenario?