Unclear structure of authentification endpoint for changenotifications from graph api - c#

I try to subscribe for the User[id]/messages source at the developer programm exchange server.
How i have to structure my request against graph is totally clear. and works but how i have to process the authentication request of Graph is unclear. I know i have to aswer with a 200 OK but i also have to send the processed token back according to some Tutorials. But not a single tutorial shows a example authentication endpoint.
[HttpPost]
[Route("api/changeNotifications")]
public HttpResponseMessage ChangeNotificationEndpoint(HttpRequestMessage httpRequestMessage)
{
_logger.Debug("Anfrage von Graph an Vif erhalten");
return new HttpResponseMessage
{
StatusCode = System.Net.HttpStatusCode.OK,
Content = /* The unclear section */ ;
};
}
I have tried to to follow some tutorials but each tutorial lacks of an example endpoint.

Here is the sample for Notification endpoint validation:
For more information: https://learn.microsoft.com/en-us/graph/webhooks?tabs=http#notification-endpoint-validation
Hope this helps.

Related

How to view SOAP fault details from Bing Ads API failure

I have a request I'm making to the Bing Ads API that looks like this:
var _campaignManagementService = new ServiceClient<ICampaignManagementService>(
_authorizationData,
apiEnvironment
);
var getCampaignRequest = new GetCampaignsByIdsRequest
{
AccountId = <the-accountid-is-here>,
CampaignIds = new List<long>() { <the-campaignid-is-here> }
};
var getCampaignResponse = (await _campaignManagementService.CallAsync((s, r) => s.GetCampaignsByIdsAsync(r), getCampaignRequest));
When I run this, an exception is thrown on the last line that reports:
"Invalid client data. Check the SOAP fault details for more information."
Unfortunately, using the API, I'm not seeing the details of the actual response. Is there a way to get at this info? (Short of rewriting the whole thing without using the API?)
Edit:
Thanks to Panagiotis Kanavos I found the solution i think. This is for a different api (reporting) but it should look the same.
The exception has an InnerException that is of type System.ServiceModel.FaultException<Microsoft.BingAds.V13.Reporting.AdApiFaultDetail> or something similar. This has the Detail property with additional information:
Original post:
Can't seem to be able to easily inspect the SOAP request. But you can sniff the request with Fiddler classic The classic version is free.

C# API call from MarketStack and print values - Error 403

I would like to make a successful API call, then print the values in order to see if it works. My main goal is to analyze the data, after I can make a successful API call, and build a systematic strategy for trading.
System.Net.Http.HttpRequestException: "Response status code does not indicate success: 403 (Forbidden)
namespace marketstacktest
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var options = Options.Create(new MarketstackOptions() { ApiToken = "secretTokenHere" });
var marketstackService = new MarketstackService(options, NullLogger<MarketstackService>.Instance);
var appleSymbol = "AAPL";
var fromDate = DateTime.Now.AddDays(-200);
var toDate = DateTime.Now;
//error at the await System.Net.Http.HttpRequestException: "Response status code does not indicate success: 403 (Forbidden)."
List<Marketstack.Entities.Stocks.StockBar> stock = await marketstackService.GetStockEodBars(appleSymbol, fromDate, toDate);
foreach (var stock_i in stock)
{
Console.WriteLine($"close: {stock_i.Close}");
}
}
}
}
In the API manual, which is directly linked from the github, it gives information about all of the error codes. The relevant ones here are these two:
Code
Type
Description
403
https_access_restricted
HTTPS access is not supported on the current subscription plan.
403
function_access_restricted
The given API endpoint is not supported on the current subscription plan.
Their class library on github is just wrapping a json REST api. Every call to the API is just an http request, returning data as json objects. The 403 error indicates that your request was accepted as a valid request, but intentionally rejected by the server for some reason. And according to the docs, the error was because your account is not allowed access to either https or to the type of request.
Their free-tier subscription only includes end-of-day data, which is what you requested, so it wouldn't make sense for that not to be allowed. So, your app is almost certainly making an https call.
I went to the examples at the very beginning of their quick start guide, and chose the end-of-day example to match your app, and clicked on the link. It worked, and gave a bunch of json records. But, the request they made was using 'http' not 'https'.
Changing the requst to 'https' elicited a 403 response with this content (formatted for readability):
{
"error":
{
"code": "https_access_restricted",
"message": "Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."
}
}
At this point we have enough to be almost certain that this is your issue. The final thing is to go look up how to turn https requests off in their class library. To avoid having to go through the code, I checked the help at the bottom of the page one more time, and found this (formatted for readability):
var options = Options.Create(new MarketstackOptions(){
ApiToken = apiKey,
MaxRequestsPerSecond = 3,
Https = true
});
Welp. This should probably be in their first example, since that's what people are most likely to try first, but it's not. So, to stop trying to make http requests, you just need to set the Https option to false in your code. You just need to add that to the options in your code, like so:
var options = Options.Create(new MarketstackOptions(){
ApiToken = "secretTokenHere",
Https = false
});
I will leave the testing to you, but from the browser test, we know that the request should work, unless there's a bug in their library. Given the information that was available, this is almost certainly the issue.

How to Use application Insights REST API in Visual Studio MVC project

I want to retrieve all the data that is present in my resource on the azure portal. I have found out that there is a REST API for application insights that can help in retrieving the data. What I want is to get the data and generate a grid report on my web page which displays the events related information, that is, date, type, message and all the related information. I haven't worked with REST API's before and what I want as a help is a proper guideline to use this REST API in my MVC based web project in visual studio. If anyone can help will be a great assistance.
You can follow the steps below:
step 1: Get the Application ID and an API key.
Nav to your application insights -> API Access, see the screenshot(Please remember, when the api key is generated, write it down):
step 2: Understand the API Format, for details, refer to here:
Here is an example for get requests count in the last 6 hours:
https://api.applicationinsights.io/v1/apps/your-application-id/metrics/requests/count?timespan=PT6H
This part https://api.applicationinsights.io/v1/apps/ do not need to change.
Then input your-application-id which you get from last step.
Then you can specify metrics or events as per your demand.
This part requests/count, you can refer to this, screenshot below:
The last part ?timespan=PT6H, you can refer to this, screenshot below:
step 3: Write your code to call this api, like below:
public class Test
{
private const string URL_requests = "https://api.applicationinsights.io/v1/apps/your-application-id/metrics/requests/count?timespan=PT6H";
public string GetRequestsCount()
{
// in step 1, you get this api key
string apikey = "flk2bqn1ydur57p7pa74yc3aazhbzf52xbyxthef";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("x-api-key", apikey);
var req = string.Format(URL_requests);
HttpResponseMessage response = client.GetAsync(req).Result;
if (response.IsSuccessStatusCode)
{
// you can get the request count here
return response.Content.ReadAsStringAsync().Result;
}
else
{
return response.ReasonPhrase;
}
}
}

WCF Service - HTTP Request and Response

I have 2 WCF services:
1. Inbound - the client calls this service.
2. Outbound - we send information to client.
We now know that the response from client will be in default http response for outbound, and they want us to send a default http response for inbound.
Right now, I have specified the response object as a class. How do I implement http response?, how can I manage my services to send a http response?.
I have tried to search around but I am not getting any starter links for this.
Could you please guide me in the right direction?
What should my response object look like in this case?
I solved my issue with this:
To set the response object with the value:
WebOperationContext ctx = WebOperationContext.Current;
ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
To retrieve the value I used this:
int statuscode = HttpContext.Current.Response.StatusCode;
string description = HttpContext.Current.Response.StatusDescription;

Getting 404 Error during login using oAuth and RestSharp in C# for WP

I'm getting 404- Not Found error during google's authentication in windows phone 7.5 app.
public void login()
{
var cli = new RestClient("https://accounts.google.com/o/oauth2/auth");
cli.Authenticator = new HttpBasicAuthenticator(user, password);
var request = new RestRequest("token", Method.POST);
cli.ExecuteAsync(request, response =>
{
MessageBox.Show(response.Content);
});
}
I given valid login credential, but its shows the response as 404-NotFound. could please help me to resolve this issue
Thanks
For some reason the URI is probably not formed correctly.
If you check the documentation you'll notice an example URI which obviously works if you click on it. That means that the service exists and everything is OK with it. You are doing something wrong with RestSharp, and for that I recommend a detailed tutorial available on CodeProject called Google OAuth2 on Windows Phone

Categories