How to replace url path parameter - azure-api-management

How to replace value of tenantId in the following url: /{tenantId}/users? I need to replace it with a value from jwt token. It's trivial for query param, but path params are not documented anywhere.

If I'm getting you right, you want to rewrite the uri in the inbound section?
If your url is:
https://stackoverflow.com/{tenantId}/users
Then you can rewrite the Uri with following command:
<rewrite-uri template="#(context.Request.OriginalUrl.Path.Replace(context.Request.MatchedParameters["tenantId"], "<YOUR-JWT-TOKEN-VALUE>"))" copy-unmatched-params="true" />

Related

Query on JSON response returns, Parse exception Unexpected end of input

Good day,
Hope you are well.
I am trying to use the Vincere API, and trying to query the response to only return where private_job:0. I am using Postman to test the API.
When I use the below request, doing my best to follow the instructions on the Documentation:
https://domain.vincere.io/api/v2/job/search/fl=job_title,private_job;sort=published_date asc?q=private_job:0
I get the following response:
"Parse exception Unexpected end of input, expected term_char, ws0, term or term_end (line 1, pos 14):\nprivate_job:0\n ^\n"
If I remove ?q=private_job:0, I get a valid response.
I am clearly doing something wrong. Please assist.
in query parameter the key name is q ,
q=private_job:0
but in documentation it says instead of q it should be fq
https://domain.vincere.io/api/v2/job/search/fl=job_title,private_job;sort=published_date asc?fq=private_job:0
Also if you are using special character q=private_job:0 # , then give the value in the query parameter session of postman it will url encode it automatically for you
This stumped me as well, turns out my issue was twofold.
Firstly, this error refers to their URL parser expecting to see the end character %23, so your query string needs to end with that.
Secondly, I was attempting to query the job_type and using the actual string value ie. job_type:PERMANENT%23. This actually needs to be the enum value (1 in this case).

Azure API managment Policy check contain for URL

I am trying to set variable if url contains text "verification"
<set-variable name="pathQuery" value="#(context.Request.Url.Contains("verification"))" />
I get the following error
Error in element 'set-variable' on line 16, column 10: 'IUrl' does not
contain a definition for 'Contains' and the best extension method
overload 'Queryable.Contains(IQueryable, string)'
requires a receiver of type 'IQueryable'
How do I set this?
You could use the code as below:
<set-variable name="pathQuery" value="#(context.Request.Url.Path.Contains("verification"))" />
For more details, you could refer to this article.

Node.js: How to read parameters from an axios get request?

So I have an axios request along the lines of this in my ReactJS project:
axios.get(URL, {params: {id: id}}
This would pretty much pass a get request to my backend with an URL like so:
URL?id=id
I also have a Node.js Lambda function that runs a mysql query like so:
connection.query("SELECT * FROM database.USER WHERE ID = '"+event.id+"'", function (error, results, fields))
So I know this does not work because I'm passing in a params through a URL, which does not work with event
I am trying to make my Node.js function read the id from my URL params, but I do not seem to know the syntax to do that.
Does anyone know how to get the params from a Node.js function? I've tried stuff like params.id, #id, :id, params[0].id, but none of them seem to work.
First of all you are exposing your backend to SQL Injection. You should NEVER concatenate your sql queries with values from the outside that you don't control. Please read about SQL injection: https://www.w3schools.com/sql/sql_injection.asp
You must use mysql2 library and prepared statements SEE: (https://github.com/sidorares/node-mysql2/blob/master/documentation/Prepared-Statements.md)
Since you are using AWS lambda you read values from the query using:
const id = event.queryStringParameters ? event.queryStringParameters.id : null;

Get request with query string in express

I want to be able to complete a get request on a local host port. The full url should be "localhost:3000/data/mydb.json?get=somefield" where mydb.json can be any filename and somefield is a key. In my app.js file my get request looks like this:
app.get('/data/:filename?get=somefield', routes.getdatabase);
regardless of what i put in the routes file it is unable to complete a get request on any sort of url matching this pattern. To debug i removed everything after the question mark (e.g. app.get('/data/:filename, routes.getdatabase);) and any filename works. Is there some module i need to require in order to use this query string syntax or is there anything else wrong with this get request?
Query strings are not a part of the route path.
Given your second example:
app.get('/data/:filename', routes.getdatabase);
You should be able to use req.query.get for your query param.
routes.js
exports.getdatabase = function(req, res, next) {
console.log(req.params.filename);
console.log(req.query.get);
// Do some stuff
return res.send(someResponse);
}
Console (URI: /data/someFile?get=cats):
someFile
cats

Removing URL encoding from Active Record query

I'm in over my head as always, but it's the only way I learn. Right now I am trying to query a column in a database for the current user and return the values. I'm using something like:
#tags = current_user.tags.select(:name).each { |p| p.name}
But it returns:
%5B%23%3CTag+name%3A+%22tag1%22%3E%2C+%23%3CTag+name%3A+%22tag2%22%3E%2C+%23%3CTag+name%3A+%22tag+test%22%3E%5D
From what I understand is that's Url Encoding. Is it possible to clean that up? I've tried using .delete or .gsub but I must be doing something wrong. Any insight? All my research on the site yields how to URL encode, but not URL decode.
For URI encoding/decoding you can take a look at rubyonrails.org:URI::Escape
For displaying HTML in Rails views check out the raw() method rubyonrails.org:ActionView::Helpers::OutputSafetyHelper