I would like to send array of id's via postman
https://stackoverflow.com/questions/12756688/is-it-possible-to-send-an-array-with-the-postman-chrome-extension
I looked on to above thread, for me array[] /array[0] didn't work out,
using same key with different value worked for me.
It gave
But I am not able to send single element in array or an empty array.
I see it in req.body as a string of characters
So how should I send it?
So I just needed to set extended option of urlencoded to true and use arr[0] in postman, and it worked for me.
just make express.urlencoded({extended : true});
it was set to false before and arr[] or arr[0] didnot worked.
Related
I am using mockoon for API simulation. I created 2 routes there with method GET and its body contains(responds with) JSON object. I noticed that my express app is not able to parse one of the routes. But the route that has JSON object in body which contains ARRAY is getting parsed. I tested both routes with Express(by console.log) and in chrome browser(I have JSON formatter extension) and it is behaving the same meaning response that does not contain ARRAY is not getting parsed but the response with array is getting parsed(behaving normally). Let me show the screenshots:
Express(by console.log):
With array:
Without array:
Chrome(JSON Formatter extension):
With array(extension is able to parse):
Without array(extension is not able to parse):
I tried adding Header(Content-Type: application/json) to the route in mockoon. But still, I am not aware of what is going on here. Someone please explain
The express code:
const iabs_client = await axios.get(
"http://localhost:3001/iabs-client
);
Here is the route created in Mockoon(without array inside JSON):
P.S mockoon is a program that creates endpoints in localhost, useful for API simulation when developing front-end without having backend yet
The trailing comma after "something" is not valid JSON. Edit your Mockoon body to remove the comma and it should work.
I have a response from a webservice like this:
[{"record_id":"63","date":"2021-04-12","acept":"1","name":"John","document":"1","passport":"","phone":"999999999","sign":"[document]","activity":"2"}]
There is a var called response that stores that response.
How do I get the "name" and the "phone" from this?
I tried to do JSON.stringify(response) in order to get somehow the info but I don't know what to do next.
Is the response a JSON or just a String??
Should I do JSON.stringify or JSON.parse to be able to work with this?
Thanks a lot
To check to see whether this is a JSON object or string, run console.log(typeof response). If it logs object, then this is already a JSON object! You don't have to do anything, and can get attributes out of it like any other object. (For instance, to get the name attribute, you can run response[0]["name"].) If it logs string, then you'll have to run JSON.parse(response) and save that to a variable to parse the string and turn it into an object.
After parse the response, you can access to name and phone like this:
response[0]["name"]
response[0]["phone"]
So I'm editing code right now, and I'm making a system that reads an array in a JSON file, and determines what to do if a user's id is in the array.
So, I put const idarray = require('./config.json').idarray
if (idarray.includes("1234")) return console.log(idarray);
So, it should return the contents of the array, right? Well no, it doesn't. It returns 'undefined', and crashes. Could I get some help? I've used this multiple times before, and it hasn't errored once...
I'm trying to make a request with Content-Type x-www-form-urlencoded that works perfectly in postman but does not work in Azure Logic App I receive a Bad Request response for missing parameters, like I'd not send enything.
I'm using the Http action.
The body value is param1=value1¶m2=value2, but I tried other formats.
HTTP Method: POST
URI : https://xxx/oauth2/token
In Headers section, add the below content-type:
Content-Type: application/x-www-form-urlencoded
And in the Body, add:
grant_type=xxx&client_id=xxx&resource=xxx&client_secret=xxx
Try out the below solution . Its working for me .
concat(
'grant_type=',encodeUriComponent('authorization_code'),
'&client_id=',encodeUriComponent('xxx'),
'&client_secret=',encodeUriComponent('xxx'),
'&redirect_uri=',encodeUriComponent('xxx'),
'&scope=',encodeUriComponent('xxx'),
'&code=',encodeUriComponent(triggerOutputs()['relativePathParameters']['code'])).
Here code is dynamic parameter coming from the previous flow's query parameter.
NOTE : **Do not forget to specify in header as Content-Type ->>>> application/x-www-form-urlencoded**
Answering this one, as I needed to make a call like this myself, today.
As Assaf mentions above, the request indeed has to be urlEncoded and a lot of times you want to compose the actual message payload.
Also, make sure to add the Content-Type header in the HTTP action with value application/x-www-form-urlencoded
therefore, you can use the following code to combine variables that get urlEncoded:
concat('token=', **encodeUriComponent**(body('ApplicationToken')?['value']),'&user=', **encodeUriComponent**(body('UserToken')?['value']),'&title=Stock+Order+Status+Changed&message=to+do')
When using the concat function (in composing), the curly braces are not needed.
First of all the body needs to be:
{ param1=value1¶m2=value2 }
(i.e. surround with {})
That said, value1 and value2 should be url encoded. If they are a simple string (e..g a_b) then this would be find as is but if it is for exmaple https://a.b it should be converted to https%3A%2F%2Fa.b
The easiest way I found to do this is to use https://www.urlencoder.org/ to convert it. convert each param separately and put the converted value instead of the original one.
Here is the screenshot from the solution that works for me, I hope it will be helpful. This is example with Microsoft Graph API but will work with any other scenario:
I'm trying to send get method request and want to pass value in URL.
Like my api look like
app.get('/api/getlocation/:customerName', customer.getlocation);
For call this I wrote in postman
localhost:8080/api/getlocation/:customerName=kumbhani
For test
var customerName = req.params.customerName;
console.log('name', customerName); // =kumbhani
It returns name with = sign - I want only kumbhani
The colon character in the path in Express has a special meaning: whatever you put in the URL after getLocation/ will be put in req.params.customerName.
This means in Postman, you should actually call this URL:
localhost:8080/api/getlocation/kumbhani
→ See related question.