WSO2 APIM adding sequence for backend server of API - wso2

I am working on one scenario where I have add a sequence in the API using restAPI of APIM2.6.0 [https://docs.wso2.com/display/AM260/apidocs/publisher/#!/operations#MediationPolicyCollection#apisApiIdPoliciesMediationPost]
Once the mediation policy is added to the respective API, do we have to publish the API once again. As when I am doing it from publisher once the sequence is added to direction IN, then I am saving it to get it reflected to synapse.
So, I believe if I am adding the same from restAPI, then also I have to republish it again to get it reflected to synapse.
Please let me know if the understanding is correct.
Thanks

Yes, you need to republish the API again to reflect the changes applied. You can check the code when adding a mediation policy for the API in [1].
[1] - https://github.com/wso2/carbon-apimgt/blob/85d02e1864bf77bd53bd269445995ab8e8e9641f/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/impl/ApisApiServiceImpl.java#L796

Yes.
Normally, the once the API is published, all the changes will be auto deployed.
So, adding the mediation policies should also reflect without re-publishing the API.
Update
The answer above is for when using the UI. In REST API, we should republish the API.

Related

How to check the API synapse file in api manager 410

In previous api-manager version when we create an api, api synapse files were recorded in Users/bilal/test/api-manager/wso2am-2.6.0/repository/deployment/server/synapse-configs/default/api. But in 410 only default apis are there and my apis' synapse file is not there. But the api can be called without issue. Same thing for sequences.
I need to check and change the mediation that was applied. Always changing and uploading from the publisher is too much of work.
Adding to what pubudu has mentioned above. From APIM 3.2.0 onwards, we have introduced inbuilt artifact synchronizer and this will store the API artifacts such as synapse api definition, mediation sequences and endpoints to the database. It will then use events to distribute these artifact across gateways.
Previously, artifacts were saved to the file system and if you had multiple gateway nodes, file based synchronizers such as NFS, rsync had to be used to deploy these artifacts across gateway cluster.
Because of this new architecture, we removed the artifacts being saved to the file system and provided a gateway rest API, that you can use to view the deployed artifacts or redeploy artifacts in each gateway. If your requirement is to verify the deployed artifact, you can use this API.
And from APIM 4.1.0, we have changed the mediation policies feature to the new API policies framework.
If your requirement is to change the meditation sequence manually, you still can create a mediation sequence as you have created for APIM 2.6.0 and use the correct naming convention <API_NAME>:<VERSION>--<Direction> (eg: PizzaShackAPI:v1.0.0--In) and add it to the sequence directory. This will deploy the policy in the gateway and will be engaged when you invoke the API. However since we no longer keep artifacts in the file system, every restart will clear these directories and only keep the whitelisted files. That's where pubudu's above configurations are used for and you need to add your sequences' name to this configuration under sequences.
Please note that never to use these file based artifacts in your production deployment and only use them for testing progress. This is because whenever you add a policy from the publisher and deploy it in the gateway, this mediation policy will be undeployed and that file will deploy. At the server startup, this will create a inconsistent behaviour. so my recommendation is, you can use this apporach during the sequence development phase and once you have satisfied with it, use the correct apporach and add it as an API policy.
In the latest API Manager version, you can't find those files as those are not written into those files. Those data is kept in the memory.
You can add the following config to the deployment.toml to provide files from the file system.
[apim.sync_runtime_artifacts.gateway.skip_list]
apis = ["api1.xml","api2.xml"]
endpoints = ["endpoint1.xml"]
sequences = ["post_with_nobody.xml"]
local_entries = ["file.xml"]

JSON and XML threat protection in WSO2 API Manager is not working

When I was trying "JSON/XML Threat Protection for API Gateway" in WSO2 APIM 3.1.0, by adding a mediation policy. It isn't considering the custom policy that I've written, it's taking the default values which are 100.
Anything more I should be adding, please suggest!
Once a new mediation sequence is implemented, it needs to be upload and select as a mediation sequence in the "Message Mediation" section. Once selected need to republish to apply the changes.
You can confirm this by checking the generated sequences file in the <AM_HOME>/repository/deployment/server/synapse-configs/default/sequences. The file format will be <provider>--<API-Name>_v<Version>--<Direction>.xml

WSO2 API 2.2.0 - API runtime call redirection

How to redirect an API Call received by WSO2 API Manager to another API also running in the same server?
Maybe I do not understand well your problem.
Why not, simply, in the new API declare the endpoints pointing old one?
If you want a more performant solution, create a custom sequence in the new one, with a call to the old.
As #Sourcerer has mentioned you can add mediation extension using custom mediation sequences. Have a look at https://docs.wso2.com/display/AM220/Adding+Mediation+Extensions

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

How do I disable OAuth2 for a resource in WSO2's API Publisher?

I've created a simple API and I'm trying to publish it using WSO2's API Publisher (aka API Cloud). I've gone through all the steps, but it seems to require an Authorization header to access my endpoint. In older documentation, it says that I can change the "Auth Type" at the resource level.
https://docs.wso2.com/display/AM160/API+Resources
However, this option doesn't seem to be there in the current version. I tried to make it so the Authorization header was not required. Unfortunately, I still get the following error:
<ams:fault xmlns:ams="http://wso2.org/apimanager/security">
<ams:code>900902</ams:code>
<ams:message>Missing Credentials</ams:message>
<ams:description>Required OAuth credentials not provided</ams:description>
</ams:fault>
Is it possible to disable authentication for my API? I don't need it at this point in my project.
The document you have referred is from APIM 1.6. From APIM 1.7, the APIM team changed the API creation process to a 3-step process. It involves API Design, Implement and Manage. I think you have experienced this by now. In the Manage section, at the very bottom, it lists down the available resources of the API, their auth type, allowed tier and the scope allowed.
Default auth type is application & application user. If you click on that, you will get a drop down where you will see "None" as an option. If you set the auth type as none, you will be able to invoke the API without providing the OAuth token.
See the following screenshot where I have selected different Auth types when creating an API.
Open the configuration related to your API in ${AM_HOME}/repository/deployment/server/synapse-configs/default/api/ and remove the following part.
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>