How to display correlationId, request payload and response body when certain api was in wso2 apim log - wso2-api-manager

I am trying to write custom api log handler for wso2 apim (4.0.0) so that it should add correlationId, request payload and response body when certain api is called. I followed the answer to similar question. So far I have done following:
public boolean handleRequestOutFlow(..) {
...
String uuIdHeader = (String) messageContext.getProperty("CORRELATION_ID_HEADER");
if (tenantDomain == null) {
tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
...
}
But uuIdHeader keeps returning null.
Any hint is appreciated on how to get correlationId, request payload and response body.

The correlation ID is generated when Observability logs are enabled in the API Manager server.
Therefore, to get the correlation-id printed in your logs, you have to enable the observability logs as instructed in here. You can get more insights about the observability logs and correlation IDs in the official Docs.

Related

Handle POST request with Firebase function

I am using fulcrum to collect data. fulcrum has a webhook feature
I have created a firebase function and linked the firebase function to fulcrums webhook feature with the functions URL. https://us-central1-example.cloudfunctions.net/fulcrumHook
Here is my existing function.
exports.fulcrumHook = functions.https.onRequest((request, response) => {
console.log(response.data.form_id)
response.send(200)
})
Through hours of debugging, in the logs I can see that the data I want is coming through but I am struggling to access it in the function itself.
When I log the request I get IncomingMessage { _readableState: ReadableState { objectMode: false,.....
When I log the response I get ServerResponse { domain: null, _events: [Object: null prototype] { finish: [ [.... as well as the body much further down with the actual data i need in it.
I have search for all the keywords i can think of about how to handle this data but I am completely stumped.
Do I need to handle the response like a promise with response.then(data => ...stuff)
Do I need to establish a connection like a socket with response.on('data', (data) => ...stuff)
Everything you need is in the documentation for HTTP triggers.
The request and response are essentially Express Request and Response objects.
Used as arguments for onRequest(), the Request object gives you access to the properties of the HTTP request sent by the client, and the Response object gives you a way to send a response back to the client.
You can click through to those linked APIs to understand in detail how they work.
Data passed to the function can be found by reading values from the request. If it's a POST request, form values are read like this:
request.body.form_id
The response is sent using response.send(). Just pass it an object that will get automatically serialized as JSON. Or use the linked API for the response object from above to learn more about your options.

Got These credentials do not authorize access from nokia here api getlinkinfo

I'm performing the following call:
http://route.st.nlp.nokia.com/routing/7.2/getlinkinfo.json?app_id=APP_ID&waypoint=LATITUDE%2CLONGITUDE&app_code=APP_CODE
it always worked until yesterday, when I started getting http 403 error with the following json error message:
{
"response":{
"_type":"ns2:RoutingServiceErrorType",
"type":"SystemError",
"subtype":"SystemError",
"details":"These credentials do not authorize access. Please contact your customer representative or submit a request here https://developer.here.com/contact-us to upgrade your account. You can also get valid credentials by registering for a free trial license on https://developer.here.com.",
"metaInfo":{
"timestamp":"2017-11-08T10:48:02Z",
"mapVersion":"8.30.76.154",
"moduleVersion":"7.2.201744-2851",
"interfaceVersion":"2.6.34"
}
}
}
I checked my account but it's a Public Basic Plan one so there is no expiration or restriction on the api I'm calling.
Domains with nokia.com aren't supported anymore. You need to change the domain name to the actual one.
Try to use https://route.api.here.com/

Not found exception when executing request in service account

I get the following error when retrieving the events of my calendar using service account.
Can anyone tell me what I'm doing wrong.
Google.Apis.Requests.RequestError Not Found [404]Errors [Message[Not Found] Location[ - ] Reason[notFound] Domain[global]]
//file path
string GoogleOAuth2CertificatePath = Server.MapPath("GoogleStore\My Project-a725fb0190fc.p12");
// #developer... e-mail address.
string GoogleOAuth2EmailAddress = "939544675132-compute#developer.gserviceaccount.com";
// certificate password ("notasecret").
string GoogleOAuth2PrivateKey = "notasecret";
X509Certificate2 certificate = new X509Certificate2(GoogleOAuth2CertificatePath, GoogleOAuth2PrivateKey, X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(GoogleOAuth2EmailAddress)
{
Scopes = new[] { CalendarService.Scope.Calendar }
}.FromCertificate(certificate));
// Create the service.
service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName
});
ListRequest request = service.Events.List(calID);
request.ShowDeleted = false;
request.SingleEvents = true;
events = request.Execute();
Thank you for any answer what can help me.
Usually when encountering 404: Not found the specified resource was not found. This can happen in several cases.
when the requested resource has never existed.
when accessing a calendar that the user can not access.
Based on the Official Google Documentation, the suggested action is to implement exponential backoff.
Exponential backoff is a standard error handling strategy for network applications in which the client periodically retries a failed request over an increasing amount of time. If a high volume of requests or heavy network traffic causes the server to return errors, exponential backoff may be a good strategy for handling those errors. Conversely, it is not a relevant strategy for dealing with errors unrelated to rate-limiting, network volume or response times, such as invalid authorization credentials or file not found errors.
Used properly, exponential backoff increases the efficiency of bandwidth usage, reduces the number of requests required to get a successful response, and maximizes the throughput of requests in concurrent environments.
Take note that in every request, your application sends to the Google Calendar API must include an authorization token. The token also identifies your application to Google.
Here's a related SO ticket encountered 404 not found error: Error 404 when creating a calendar with Google Calendar Api v3 using c# .net

Handling authentification to Firebase Database with Fetch in a Service Worker

I'm trying to query a Firebase database from a Service Worker using the Fetch API. However it doesn't work as expected as I can't get authenticated correctly.
Basically what I'm trying to do is from origin https://myproject.firebaseapp.com inside a Service Worker I do a call like this :
var fetchOptions = {};
fetchOptions.credentials = 'include';
var url = options.messageUrl;
var request = new Request('https://myproject.firebaseio.com/user/foobar.json', fetchOptions);
messagePromise = fetch(request).then(function(response) {
return response.json();
});
I'm getting this error :
Fetch API cannot load https://myproject.firebaseio.com/user/foobar.json. Response to preflight request doesn't pass access control check: Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'https://myproject.firebaseapp.com' is therefore not allowed access.
Any idea of a way to fix it? How one should do to query/update the Firebase database from a SW?
I've read https://jakearchibald.com/2014/using-serviceworker-today/ and one of the gotcha was exactly that problem, the fact that Fetch request do not send authentification.
Ideally it would be great to be able to use the Firebase JS API inside a SW but this doesn't seem to work as well.
Firebase doesn't store authentication info as a cookie or in anything that would be sent along in the credentials, so there's no need to send them in your fetch request. Instead, you'll need to pull the token from Firebase Auth:
firebase.auth().currentUser.getToken(true).then(function(token) {
// token is the value you'll need to remember for later
});
Once you've got the token, you should be able to add it as a query parameter to the REST request e.g. ?auth={THE_TOKEN}. This will allow you to make your authenticated request in the Service Worker.

workfront : blank response on attempt to create API key

When I attempt to derive an APIkey from a user account in Workfront using the methods detailed in https://developers.workfront.com/api-docs/#API_key I only get a blank response. Whilst most users in this domain auth using SAML the user in question has been set up as a API account and SAML is disabled.
The URL used is:
/attask/api-internal/user?action=getApiKey&username=yyyyy#xxxxx&password=xxxxxxxx&method=put (xxx and yyy masking actual text)
... and I receive the following result. I get the same result in both prod and sandbox
{
data: {
result: ""
}
}
If I use an invalid user/password pair I receive the following result:
{
error: {
class: "com.attask.common.AuthenticationException",
message: "That username/password combination wasn't quite right.
Make sure your caps lock isn't on and try again."
}
}
If use the user/password method to auth (https://developers.workfront.com/api-docs/#Authentication) this works and I receive the full session information.
If you are getting a blank response then you do not have a API key to get. You can either generate on in the UI by opening setup > system > customer info or through the API
/attask/api/v5.0/user?action=generateApiKey&username=yyyyy#xxxxx&password=xxxxxxxx&method=put

Resources