How to view SOAP fault details from Bing Ads API failure - c#

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.

Related

Unclear structure of authentification endpoint for changenotifications from graph api

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.

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.

Autodesk Forge Error trying to access the API online

I have a problem loading a 3D model on an online server, the error shown is related to accessing the Forge API, locally works smoothly however when mounted on the server or a website is made marks the following error "Failed to load resource: the server responded with a status of 404 (Not Found)", then "onDocumentLoadFailure() - errorCode:7".
As I comment, what I find stranger is that, locally, it works. Attached the segment of the code where it displays the error.
function getAccessToken() {
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", '/api/forge/toke', false); //Address not found
xmlHttp.send(null);
return xmlHttp.responseText;
}
Thank you very much in advance.
Are you sure the code you're running locally and the code you've deployed are really the same?
The getAccessToken function doesn't seem to be correct, for several reasons:
First of all, there seems to be a typo in the URL - shouldn't it be /api/forge/token instead of /api/forge/toke?
More importantly, the HTTP request is asynchronous, meaning that it cannot return the response immediately after calling xmlHttp.send(). You can find more details about the usage of XMLHttpRequest in https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest.
And finally, assuming that the function is passed to Autodesk.Viewing.Initializer options, it should return the token using a callback parameter passed to it (as shown in https://forge.autodesk.com/en/docs/viewer/v7/developers_guide/viewer_basics/initialization/#example).
With that, your getAccessToken should probably look more like this (using the more modern fetch and async/await):
async function getAccessToken(callback) {
const resp = await fetch('/api/forge/token');
const json = await resp.json();
callback(json.access_token, json.expires_in);
}
I've already found the issue. When I make the deploy I have to change the url where the request is made for the public or the name of the domain. For example: mywebsite.com/aplication-name/api/forge/token.

Microsoft Vision API in Xamarin exception

I was trying this tutorial in Xamarin:
Performing OCR for iOS, Android, and Windows with Microsoft Cognitive Services
But I get an: Exception of type 'Microsoft.ProjectOxford.Vision.ClientException' was thrown.'
It happens in the line:text = await client.RecognizeTextAsync(photoStream);
I have looked at other post (none Xamarin) and they solved by setting the position of the stream to 0. I tried it but still get the same error.
The tutorial was written by Pierce Boggan.
Thanks for any help.
OcrResults text;
var client = new VisionServiceClient("my api key");
using (var photoStream = photo.GetStream())
text = await client.RecognizeTextAsync(photoStream);
It happens in the line:text = await client.RecognizeTextAsync(photoStream); I have looked at other post (none Xamarin) and they solved by setting the position of the stream to 0. I tried it but still get the same error.
Different Areas have different Rest API Url, So in most cases, you need to set your apiRoot manually, which wasn't mentioned the tutorial, you posted. For detailed description, you can refer to Obtain Subscription Keyps.
To do that, you can obtain the API url in your subscription page:
And use the url to construct VisionServiceClient object:
OcrResults text;
var client=new VisionServiceClient("Your API Key", "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0");
using (var stream = photo.GetStream())
...

Error Calling DescribeIndexFieldsAsync on AmazonCloudSearchClient

I've confirmed that I have permissions to perform the request.
According to amazon's Cloud Search Dev Troubleshooting Guide the error I'm experiencing is likely due to the .net sdk using the wrong api version. I don't see a way to specify the api version explicitely.
I want to avoid having to manually create the http request.
I want to make the request through the SDK.
I've tried all the available versions of the SDK and all of them give me this error.
I've also tried specifying the request properties in various combinations. Nothing works.
Can anybody give me direction as to how I can resolve this issue?
Expected behavior: return info for all index fields
Actual behavior:
error -
"Result Message:
Amazon.Runtime.AmazonUnmarshallingException : Error unmarshalling response back from AWS. Response Body: {
"message": "Request forbidden by administrative rules",
"__type": "CloudSearchException"
}"
----> System.Xml.XmlException : Data at the root level is invalid. Line 1, position 1.
Code sample:
var _configClient = new AmazonCloudSearchClient(
WebConfigurationManager.AppSettings["CloudSearchAccessKey"],
WebConfigurationManager.AppSettings["CloudSearchSecretKey"],
new AmazonCloudSearchConfig
{
RegionEndpoint = RegionEndpoint.USWest2,
ServiceURL = WebConfigurationManager.AppSettings["CloudSearchUrl"]
});
await _configClient.DescribeIndexFieldsAsync(new DescribeIndexFieldsRequest())
CloudSearch is returning json, which you can see in your response body, and the SDK is trying to unmarshal that into xml. When you make a query directly, you can add &format=xml to get xml results. There should be an analogous option in the SDK.

Categories