How can I pass tenant value in the URL via Integration Studio? - wso2

I have a multi tenant API and I am trying to RESTIFY it using wso2. I am trying a way to pass the tenant value in the url.
localhost:8290//tenant/api/...
https://tenant.xyz.com/api/...
I tried İntegration studio and i managed to pass a literal tenant value in http endpoint by creating a property named {uri.var.tenant} and setting it to tenant name. However, I don't know how can I take the tenant name from here
localhost:8290//tenant/api
and pass it here.
https://tenant.xyz.com/api/
I also tried using the APIM publisher page with no success.

As I see, there are 2 parts for your question.
How to parameterize the backend URL.
How to read the path parameter from the fronting API that is being called.
For the first one, the method you have followed is correct and an example can be found at https://apim.docs.wso2.com/en/latest/integrate/examples/endpoint_examples/using-http-endpoints/#example-1-populating-an-http-endpoint-during-mediation . What's remaining is to read the path parameter and to populating {uri.var.tenant} which is the second point.
For the second point, you can create and API definition with the URL templated. See the property URI Template at https://apim.docs.wso2.com/en/latest/reference/synapse-properties/rest-api-properties/ you can find an example of the usage at https://apim.docs.wso2.com/en/latest/integrate/examples/rest_api_examples/setting-query-params-outgoing-messages/#reading-a-query-or-path-parameter

Related

GCP: Resource Name vs URL : Inconsistent matching

For a Resource Name find the appropriate HTTP Rest URL for it.
With the help of the below Google Doc, for some resources name to URL mapping is working fine
Doc:
https://cloud.google.com/apis/design/resource_names#resource_name_vs_url
Example:
Name Format:
//cloudresourcemanager.googleapis.com/organizations/ORGANIZATION_NUMBER
URL:
https://cloudresourcemanager.googleapis.com/v1/organizations/ORGANIZATION_NUMBER
Basically adding HTTPS scheme before the name and the API major version before the resource path this works fine.
But the problem is this conversion scheme is not consistent for some resources if we form URL with this approach it will differ from the actual URL
Example:
Name Format: //compute.googleapis.com/projects/PROJECT_ID/
Formed URL: https://compute.googleapis.com/v1/projects/PROJECT_ID/
URL in Google Doc: https://compute.googleapis.com/**compute**/v1/projects
Compute Engine API Reference: https://cloud.google.com/compute/docs/reference/rest/v1
Other resources apart from compute also have actually different URL from the generated one using the above method.
Queries are:
Apart from the mentioned way is there any way to map resource names to URL
What are the best practices in such conversion
Apart from manually mapping each name to URL is there any generic way
Is there any API which provides this mapping, Like pass, a resource name and URL for it will be returned(On the internet I didn't found one)
Google APIs have a discovery document.
In that JSON file, there are 2 fields revelant for this question: rootUrl and servicePath.
To construct a proper URL for the API, concatenate both values.
More details in the discovery service docs.

API Gateway Custom Domain - having both empty base path mapping to stages and a static html page on the empty base path

I have an AWS API Gateway set up with a custom domain name one the format api.example.com. I have a api.example.com/prod stage and a api.example.com/dev stage, but I would also like to be able to modify the response returned on api.example.com.
What I want is very similar to how the GitHub api behaves. Where https://api.github.com/v2 access version 2 of the api, and https://api.github.com/v3 access version 3, but https://api.github.com gives a custom response.
In my case I would like to have a small static html page on api.example.com, but a custom json response (like on api.github.com) is fine, anything more helpful than {"message":"Forbidden"} would do.
I know I set up base path mappings to the dev and prod stages in the custom domain window (as my partially redacted settings below), but I would like to add a empty path as well, and have that point to another API with just a GET method on the root resource that returns a small static html page. API Gateway does not allow combining an empty base path mapping with non-empty base path mappings (for a good reason I assume), but it feel there should be some way to achieve what I am trying to set up.
Anyone who knows a way to achieve this using AWS API Gateway?

How to create URL with path parameters inside API Gateway

I want to create a path as follows in the API Gateway:-
/users/{userId}/photos/{photoId}.
A clever guy may say why can't you go for /users/photos/{userId}/{photoId}. Well I can't club many path parameters under the same URL.
How can I create a precise URL path with API Gateway.
Refer to the section with the following heading in this link.
Integration 3: Create a GET Method with Path Parameters to Call the Lambda Function

Add Web Root Context to return calls in WSO2 IS 5.7.0

I need to add a WebRootContext to all the calls in the WSO2 Identity Server's Implicit Flow so that I can make calls through an API Gateway. I have managed to do this for all the calls I need by changing the
<WebContextRoot>/wso2-is<WebContextRoot>
property as well as changing the name of my webapp folders: wso2-is#authenticationendpoint and wso2-is#oauth2 endpoints. I can now successfully call http://localhost:9443/wso2-is/oauth2/authorize.
I also changed the endpoints in repository/conf/identity/identity.xml to include the wso2-is root context, specifically the OAuth2AuthzEPUrl, so that in the management console this shows up under identity:
However, after I login, the application calls http://localhost:9443/wso2-is/commonauth which has a return location of http://localhost:9443/oauth2/authorize?sessionDataKey=... and I can't figure out how to add my context root to the returning call. Where does the commonauth endpoint get the location it returns to? I'm assuming there is some property I need to set to make that happen, but I can't find it.
I also tried re-seeding the database with all my changes and this did not solve my issue either.
I looked in the source code here in github and couldn't find any references to commonauth or oauth2/authorize that stood out as to where this call is being formed. Any additional details would be greatly appreciated.
As per the official documentation, using a reverse proxy is the recommended way to add a custom context path to wso2 products.
However, as I wrote in another question, I could complete the implicit flow with local auth successfully with the mentioned configs in my answer.
I guess, what you are missing here is ProxyContextPath.

Unable to send POST request to DialogFlow (404)

I am working on upgrading a 3 year old api.ai app to DialogFlow. I have modified the request using the Migration Guide. I get a 404 error using the base url:
https://dialogflow.googleapis.com/v2/{session=projects/Project_ID/agent/sessions/1}:detectIntent
This is from the detectIntent documentation. I am trying to use the detectIntent method, but I was having the same problem when I tried to use context. Additionally, I have tried on multiple networks. I even get a 404 when I put it in a browser. Any idea what is incorrect in my URL?
As noted at the documentation for detectIntent, the URL uses Google API HTTP notation to document parameters and how they need to be specified. That second link isn't very useful, but basically it means that you can interpret the URL
https://dialogflow.googleapis.com/v2beta1/{session=projects/*/agent/sessions/*}:detectIntent
as
The parts outside the {} are literal. That is exactly what you should be sending in the URL.
The {} is not literal. It specifies a parameter.
The part inside the {} is a parameter named "session".
The "session" parameter takes the form of a string that has two portions that can be a single path segment (the description of detectIntent puts additional limitations on these portions, but sometimes this is specified in the notation) and the rest is a literal path.
So if the session is projects/12345/agent/sessions/6789 then the URL will be
https://dialogflow.googleapis.com/v2beta1/projects/12345/agent/sessions/6789:detectIntent