This guide illustrates how to use the SDK to implement the following method patterns:
- CREATE
- LIST
- GET
- DELETE
- VERIFY (BANK ACCOUNTS)
- UPDATE
$ dotnet add package lob.dotnet
using lob.dotnet;
Configuration config = new Configuration();
config.Username = "<<YOUR API KEY HERE>>"
You then instantiate the specific resource API that you need access to as follows:
api = new AddressesApi(config);
This abstracts the request/response interaction out of the calling code such that you create the resource and pass it to the corresponding API in a try/catch such that any non-success is an ApiException
that must be handled.
Here is a sample of the CREATE method
AddressEditable addressEditable = new AddressEditable(
"210 King St", // addressLine1
"# 6100", // addressLine2
"San Francisco", // addressCity
"CA", // addressState
"94107", // addressZip
CountryExtended.US, // addressCountry
"Harry - Office", // description
"Harry Zhang", // name
"Lob", // company
"5555555555", // phone
"[email protected]" // email
);
try {
Address result = api.create(addressEditable);
} catch (ApiException e) {
Console.WriteLine(e.ToString());
}
Here is a sample of the LIST method:
List<string> includeList = new List<string>();
includeList.Add("total_count");
Dictionary<String, String> metadata = new Dictionary<String, String>();
metadata.Add("name", "Harry");
Dictionary<String, DateTime> dateCreated = new Dictionary<String, DateTime>();
DateTime dateCreatedDate = DateTime.Today.AddMonths(-1);
dateCreated.Add("lt", dateCreatedDate);
try {
AddressList response = api.list(
2, // limit
null, // before
null, // after
includeList, // include
dateCreated, // dateCreated
metadata // metadata
);
} catch (ApiException e) {
Console.WriteLine(e.ToString());
}
Here is a sample of the GET method:
try {
Address response = api.get("adr_fa85158b26c3eb7c");
} catch (ApiException e) {
Console.WriteLine(e.ToString());
}
Here is a sample of the DELETE method:
try {
AddressDeletion response = api.delete("adr_43769b47aed248c2");
} catch (ApiException e) {
Console.WriteLine(e.ToString());
}
Here is a sample of the BANK ACCOUNT VERIFY method:
List<int> amounts = new List<int>();
amounts.Add(25);
amounts.Add(63);
BankAccountVerify verification = new BankAccountVerify(amounts);
try {
BankAccount verified_account = api.verify("bank_dfceb4a2a05b57e", verification);
} catch (ApiException e) {
Console.WriteLine(e.ToString());
}
Here is a sample of the UPDATE method:
TemplateUpdate update = new TemplateUpdate("update template", "vrsn_362184d96d9b0c9");
try {
api.update("tmpl_c94e83ca2cd5121", update);
} catch (ApiException e) {
Console.WriteLine(e.ToString());
}