CRM 2016 exposes odata/web api, and has functions and actions out of the box.
With the organization service, we can issue a request like this:
// Create the van required resource object.
RequiredResource vanReq = new RequiredResource
{
ResourceId = _vanId,
ResourceSpecId = _specId
};
// Create the appointment request.
AppointmentRequest appointmentReq = new AppointmentRequest
{
RequiredResources = new RequiredResource[] { vanReq },
Direction = SearchDirection.Backward,
Duration = 60,
NumberOfResults = 10,
ServiceId = _plumberServiceId,
// The search window describes the time when the resouce can be scheduled.
// It must be set.
SearchWindowStart = DateTime.Now.ToUniversalTime(),
SearchWindowEnd = DateTime.Now.AddDays(7).ToUniversalTime(),
UserTimeZoneCode = 1
};
// Verify whether there are openings available to schedule the appointment using this resource
SearchRequest search = new SearchRequest
{
AppointmentRequest = appointmentReq
};
SearchResponse searched = (SearchResponse)_serviceProxy.Execute(search);
if (searched.SearchResults.Proposals.Length > 0)
{
Console.WriteLine("Openings are available to schedule the resource.");
}
Is it possible to mimic this functionality using functions/action or any other odata functionality?
I believe that the request should be something like this:
crmOrg/api/v8.1/Search(AppointmentRequest=#request)?#request=
However, I'm not sure how to encode the rest of the request.
The parameter goes like:
http://yourcrm.org/org/api/data/v8.1/Search(AppointmentRequest=#ar)/?#ar={SearchWindowStart:%272017-01-01%27,Duration:60,NumberOfResults:10}
it is url encoded json of serialized AppointmentRequest class.
{
SearchWindowStart:'2017-01-01',
Duration: 60,
NumberOfResults:10,
etc...
}
More info here: https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.appointmentrequest.aspx
ODATA reference: http://odata.github.io/WebApi/04-06-function-parameter-support/
Related
we are experiencing problems with API authentication of our project in asp-net core 3.1. Specifically we have integrated the text-to-speech service provided by Google. Locally everything works correctly, but this does not happen when the web-app is online.
try
{
var path = "C://GoogleVoice//food-safety-trainer-47a9337eda0f.json";
var credential = GoogleCredential.FromFile(path);
var storage = StorageClient.Create(credential);
TextToSpeechClient client = TextToSpeechClient.Create();
var test = client.GrpcClient;
// The input can be provided as text or SSML.
SynthesisInput input = new SynthesisInput
{
Text = text
};
VoiceSelectionParams voiceSelection = new VoiceSelectionParams();
voiceSelection.LanguageCode = "it-IT";
voiceSelection.Name = "it-IT-Wavenet-A";
voiceSelection.SsmlGender = SsmlVoiceGender.Female;
// The audio configuration determines the output format and speaking rate.
AudioConfig audioConfig = new AudioConfig
{
AudioEncoding = AudioEncoding.Mp3
};
SynthesizeSpeechResponse response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);
var result = _mp3Helper.SaveFile(response);
if (result.Item1 == "Success")
return Json(new { Result = true, Value = result.Item2 });
else
return Json(new { Result = false, Error = result.ToString() });
}
catch(Exception ex)
{
return Json(new { Result = false, Error = ex.Message.ToString() });
}
The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
Assuming you want to use the same service account for both Speech and Storage, you need to specify the credentials for the text-to-speech client. Options:
Set the GOOGLE_APPLICATION_DEFAULT_CREDENTIALS environment variable to refer to the JSON file. Ideally, do that as part of deployment configuration rather than in your code, but you can set the environment variable in your code if you want to. At that point, you can remove any explicit loading/setting of the credential for the Storage client.
Specify the CredentialPath in TextToSpeechClientBuilder:
var client = new TextToSpeechClientBuilder { CredentialPath = path }.Build();
This will load a separate credential.
Specify the credential's token access method via the TokenAccessMethod property in TextToSpeechClientBuilder:
var client = new TextToSpeechClientBuilder
{
TokenAccessMethod = credential.GetAccessTokenForRequestAsync
}.Build();
I have an application that uses a deep integration with Stripe. My platform is occasionally charging the connected accounts and I am storing information about these charges in the metadata of the charge itself.
I want to display this information back to the connected account so I am using the Charge Service to list charges. However I want to filter that list based on some metadata key/value pair so that I don't have to list all of the charges each time, for every connected account.
Is there a clever way of doing this?
Filtering based on metadata is not supported.
Since you are doing this across Connected accounts, a better approach would be to store the Charge ID and metadata on your end so that you don't have to list and paginate through charges, looking for particular metadata.
Stripe recently added Search API that allows search by metadata. Currently, it does not have .NET / C# integration but you can query using HTTP call directly:
Example from their docs:
curl https://api.stripe.com/v1/search/charges \
-u sk_test_daHanKyJOCiXCeBsa65biLML00wylimZ8S: \
--data-urlencode "query=metadata['key']:'value'" \
-H "Stripe-Version: 2020-08-27;search_api_beta=v1" \
-G
I was able to accomplish this with the "TransferGroup" property of the ChargeCreateOptions object. I basically set the TransferGroup property to a unique value for each connected account which I can then query later.
CREATE THE CHARGE
//THERE IS NO ID IN THE REQUEST OPTIONS BECAUSE
//WE ARE USING THE PLATFORM
var requestOptions = new RequestOptions()
{
ApiKey = {API Key}
};
//CHARGE OPTIONS
var chargeOptions = new ChargeCreateOptions
{
Amount = {AMOUNT},
Currency = "usd",
Description = $"Platform Charge",
SourceId = {StripeId},
Metadata = {MetaData},
TransferGroup = {Unique String For Each Connected Account}
};
//CREAT AND RETURN THE CHARGE
var chargeService = new ChargeService();
return chargeService.Create(chargeOptions, requestOptions);
QUERY THE PLATFORM CHARGES BASED ON TRANSFER GROUP
public List<Charge> StripePlatformCharges(string apiKey, int days, string transferGroup)
{
try
{
RequestOptions requestOptions = new RequestOptions()
{
ApiKey = apiKey
};
ChargeListOptions chargeListOptions = new ChargeListOptions()
{
CreatedRange = new DateRangeOptions()
{
GreaterThanOrEqual = DateTime.Now.AddDays(-days)
},
TransferGroup = transferGroup
};
ChargeService chargeService = new ChargeService();
return chargeService.List(chargeListOptions, requestOptions).ToList();
}
catch (Exception ex)
{
throw new Exception("Error getting stripe charges from the platform", ex);
}
}
Stripe recently released a Search API which offers filtering by metadata for certain resources including charges. The documentation is at https://stripe.com/docs/search
I Want use telegram api bot . every thing is ok (in my idea) but i have stupid error that where ever is search i cant find any thing .
I am using Inline mode .
var awnser = new AnswerInlineQuery()
{
inline_query_id =model.inline_query.id,
results = new List<InlineQueryResultArticle>()
};
awnser.results.Add(new InlineQueryResultArticle() { id = Guid.NewGuid().ToString("N"), type = "article", url = "fidilio", input_message_content = new InputTextMessageContent() { message_text = "salam" }, title = "test" });
var send = SendInlineAwnser(awnser);
The send method is using restsharp
var ser = JsonConvert.SerializeObject(data);
var url = "https://api.telegram.org/bot" + telegramToken + "/answerInlineQuery";
var req = SimplePost<AnswerInlineQuery>(ser, url);
my serlization out put is this
{"inline_query_id":"302418856930797437","results":[{"type":"article","id":"fae56651b23244f8a3be94b1e6ebf6e7","title":"test","input_message_content":{"message_text":"salam"},"url":"fidilio"}]}
make sure that model.inline_query.id is correct and if so, keep in mind that you can send notify max 15 sec after inline keyboard pushed. Besides, I suggest using async method for sending inline query results.
I'm currently working on a POC MDS/MDM WCF service and have a question regarding validation. Does anyone have an example of calling the MDS web api to kick of validating the MDS model? I know i have to add a service reference to MDS in order to gain access to the proxies, i was just hoping for a simple example of using the api.
https://msdn.microsoft.com/en-us/library/microsoft.masterdataservices.serviceclient.validationprocess(v=sql.110).aspx
//ValidationProcess For an entity
public Collection<ValidationIssue> ValidationProcess(string ModelName, string verName, string EntityName, string memCode)
{
//Instantiate all of request and response objects
ValidationProcessRequest Request = new ValidationProcessRequest();
ValidationProcessResponse Response = new ValidationProcessResponse();
//Instantiate the Criteria and Options objects
Request.ValidationProcessCriteria = new ValidationProcessCriteria();
Request.ValidationProcessOptions = new ValidationProcessOptions();
//Set Model and Version Identifiers - these will be required in all instances
Request.ValidationProcessCriteria.ModelId = new Identifier { Name = ModelName };
Request.ValidationProcessCriteria.VersionId = new Identifier { Name = verName };
Request.ValidationProcessCriteria.EntityId = new Identifier { Name = EntityName };
Request.ValidationProcessCriteria.Members = new Collection<MemberIdentifier>();
Request.ValidationProcessCriteria.Members.Add(new MemberIdentifier { Code = memCode });
//Options can return validation results or trigger the commit of a version (when validation is already successful)
Request.ValidationProcessOptions.ReturnValidationResults = true;
Response = mds_Proxy.ValidationProcess(Request);
return Response.ValidationIssueList;
}
I use the PayPal Express Checkout SOAP service. For example here's a trimmed down version of the code to redirect the user to PayPal Sandbox when checking out:
var client = new PayPalAPIAAInterfaceClient();
var credentials = new CustomSecurityHeaderType() {
Credentials = new UserIdPasswordType() { ... }
};
var paymentDetails = new PaymentDetailsType() {
OrderTotal = new BasicAmountType() {
Value = string.Format("{0:0.00}", 100m)
}
};
var request = new SetExpressCheckoutReq() {
SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() {
SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType() {
PaymentDetails = new PaymentDetailsType[] { paymentDetails },
CancelURL = "http://www.mysite.com" + Url.Action("Cancelled", "PayPalCheckout"),
ReturnURL = "http://www.mysite.com" + Url.Action("Index", "PayPalCheckout")
},
Version = "60.0"
}
};
var response = client.SetExpressCheckout(ref credentials, request);
return Redirect(string.Format("{0}?cmd=_express-checkout&token={1}", "https://www.sandbox.paypal.com/cgi-bin/webscr", response.Token));
I then handle the data when the user is returned to the ReturnUrl. This was taken from some code I found on another website.
I now need to add a refund facility to my site. I was wondering if anyone else has done this? I've tried searching online but can't seem to find anything that helps. I also tried doing it myself but the API isn't very intuitive.
I'd appreciate the help. Thanks
It would just need to be a RefundTransaction API call that you would need to execute. Are you trying to have your return page issue a refund based on a condition, or are you trying to create a GUI type of interface to allow someone to issue a refund for a transaction? Have you looked at the code samples for this within the SDK's that PayPal offers? You should be able to use this code.