how to add additional parameters in WSO2 API call - wso2

I am using WSO2 API manager 1.7. What I want is that when WSO2 API manager gets a REST API call then I want to pass 2 additional parameters to Endpoint gateway API. So e.g. API manager get 3 params then I want to pass 2 more static params to endpoint URL.
how can I achieve that, please help.
Thanks
Parvendra

You can append a sequence to the exposed API and add these parameters in a header. You can add a sequence to the API Manager by following the doc below[1]. Similarly u can add the required header using a header mediator as shown in [2]
[1] https://docs.wso2.com/display/AM170/Adding+Mediation+Extensions
[2] https://docs.wso2.com/display/ESB481/Header+Mediator

Related

wso2 api manager, optional authentication (v1.9)

I'm working with an older (v1.9) version of wso2 and we are trying to basically have an endpoint with optional authentication on it. If the security on the resource is set to None, if a request comes in with a token (authenticated) it does not get sent to the backend. Is there some way to force wso2 v1.9 to do the authentication on such a route and forward the JWT to the backend if there is an Authorization header set?
In API Manager v1.9, by default it removes the Auth header from the message context and it won't pass to the backend service [1].
There is a property called RemoveOAuthHeadersFromOutMessage where you can disable removing this header [2].
But this is a system-wide config and it affects all the APIs in the system. If you set this value to false, for all the APIs it does not drop the Auth header. In that case, you can use a global sequence or custom sequence [3] to drop this auth header selectively.
Another workaround:
You can use a custom handler [4] and apply this handler before the API security handler. In this handler, you can copy the auth header value to a different header and then using a custom sequence you can copy the custom header value to auth header again. In this case you don't need to change the value for RemoveOAuthHeadersFromOutMessage. But in the handler, you have to perform this operation selectively.
[1] - https://github.com/wso2/carbon-apimgt/blob/1.2.5/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/oauth/OAuthAuthenticator.java#L96
[2] - https://docs.wso2.com/display/AM191/Working+with+Access+Tokens
[3] - https://docs.wso2.com/display/AM191/Adding+Mediation+Extensions
[4] - https://docs.wso2.com/display/AM191/Writing+Custom+Handlers

WSO2 APIM : Get API Rating and Business Information through Store REST API

I have a custom page where I obtain Published API list using WSO2 Store Restful API
https://docs.wso2.com/display/AM220/apidocs/store/#!/operations#APICollection#apisGet
The problem is the returned result does not includes API Rating and Business Information whereas the Jaggery API that has been used by the default API Manager UI does include it. Is there any way to configure it so the REST API returns that data?
If I use the jaggery API instead, it is cookie based while I am using OAuth2 OIDC Service Provider of the IS. I cant obtain API that has visibility to only its own domain by passing access token to the Authorization header.
APIM Version: 2.2
Please Advice. Thanks!
There is no such a way which will change the output response of defined APIs.
If you want to do that, get source code of wso2 from github & edit the APIs & use the edited source to deploy your application. (But this will add lots of maintenance issue)
The quickest way is to call the get details of api.
It will return the business information object as well as below:
"businessInformation": {
"technicalOwner": "John Doe",
"technicalOwnerEmail": "architecture#pizzashack.com",
"businessOwner": "Jane Roe",
"businessOwnerEmail": "marketing#pizzashack.com"
},
Here you will get the heavy response as it returns the complete swagger definition as well.

WSO2: How to use the response of one api as a input parameter to another separate API

Can some one please let me know or guide me to achieve this:
I am calling one login API which returns authorization ticket. I need to capture the ticket information from the response message of first API and use it to invoke another API.
First and Second API are separate ones. First API is for login and second API is for creation of entity.
I have read through many posts and blogs but not able to proceed further and I am fairly new in WSO2. Can some one please guide me.
Thanks
You can simply achieve this by using a proxy service, mediation sequences and mediators. You will need 2 sequences which perform,
Log in, read the response and extract the token which then set to a property mediator. So that the second sequence can retrieve it.
Read the token which was set from the sequence1 and invoke the next API.
Then you can create a single proxy service in ESB, which invokes sequence 1 and 2.
Please go through the documentation[1] on Message Mediation for more detailed information on how to use different mediators.
[1] https://docs.wso2.com/display/ESB490/Mediating+Messages

providing dummy apis in wso2 api manager

Is there a way I can create some dummy APIs with dummy response in WSO2 API Manager? Our API implementation is not yet ready.Till its ready , can we create an API and give some sample json as response?
Best thing would be using the API manager to create API using prototype option.
Create API
Add entries for design screen
On the implementation screen choose - Prototyped API
Choose Implementation Method as inline for JSON (it will not work for
SOAP)
in Resource section click on any of the method types lets say Get
add the java script to mock the json data
/* mc.setProperty('CONTENT_TYPE', 'application/json');
enter code heremc.setPayloadJSON('{ "data" : "sample JSON"}');/
/ Uncomment the above comment block to send a sample response.*/
Publish it.
Hope this helps
Yes, you can create prototype API. please let me know if this help.
Refer following document Deploy and Test as a Prototype
If your servers has internet access, you can use http://www.mocky.io/ to mock your response. When you are creating an API in WSO2 API Manager provide the url of the mocky.io as the endpoint.

How to have multiple endpoints for one API in WSO2 API Manager?

Can I add multiple endpoints to 1 API in WSO2 Api Manager?
As far as I know I have to create a context and a version. The background is that I just want to make a request like https://api.manager.com/rest/1.0/userList or https://api.manager.com/rest/1.0/tasks.
The userList REST-Controller is implemented on backend A and tasks REST-Controller is implemented in backend B. (A and B are separate web applications)
As far as I know I have to create in my API Manager two APIs with different context values.
The API Manager application would simply subscribe both APIs.
But this would mean that I have to change my requests on the javascript side. This is in my opinion not good because I dont want my javascript application to care about the context. I want that the API Manager delegates to the correct backend automatically. Is this possible? What is best practise?
You can have multiple endpoints per API using Dynamic Endpoint Feature. When creating the API you need to set the Endpoint Type as "Dynamic Endpoint" and upload a mediation in-sequence that sets the "To" header. Within the sequence you can specify your logic to route to the correct endpoint (setting the correct "To" header) according to the request path. Please read [1] for more information.
[1] http://blog.lakmali.com/2016/08/dynamic-endpoints-in-wso2-api-manager.html