c# - aws api gateway flush cache - c#

Is there any way to flush aws API gateway cache for the particular stage through c# code?
I have a requirement to synchronize my api with frequently changing data at the backend.
Once data updated in database my code should clear the api gateway cache so that user will see the updated result on the UI.
I found articles in aws which uses CLI commands to clear cache.
Below is the link for reference
Please help me to find the similar c# code for the same.

{
AmazonAPIGatewayClient amazonAPIGatewayClient = new
AmazonAPIGatewayClient(Amazon.RegionEndpoint.EUWest1);
FlushStageCacheRequest req = new FlushStageCacheRequest
{
RestApiId = "APIID",
StageName = "yourAPIstagename"
};
FlushStageCacheResponse response =
amazonAPIGatewayClient.FlushStageCacheAsync(req).Result;
}

Related

Modifying the SAS key for Service Endpoint from c# script CRM

I have Service Endpoint for D365 (CRM online) to connect with Azure Service Bus during registration I've specified SAS key from Service Bus Queue and everything works as expected.
Currently, I need to modify the SAS key for some environments but I would prefer to do it from c# script to avoid manual actions. During the investigation, I've found out service endpoint info in the entity "serviceendpoint" and SAS key should be in the "authvalue" field.
I'm trying to perform a regular update for this field but no lack. For some reason, it is impossible to perform a regular update for it.
Could anybody share ideas on how to update the SAS key from the c# script?
I know this comes a little late but I found myself in this exact situation and this is working for me:
// get the CRM endpoints
var query = new QueryExpression("serviceendpoint");
query.ColumnSet.AddColumns("name", "serviceendpointid", "saskeyname");
query.Criteria.AddCondition("name", ConditionOperator.EndsWith, busName);
var queryResult = client.RetrieveMultiple(query);
foreach (var entity in queryResult.Entities)
{
var updateEntity = new Entity(entity.LogicalName, entity.Id);
updateEntity["namespaceaddress"] = nameSpace;
updateEntity["saskeyname"] = sasName;
updateEntity["saskey"] = sasKey;
client.Update(updateEntity);
}
Partly working because I don't get an error and I can see the saskeyname attribute changing on the Plugin Registration Tool, but then the endpoint stops sending data. I then overrode it with the key on that same tool and it worked again, so from what I can see I can update the values but there's something special about that field I just couldn't find anything on the documentation.
Hope this helps someone, and if anyone knows what I'm missing please just let me know

How to update the record in an azure function triggered by a webhook?

I have an Azure function triggered post creation of a record in Dynamics 365 CE. The azure function and Dynamics 365 CE are integrated by a Webhook registered via the Plugin Registration.
What is the best way to update some data fields inside the record in RemoteExecutionContext .
Do I connect to Dynamics again or I can update as part of the Dynamics pipeline?
I have tried the .InputParameters["Target"].Id but upon updating with a new HttpClient I am getting a record not found error, whereas the webhook is in Post.
JObject Obj1 = new JObject();
Obj1.Add(STATE, 1);
Obj1.Add(STATUS, 123);
obj1.Add(ERROR_MESSAGE, "Update");
HttpRequestMessage updateApiRequest = new HttpRequestMessage(new HttpMethod("PATCH"), $"{d365Client.BaseAddress}new_customeentity1({targetEntity.Id.ToString()})");
updateApiRequest.Content = new StringContent(obj1.ToString(), Encoding.UTF8, "application/json");
HttpResponseMessage updateResposne = await d365Client.SendAsync(updateApiRequest );
What's the best way to achieve a similar integration?
How can I update the record within the pipeline without getting the Record Not Found error?
I would check two things for solving this particular "record not found" issue:
Try to register the step in "Asynchronous" mode if it's registered as "Synchronous" Read more
Verify the code sample & important points explained in this blog. Basically to avoid sandbox limitations and External Integration purpose only we go for Azure functions/webhooks
So, if you are not doing anything else other than this simple update back to CRM record, then complete the service.Update in post-create plugin itself.

Google Cloud API not returning any response

Background information:
I'm trying to create a PoC for Google Cloud Vision API using their .NET library.
What I have done:
Create a simple console apps with the following code for Vision API.
GoogleCredential credential = GoogleCredential.FromFile(ConfigurationManager.AppSettings["GoogleCredentialFile"]);
Grpc.Core.Channel channel = new Grpc.Core.Channel(Google.Cloud.Vision.V1.ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
var client = Google.Cloud.Vision.V1.ImageAnnotatorClient.Create(channel);
var image = Google.Cloud.Vision.V1.Image.FromFile(#"C:\Users\u065340\Documents\sample.jpg");
var response = client.DetectLabels(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
result = annotation.Description;
}
Problem:
The line client.DetectLabels(image) gets stuck for a long time before ultimately throwing the error Deadline Exceeded.
My code sits behind a corporate proxy, but I have validated that it is not blocking internet access because I can call https://vision.googleapis.com/$discovery/rest?version=v1 from the same apps and get its JSON response just fine.
Any suggestions?
After digging around through github issues related to proxies as suggested by Jon Skeet, I found that Google Cloud Client APIs can be generally divided into 2 categories (Ref: here): REST-based HTTP 1.1 with JSON and gRPC.
For APIs associated as REST-based, there should be no issue with proxies. The problem starts to appear when we are using gRPC-based APIs such as Google Cloud Vision and Google Speech. In gRPC, we need to explicitly provide our proxy server information.
For those using Java Client, it seems we still can't set proxy properly because it will eventually be ignored, and causing the Deadline Exceeded error. This issue is already well known and can be found at here and further traced into here.
The Google team has determined that it is indeed a bug, and the status remains Open.
As for C# Client, we can set proxy information using gRPC Environment Variables which is documented in here. The code is Environment.SetEnvironmentVariable("http_proxy", <your_proxy_server>);
After I set the http_proxy environment variable pointing to my proxy server, all is well again. I get the expected output "This API needs Billing Account".
Many thanks to Jon Skeet for pointing me in the right direction :D

Using Bing API: easiest way to connect with an API and get data from it

I've searched some time, looking for easy way to connect with some other sites WebAPI. There are some solutions, but they are made in very complicated way.
What I want to do:
Connect with server using URL adress
Provide login and password to get some data
Get data as JSON/XML
Save this data in an "easy-to-read" way. I mean: save it to C# variable which could be easy to modify.
Currently, API that I want to work with is Bing Search, but I'm looking for some universal way. I found an example, but it doesn't work for me and in my app I can't use this class: "DataServiceQuery" because it doesn't exsist.
How do you usually do it? Do you have your favourite solutions? Are there some universal ways or it depends on type of API that you work with?
I'm currently working on .NET MVC app (in case it could make any difference)
From server side
You can use that like below.
// Create an HttpClient instance
HttpClient client = new HttpClient();
// Send a request asynchronously continue when complete
client.GetAsync(_address).ContinueWith(
(requestTask) =>
{
// Get HTTP response from completed task.
HttpResponseMessage response = requestTask.Result;
// Check that response was successful or throw exception
response.EnsureSuccessStatusCode();
// Read response asynchronously as JsonValue
response.Content.ReadAsAsync<JsonArray>().ContinueWith(
(readTask) =>
{
var result = readTask.Result
//Do something with the result
});
});
You can see example on following link.
https://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee
For JavaScirpt:
You could use jQuery and WebAPI both together to do your stuff.
There are few steps to it.
Call web api with Ajax jquery call.
Get reponse in JSON
Write javascript code to manipulate that response and do your stuff.
This is the easiest way.
See following link for reference:
http://www.codeproject.com/Articles/424461/Implementing-Consuming-ASP-NET-WEB-API-from-JQuery
It entirely depends on the type of API you want to use. From a .Net point of view, there could be .Net 2 Web Services, WCF Services and Web API Services.
Web APIs today are following the REST standard and RMM. Some APIs need API Keys provided as url parameters, others require you to put in request's header. Even some more robust APIs, use authentication schemes such as OAuth 2. And some companies have devised their own standards and conventions.
So, the short answer is that there is no universal way. The long answer comes from documentation of each API and differs from one to another.

Express PayPal checkout, Could not create SSL/TLS secure channel

I'm trying set up paypal express checkout using SOAP 2.0 API in ASP.NET C# code. First I try to use sandbox, I created seller/buyer test accounts, imported web service and then I try to get token, in my C# code I have:
// Create the request object
SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();
// Create the request details object
pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction;
pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;
pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();
pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount;
pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;
SetExpressCheckoutResponseType response = (SetExpressCheckoutResponseType) caller.Call("SetExpressCheckout", pp_request);
but on the last line of that code it throws an error:
The request was aborted: Could not create SSL/TLS secure channel.
That I'm doing wrong?
Thanks.
Your code certainly seems correct but the PayPal API can be finicky when it comes to a few things. One thing to look out for is that it will generate exceptions when the payment amount is not rounded to 2 decimal places - can you try ensuring this is the case?
Also ensure that your configuration values are correct. Aside from that the code you have posted is exactly what I used to use for the SOAP API.
I stopped using the SOAP API a while ago in favour of the NVP API, which in my mind is a bit easier to deal with: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPIOverview
I made available a library to do all the work for you: https://github.com/davidduffett/Moolah
The instructions here show exactly how to use PayPal Express Checkout: https://github.com/davidduffett/Moolah#paypal-express-checkout

Categories