easypost / easypost-csharp Goto Github PK
View Code? Open in Web Editor NEWEasyPost Shipping API Client Library for .NET and .NET Framework applications
Home Page: https://easypost.com/docs/api
License: MIT License
EasyPost Shipping API Client Library for .NET and .NET Framework applications
Home Page: https://easypost.com/docs/api
License: MIT License
I want to use Sourcegraph for easypost-csharp code search, browsing, and usage examples. Can an admin enable Sourcegraph for this repository? Just go to https://sourcegraph.com/github.com/EasyPost/easypost-csharp. (It should only take 30 seconds.)
Thank you!
Perhaps because Event.result in this case mostly has String[] as values instead of strings.
When trying to use this package, getting the error: "Could not load file or assembly 'RestSharp, Version=100.0.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
Receiving data related errors (address errors) and environment errors via the EasyPostException. How can we tell the difference between data related errors from environmental errors?
There is a verifyAddress object getMessage that returns null when successful. Can all data related errors be returned via the verifyAddress.getMessage()?
When coding an interface, it simplifies the coding if we provide to very distinct path for returning Exceptions.
Or if it is imperative to return data errors via an Exception, can you create an EasyPostDataException?
Or simply move all the environmental Exceptions to the JAVA Exception.
Thanks for your time and support.
Hi,
at this url
https://www.easypost.com/docs/api/csharp.html#shipments-create-codesample
I find a C# sample that I have implemented in this way
static void Main(string[] args)
{
ClientManager.SetCurrent(() => new Client(new ClientConfiguration("xjv...VTQ")));
var fromAddress = new Address
{
name = "EasyPost",
street1 = "417 Montgomery Street",
street2 = "5th Floor",
city = "San Francisco",
state = "CA",
zip = "94104",
country = "US",
phone = "4153334444",
email = "[email protected]"
};
// verifications: non genera errore
// strictVerifications: solleva una EasyPost.HttpException
fromAddress.Create(strictVerifications: new List<string>() { "delivery" });
var toAddress = new Address
{
name = "Dr. Steve Brule",
street1 = "179 N Harbor Dr",
city = "Redondo Beach",
state = "CA",
zip = "90277",
country = "US",
phone = "4153334444"
};
toAddress.Create(strictVerifications: new List<string>() { "delivery" });
var parcel = new Parcel
{
length = 20.2,
width = 10.9,
height = 5.0,
weight = 140.8
};
Console.WriteLine(parcel.predefined_package);
var shipment = new Shipment
{
to_address = toAddress,
from_address = fromAddress,
parcel = parcel,
customs_info = new CustomsInfo
{
contents_type = "merchandise",
customs_certify = "false",
non_delivery_option = "return",
restriction_type = "none",
customs_items = new List<CustomsItem>
{
new CustomsItem
{
description = "Many, many EasyPost stickers.",
hs_tariff_number = "123456",
origin_country = "US",
quantity = 1,
value = 879,
weight = 140,
}
}
}
};
shipment.Create();
Console.ReadLine();
}
But I've got this error
'DateTimeInvalidLocalFormat'
Additional information: This can happen when calling DateTime.ToString using the 'z' format specifier, which will include a local time zone offset in the output. In that case, either use the 'Z' format specifier, which designates a UTC time, or use the 'o' format string, which is the recommended way to persist a DateTime in text. This can also occur when passing a DateTime to be serialized by XmlConvert or DataSet. If using XmlConvert.ToString, pass in XmlDateTimeSerializationMode.RoundtripKind to serialize correctly. If using DataSet, set the DateTimeMode on the DataColumn object to DataSetDateTime.Utc.
You should be able to fix it, here
https://github.com/EasyPost/easypost-csharp/blob/master/EasyPost/Request.cs#L106
if I read the error correctly.
Can you please provide us a feedback?
Allow apiBase
to be set from code.
Currently, this package does not work with the most current version of DotNet and C#. DotNetCore, the latest version of C# and Asp.Net has been out for over a month. Please support it.
Currently, if you try to create an Order without initializing the client, you get a null pointer on ClientManager.cs line 11. It would be nice if this threw a "No EasyPost Client Configured" message or similar.
The below doesn't seem to work... it's not enumerating the list correctly as there is only 1 shipment returned in the batch and it is always the last shipment is the list.
batch.AddShipments(new List<string>() { "shp_KYCxvzPY", "shp_C3Cm07xW" });
The only way to get it to work is to call AddShipments multiple times with a single shipment in each call... this works and creates 2 shipments in the batch.
batch.AddShipments(new List<string>() { "shp_KYCxvzPY" });
batch.AddShipments(new List<string>() { "shp_C3Cm07xW" });
This would be really helpful for associating the scan_form.updated event with the parent batch.
I've been trying for several days to get an answer to how to make ScanForm.Create work, both here in github and with your support channels. My prior ticket (#76) was closed, and I was directed to look at the unit test for ScanForm:
https://github.com/EasyPost/easypost-csharp/blob/master/EasyPostTest/ScanFormTest.cs
I created my own test shipment to plugin to the TestScanFormCreateAndRetrieve test, and it fails. I wrote a few more tests (one that attempts to create a ScanForm from an unpurchased shipment, and one that attempts to buy the shipment, THEN create ScanForm), and neither works. Could someone on your team please run these tests? My hope is you'll quickly see what I'm seeing, and be able to address. I'm assuming this is an issue with the C# client, as there must be someone generating ScanForms correctly within your system? Any help appreciated, this is holding us up from turning on our EasyPost implementation.
[TestFixture]
class TestScanFormFixture
{
private string _apiKey = "<INSERT KEY>";
[SetUp]
public void SetUp()
{
ClientManager.SetCurrent(() => new Client(new ClientConfiguration(_apiKey)));
}
[Test]
public void TestScanFormCreateAndRetrieve()
{
// XXX: This is not repeatable. Need a new shipment id each time.
List<Shipment> shipments = new List<Shipment>() {
new Shipment() { id = "shp_abc5c7d6af9f4af894e1ef17bcf74311" }
};
ScanForm scanForm = ScanForm.Create(shipments);
Assert.IsNotNull(scanForm.id);
ScanForm otherScanForm = ScanForm.Retrieve(scanForm.id);
Assert.AreEqual(scanForm.id, otherScanForm.id);
}
[Test]
public void CreateShipmentWithoutBuyingAndCreateScanForm()
{
var address1 = new Address
{
name = "Frank Smidlap",
company = "Great Company",
street1 = "100 N Main St",
street2 = null,
city = "Chicago",
state = "IL",
country = "US",
zip = "60601",
phone = "3122011234"
};
address1.Create();
var address2 = new Address
{
name = "Francine Smidlap",
company = "Great Company",
street1 = "200 N Main St",
street2 = null,
city = "Chicago",
state = "IL",
country = "US",
zip = "60601",
phone = "3122011234"
};
address2.Create();
Shipment shipment = new Shipment()
{
from_address = address1,
to_address = address2,
parcel = new Parcel
{
weight = .01,
mode = "test",
predefined_package = "Letter"
},
options = new Options
{
label_date = DateTime.Now.AddDays(2).Date
},
};
shipment.Create();
ScanForm scanForm = ScanForm.Create(new List<Shipment>() { shipment });
Assert.IsNotNull(scanForm.id);
}
[Test]
public void CreateShipmetThenBuyAndCreateScanForm()
{
var address1 = new Address
{
name = "Frank Smidlap",
company = "Great Company",
street1 = "100 N Main St",
street2 = null,
city = "Chicago",
state = "IL",
country = "US",
zip = "60601",
phone = "3122011234"
};
address1.Create();
var address2 = new Address
{
name = "Francine Smidlap",
company = "Great Company",
street1 = "200 N Main St",
street2 = null,
city = "Chicago",
state = "IL",
country = "US",
zip = "60601",
phone = "3122011234"
};
address2.Create();
Shipment shipment = new Shipment()
{
from_address = address1,
to_address = address2,
parcel = new Parcel
{
weight = .01,
mode = "test",
predefined_package = "Letter"
},
options = new Options
{
label_date = DateTime.Now.AddDays(2).Date
},
};
shipment.Create();
shipment.Buy(shipment.rates.First());
ScanForm scanForm = ScanForm.Create(new List<Shipment>() { shipment });
Assert.IsNotNull(scanForm.id);
}
}
Within the tracker return there are many missing objects. For example: Tracking_Location, est_delivery_date,signed_by and others. Am I missing something obvious here?
I already have those packages installed in their latest version (105.2.3 and 9.0.1) , but after adding EasyPost package to my project, they get overwritten by EasyPosts older own dll versions.
We are operating a site that has some integrations that require Tls12, and recently noticed that after invoking a call using easypost-csharp (for example, "address.Create"), our system's SecurityProtocol had been downgraded to Tls. Looking at your code, I see the following in security.cs:
public static SecurityProtocolType GetProtocol() {
#if NET45
return SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
#else
return SecurityProtocolType.Tls;
#endif
}
}
I couldn't find where this NET45 precompiler flag was getting set, but the version we're using seems to be setting things to "SecurityProtocolType.Tls". Here's the version we're using:
<package id="EasyPost-Official" version="2.2.6" targetFramework="net45" />
Need to add retail_rates in rate object
I'm assuming this project is a WIP correct? Or am I missing something, the code in the ReadMe does not compile as is. If so are you taking pull requests?
Based upon your API documentation:
https://www.easypost.com/docs/api/c-sharp#users
It appears that the User class should be public so that one can retrieve the balance etc. Currently it is "inaccessible due to protection level" in this code:
var me = EasyPost.User.Retrieve();
I am unable to install via NuGet. The Package Manager Console gives this error:
PM> Install-Package EasyPost-Official
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.3)'.
Install-Package : File contains corrupted data.
At line:1 char:1
+ Install-Package EasyPost-Official
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], FileFormatException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
PM>
Do you have any ideas or documentation on a manual install? Thanks.
Carrier is missing in tracker object. It is listed in the docs but not in the SDK. Also the API states est_delivery_date and in the SDK it is est_delivery_days, which seems to result in nothing on every call
When attempting to send in an object of Address to CreateAndVerify, service returns street missing. This only occurs when I only send in the AddressObject, if I send in the parameters as a dictionary the return is correct.
I was testing out your API. I downloaded the DLL from Nuget Package.
There is some sample code given there.
I tried out the code that gets me Rates for a shipment.
However, I do not see anywhere where there is a call made to the Easy Post Web Service. I think due to this, I am getting Object Reference not set to an instance of object error at the code highlighted in bold.
foreach (Rate rate in shipment.rates)
{
RateinDollar = rate.rate;
// process rates
}
I also downloaded the C# code from gihub and opened the Project in Visual Studio. Even there I did not see anything under the Service Reference folder. Is there something I am missing? Please let me know
System was working fine for over 6 months but now getting HttpException error when using UPS, SHIPMENT.POSTAGE.FAILURE, "message":"Missing or invalid ship to attention name"
This happens only when an attempted rate is purchased
UK deliveries are fine, it's just international consignments
Regards
Adam Wright FIAP
TWS
Does easy post support price estimations ? It would be nice to know how much a transaction will cost before executing the transaction. If so, how ?
This is the same issue as #50 which was closed.
When I add the EasyPost-Official package to my project via NuGet, it overwrites my existing Newtonsoft and RestSharp references. Even though RestSharp 105.2.3 is specified as a dependency for EasyPost, it replaces it with RestSharp 100.0.0.0.
Need a way to handle Events including the ability to load from the JSON sent by EasyPost
When we disable TLS 1.0 on our server, we get the following error when calling Shipment.Create():
System.NullReferenceException: Object reference not set to an instance of an object.
at EasyPost.Resource.Merge(Object source)
at EasyPost.Shipment.Create()
Is there a dependency on TLS 1.0? We have no issues with it enabled.
The Insurance
object doesn't exist in this library and should be added.
In the Create and ShipmentList methods here: https://github.com/EasyPost/easypost-csharp/blob/master/EasyPost/Shipment.cs
why do they accept Dictionary instead of IDictionary? It seems like the rest of the methods in the class try to be more generic by accepting generic types as parameters, such as IEnumerables. Is there a particular reason? I think at some point in the past, it was IDictionary.
Thanks!
It would be nice to have access to the request and response JSON for logging purposes.
I'm not sure exactly how to go about that in a simple way from the existing design, though, since the methods all create the requests, pass them to client, and interpret the responses. You'd sort of need to CQRS-ify it so that there are variants of the methods that just create the response and return it, leaving the programmer responsible for handing it to the client if they actually want it to execute. And once you do that you realize that you probably want the type parameter to be on Request<T>
in addition to the type parameter dangling off the Execute<T>(Request ...)
method, so that you could have Execute<T>(Request<T> ... )
. And it doesn't play 100% nicely with the Merge approach since weird things would happen if you executed the same request twice, but you could just make that case be an exception.
Plus I'm not sure how to get RestSharp to cough up this information either, for similar reasons.
There's got to be a simpler way. I'd almost think about introducing an HTTP proxy and scraping it from there. RestClient
does support using an IWebProxy
...
I'm attempting to use the ScanForm.Create functionality, passing local Shipments (with just their "id" property populated), and am seeing the following error returned:
{"error":{"code":"SCAN_FORM.CREATE.FAILURE","message":"Unable to create manifest. 2 of the specified shipments were not found: shp_8b44037ea7fb4294a19a3412da786942, shp_195c3f7bfe564d4889769a97e4f52f3e","errors":[]}}
I have confirmed that both of these shipments exist in our test environment.
This library currently does not have any support for Async network calls? I might modify the code for the library to make it async myself, but I am curious why async support was not added from the start?
Prior to this recent update when an address was created " date created" and "date updated" returns a date. Now they return nothing and it was not obvious that this became nullable.
This info would be really helpful!
Also, add BatchShipment.id
and BatchShipment.tracking_code
.
Is there a reason why Shipment.options doesn't have a class model? Can one be added?
According to API docs, parcel length, width, height and weight should be double. Current code shows just the weight as double and length, width and height as integers. Length, width and height should be changed to double.
public class Parcel : IResource {
public string id { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
public **int** length { get; set; }
public **int** width { get; set; }
public **int** height { get; set; }
public double weight { get; set; }
public string predefined_package { get; set; }
public string mode { get; set; }
Also, what was the reasoning for removing the enums for (e.g. predefined_package) in the latest build?
Maybe I've missed something, but right now the EasyPost API is returning an error when I try to call .Create() on an instance of a Shipment like so:
var shipment = new Shipment()
{
to_address = ...,
from_address = ...,
parcel = new Parcel()
{
weight = 16,
predefined_package = "UPSLetter"
}
};
shipment.Create();
The error returned says "Validation failed: Length is required when dimensions are supplied with parcel, Width is required when dimensions are supplied with parcel, Height is required when dimensions are supplied with parcel".
It's being raised because the client is sending shipment[parcel][length]=0
, shipment[parcel][width]=0
and shipment[parcel][height]=0
, rather than allowing null values when a predefined package is present.
It's not in the package.
How do I get around this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.