EasyPost API - print_custom_1 option won't print on label - c#

This has been driving me batty for over an hour. I'm new to EasyPost and I'm trying to put some custom text on my label (in my particular case, it is which SKU to put in the package), but it just never seemed to work. I'm using the official nuget package from easypost but am guessing it is platform independent.
Shipment shipment = new Shipment() {
to_address = toAddress,
from_address = fromAddress,
parcel = parcel
};
shipment.Create();
var lowestRate = shipment.LowestRate(includeServices: new List<string>() { "First" }, includeCarriers: new List<string>() { "USPS" });
shipment.Buy(lowestRate);
shipment.options.Add("print_custom_1", "this is some sample text");
shipment.options.Add("print_custom_2", "abc");
shipment.options.Add("print_custom_3", "xyz");
shipment.GenerateLabel("pdf");

Well, that was annoying. It makes sense when you step back from it. The issue is that the options need to be set PRIOR to creating the shipment. In my head, it was a print only concern (and it is), but there are other options can and do effect shipping costs, which means that the option needs to be set when creating the shipment. Even setting the options after you create but before you "buy" doesn't work.
See working code below:
Shipment shipment = new Shipment() {
to_address = toAddress,
from_address = fromAddress,
parcel = parcel
};
//DO THIS BEFORE CREATING!
shipment.options = new Dictionary<string, object>();
shipment.options.Add("print_custom_1", "this is some sample text");
shipment.options.Add("print_custom_2", "abc");
shipment.options.Add("print_custom_3", "xyz");
shipment.Create();
var lowestRate = shipment.LowestRate(includeServices: new List<string>() { "First" }, includeCarriers: new List<string>() { "USPS" });
shipment.Buy(lowestRate);
shipment.GenerateLabel("pdf");

Related

Stripe; how to get subscriptionId when creating a customer with a new subscription

I'm creating a new customer and adding them to a subscription in one call like so:
StripeConfiguration.SetApiKey(StripeData.ApiKey);
var customerService = new CustomerService();
var myCustomer = new CustomerCreateOptions
{
Email = stripeEmail,
Source = stripeToken,
Plan = StripeData.MonthlySubscriptionPlanId
};
Customer stripeCustomer = customerService.Create(myCustomer);
Then I used to be able to do this:
myLocalUser.StripeCustomerId = stripeCustomer.Id;
myLocalUser.StripeSubscriptionId = stripeCustomer.Subscriptions.Data[0]?.Id;
But now the API isn't returning the customer's subscriptions so the second line fails
I'm now having to call the API again with this ugly code to get the customer's subscriptionId:
if (stripeCustomer.Subscriptions != null)
{
user.StripeSubscriptionId = stripeCustomer.Subscriptions.Data[0]?.Id;
}
else
{
//get subscriptionId
var cust = customerService.Get(stripeCustomer.Id, new CustomerGetOptions
{
Expand = new System.Collections.Generic.List<string> { "subscriptions" }
});
if (cust.Subscriptions.Any())
{
stripeSubscriptionId = cust.Subscriptions.First().Id;
}
}
CustomerService.Create() doesn't have the same Expand parameter option that the Get() method does...
This is expected, as subscriptions are no longer included by default on a customer object unless you expand them since API version 2020-08-27.
Creating a customer with a source and plan is still possible (although not the recommended integration path anymore since you might run into problems with 3DS and tax rates), although since you are on a newer API version you won't get the subscriptions list back. If you can you should update to creating subscriptions via their own API.
If you however still want to use this old integration path, you can still get the subscriptions back in the customer create call, you just need to expand the subscriptions on creation:
var customerService = new CustomerService();
var myCustomer = new CustomerCreateOptions
{
Email = stripeEmail,
Source = stripeToken,
Plan = StripeData.MonthlySubscriptionPlanId
};
myCustomer.AddExpand("subscriptions");
Customer stripeCustomer = customerService.Create(myCustomer);

How to use AllowPartialMatches in Microsoft.Bot.Builder.Dialogs.Choices?

I'm using Microsoft BotFramework with Microsoft.Bot.Builder 4.0 library in C#.
I want to use Dialogs.Choices, and have been able to get simple ChoicePrompt working. However, the above link does not help much in understanding the namespace in depth. Online demos and samples are very basic, so I have to guess & experiment to understand the functionality.
Specifically, I'm looking at AllowPartialMatches, which appears to support some kind of fuzzy/similarity match. I.e. user types something without exact match, and the prompt finds the 'nearest' match. Is my guess correct?
Can someone explain and provide examples? Thanks?
In the waterfall dialog, create the dialog step as:
AddDialog(new ChoicePrompt(UNSPSCPrompt){
RecognizerOptions = new FindChoicesOptions()
{ AllowPartialMatches = true }
});
In the dialog step itself:
var choices = new List<Choice>
{
new Choice()
{
Value = "itm001",
Synonyms = new List<string> {"hotdog", "hot dog"},
Action = new CardAction()
{
Type = ActionTypes.ImBack,
Title = "Buy a hotdog",
Value = "hotdog"
}
},
new Choice()
{
Value = "itm002",
Synonyms = new List<string> {"bulldog", "bull dog"},
Action = new CardAction()
{
Type = ActionTypes.ImBack,
Title = "Buy a bulldog",
Value = "bulldog"
}
},
};
return await stepContext.PromptAsync("myPrompt",
new PromptOptions {
Prompt = MessageFactory.Text("What can I offer you?"),
RetryPrompt = MessageFactory.Text("I dont have that"),
Choices = choices,
Style = ListStyle.HeroCard
}, cancellationToken);
This will make utterance "a hot one" match "hot dog".
However, "hotdogs" will match nothing, i.e. tokens (words) need exact match.
"dog" will match either of the choices, and it seems that only the 'top' score is returned. (Fully implemented?)

Azure ML Experiment Batch Webservice Call Fails with Invalid Output Extension

I have an Azure webjob that is calling a ML training experiment via HttpRequests, leveraging the code generated in the ML webportal:
var request = new BatchExecutionRequest()
{
Inputs = new Dictionary<string, AzureBlobDataReference>() {
{
"input1",
new AzureBlobDataReference()
{
ConnectionString = _connectionString,
RelativeLocation = $"{_containerName}/{experimentId}/{tenantId}/{trainingDataFileName}"
}
},
},
Outputs = new Dictionary<string, AzureBlobDataReference>() {
{
"output1",
new AzureBlobDataReference()
{
ConnectionString = "azureStorageConnectionString",
RelativeLocation = $"{_containerName}/{experimentId}/{tenantId}/Model_2018421.ilearner"
}
},
},
GlobalParameters = new Dictionary<string, string>()
{
}
};
However, the request fails with the following message:
The blob reference:
experiments/experimentId/TenantId/Model_2018421.ilearner
has an invalid or missing file extension. Supported file extensions
for this output type are: \\".csv, .tsv, .arff\\"
I'm pretty confused about this, since it's written right the documentation all over the place that if I'm expecting a trained model to use ".ilearner" as the file extension for the model.
I've seen this question asking about the same error leveraging the DataFactory, and also this question on datascience.stackexchange. Neither one had any clues, answers, or other follow up.
Any insight on what I'm missing would be greatly appreciated!
For anyone looking for your "Don't Overthink It" moment of the day:
I needed to provide TWO output blob file references:
var request = new BatchExecutionRequest()
{
Inputs = new Dictionary<string, AzureBlobDataReference>() {
{
"input1",
new AzureBlobDataReference()
{
ConnectionString = _connectionString,
RelativeLocation = $"{_containerName}/{experimentId}/{tenantId}/{trainingDataFileName}.csv"
}
},
},
Outputs = new Dictionary<string, AzureBlobDataReference>() {
{
"output1",
new AzureBlobDataReference()
{
ConnectionString = _connectionString,
RelativeLocation = $"{_containerName}/{experimentId}/{tenantId}/{outputFileNameCsv}.csv"
}
},
{
"output2",
new AzureBlobDataReference()
{
ConnectionString = _connectionString,
RelativeLocation = $"{_containerName}/{experimentId}/{tenantId}/{outputFileNameIlearner}.ilearner"
}
},
},
GlobalParameters = new Dictionary<string, string>()
{
}
};
There's an old saying in American English about not making assumptions, and I assumed the second output was an optional parameter used in batch operations. Since I'm not actually looking for more than one result from each call, I thought I was safe to remove the second output parameter.
TL/DR: Keep all the parameters the webservice portal's "Consume" tab generates, and make sure the first one is a .csv file reference.

Silverlight -CRM2011 : The Currency Cannot Be null

I use Silverlight o-data services to interact with crm 2011 from my application
When I try to save the data in the entity SalesOrder as follows:
Private void beginSave()
{
SalesOrder orderHeader = new SalesOrder();
orderHeader.TransactionCurrencyId = new EntityReference(){ Id = new Guid("77D695B5-ACB4-E111-97BC-00155D55B216"), LogicalName="transactioncurrency" };
orderHeader.AccountId = new EntityReference() { Id = new Guid(MyClassGeneralOrder.customerId), LogicalName = "account" };
orderHeader.Name = "My Name";
Money totalAmount = new Money(); Money totalAmountBase = new Money();
Money totalTaxe = new Money(); Money totalAmountLessFreight = new Money();
totalAmount.Value = (decimal)MyClassGeneralOrder.InvoiceTotal;
totalAmountBase.Value = (decimal)MyClassGeneralOrder.totalRetail;
totalTaxe.Value = (decimal)MyClassGeneralOrder.totalCharges;
totalAmountLessFreight.Value = (decimal)MyClassGeneralOrder.totalNet;
orderHeader.TotalAmount = totalAmount;
orderHeader.TotalAmount_Base = totalAmountBase;
orderHeader.TotalTax = totalTaxe;
orderHeader.TotalAmountLessFreight = totalAmountLessFreight;
orderHeader.Description = element.Name;
orderHeader.PriceLevelId = new EntityReference() { Id = new Guid("03C5C4CB-EBD0-E111-8140-00155D55B216"), LogicalName="pricelevel" };
_context.AddToSalesOrderSet(orderHeader);
_context.BeginSaveChanges(SaveCallback, orderHeader);
}
private void SaveCallback(IAsyncResult result)
{
_context.EndSaveChanges(result);
}
In my function EndSaveChanges (result), I receive this error message : : « The Currency Cannot Be null ».
I don't understand why, because my "orderHeader.TransactionCurrencyId" field is not null.
I assuming that all of your other Currency fields are populated?
Any chance you have another plugin that is firing as a result of yours that is throwing the exception. That always seems to bite me. Try disabling all other plugins except for the one you're working on...
If you're still having issues, turn on crm server side tracing. You'll get much better error information. Use the CRM diagnostic tool to turn on trace logging: http://crmdiagtool2011.codeplex.com
Mostly your Guid is wrong and it's resulting in null. Make sure it's the correct GUID you are using or not. Run an advanced find against the entity and find the correct GUID. It's not a good idea to hard code the GUID. If you deploy your solutions to some other org it won't work.

jQuery Treeview - Where do I start?

I want a treeview of dates with year, month and days. I will be using $.ajax to retrieve webservice json data. That bit is easy, but not sure how the json data should be constructed for the jquery treeview to work.
I am using http://jquery.bassistance.de/treeview/demo/ (not used before) in creating my treeview.
I've not used bassistance but have used jstree which has good documentation and examples
This link may also be helpful: http://www.jstree.com/documentation/json_data
An example of the type of json sent down might be
new object[]{
new {
attr = new {id = "node1"},
state = "closed",
data = new {
title = "Title1",
icon = "ico-database"
}
},
new {
attr = new {id = "node2"},
state = "closed",
data = new {
title = "Title2",
icon = "ico-database"
}
}
};

Categories