Anyone know how to add paramters to Faker functions on mockapi.io? - json

I'm exploring API mocking tool and this one seems to be the bee's knees. Even with out figuring this out, I'm still probably going to use it for my needs.
But there's a thing that bugs me. You can mock the response you want using Faker.js in their JSON editor like so:
{
"username": "$internet.userName",
"balance": "$finance.amount"
}
This will result in a response that looks like:
[
{
"username": "Leilani46",
"balance": "116.96",
"userid": "1"
},
{
"username": "Ellie.Stehr26",
"balance": "15.37",
"userid": "2"
},
{
"username": "Gilda60",
"balance": "677.77",
"userid": "3"
},
... etc
]
According to the Faker docs you can add parameters to the methods to control the output a little. For example finance.amount(4,10) will give you a number between 4 and 10.
I haven't found a way to get this to work, these have been my attempts:
{
"username": "$internet.userName",
"balance": "$finance.amount(4,10)"
}
{
"username": "$internet.userName",
"balance": "$finance.amount 4 10"
}
...etc
It always just results in the literal string
[
{
"username": "Leilani46",
"balance": "116.96",
"userid": "1"
},
{
"username": "Ellie.Stehr26",
"balance": "$finance.amount(4,10)",
"userid": "2"
},
{
"username": "Gilda60",
"balance": "$finance.amount(4,10)",
"userid": "3"
},
... etc
]
I've reached out to their contact email, but there's no better place to tell me I'm asking too much of this world than StackOverflow.
Beuller?

For completion, they reached back out to me and confirmed that what I want to do isn't available, yet.

Related

Why is JSON being detected as empty?

So I have a JSON file I got from Postman which is returning as an empty object. This is how I'm reading it.
import regscooter from './json_files/reginald_griffin_scooter.json'
const scoot = regscooter;
const CustomerPage = () => {...}
reginald_griffin_scooter.json
{
"success": true,
"result": {
"id": "hhhhhhhhhh",
"model": "V1 Scooter",
"name": "hhhhhhhhhh",
"status": "active",
"availabilityStatus": "not-available",
"availabilityTrackingOn": true,
"serial": "hhhhhhhhhhhh",
"createdByUser": "hhhhhhhhK",
"createdByUsername": "hhhhhhhh",
"subAssets": [
"F0lOjWBAnG"
],
"parts": [
"hhhhhhhh"
],
"assignedCustomers": [
"hhhhhhhhh"
],
"createdAt": "2019-12-03T21:47:26.218Z",
"updatedAt": "2020-06-26T22:05:54.526Z",
"customFieldsAsset": [
{
"id": "hhhhhhh",
"name": "MAC",
"value": "hhhhhhhh",
"asset": "hhhhhhhhhh",
"user": "hhhhhhhhh",
"createdAt": "2019-12-03T21:47:26.342Z",
"updatedAt": "2019-12-11T16:29:24.732Z"
},
{
"id": "hhhhhhhh",
"name": "IMEI",
"value": "hhhhhhh",
"asset": "hhhhhhh",
"user": "hhhhhhhhhh",
"createdAt": "2019-12-03T21:47:26.342Z",
"updatedAt": "2019-12-11T16:29:24.834Z"
},
{
"id": "hhhhhhhhh",
"name": "Key Number",
"value": "NA",
"asset": "hhhhhhhhh",
"user": "hhhhhhhhhhh",
"createdAt": "2019-12-03T21:47:26.342Z",
"updatedAt": "2019-12-11T16:29:24.911Z"
}
]
}
}
The error is that "const scoot" is being shown as an empty object {}. I made sure to save a ton of times everywhere. I am able to read through the imported JSON file in other variables in similar ways, so I don't know why I can't parse this one. I just want to access the JSON object inside this. Also I omitted some information with hhhhh because of confidentiality.
EDIT: The code works, but it still has a red line beneath result when I do:
const scoot = regscooter.result.id;
It would be much more effective if you will provide an example in codesandbox or so.
However at first look it might be a parser issue ( maybe you are using Webpack with missing configuration for parsing files with json extension ), meaning we need more information to provide you with a full answer ( maybe solution ? ).
Have you tried to do the next:
const scoot = require('./json_files/reginald_griffin_scooter.json');

How to create a config file for a homebridge accessory

I have installed a plugin to control my Samsung TV (https://github.com/xeenon/homebridge-samsung-tv) via my Homebridge server, however the developer did not provide a config-sample.json, hence why I am trying to make my own. I am entirely new to coding so please tell me what I am doing wrong.
This is the part of my config file for that accessory as of now (I will add the ip adress and mac adress later).
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}]
}
When I am trying to start Homebridge I get the error
TypeError: Cannot read property 'forEach' of undefined
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10
If I however change the config file to
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1",
"enabledInputs": "true"
}]
}
where I added
"enabledInputs": "true"
i get the error
TypeError: config.enabledInputs.forEach is not a function
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10
I would really appreciate any help!
Did you try valid JSON ? Would tell you are missing brackets around, also from first lines of source it looks like. It should work like this
objectVar = {
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_adress": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}
Or like this in case it you are using string somewhere: "{\"accessory\":\"samsungTv\",\"name\":\"samsungTvAccessory\",\"ip_adress\":\"\",\"macAddress\":\"\",\"polling\":\"true\",\"pollingInterval\":\"1\"}"
And then there are methods JSON.stringify(objectVar [, null, indent]) or JSON.parse(string) to convert to string or back. Stringify has also optional parameters - first is a replacer function and second indent if you want it people friendly formatted.

Microsoft Flow: How to Concatenate Data from JSON Object

I have a REST Web Services Call that is returning data in the following format:
{
"Id": "0497cee4-45dc-47d8-97a8-b45ad8018775",
"Status": "OK",
"ProviderName": "MyApp",
"DateTimeUTC": "/Date(1508348383277)/",
"Contacts": [
{
"ContactID": "1efa0ea1-de5c-4172-869c-816e27c3c825",
"ContactStatus": "ACTIVE",
"Name": "Company",
"FirstName": "Joe",
"LastName": "Bob",
"EmailAddress": "mainguy#here.com",
"BankAccountDetails": "",
"ContactPersons": [
{
"FirstName": "Operations",
"LastName": "",
"EmailAddress": "there#here.com",
"IncludeInEmails": true
},
{
"FirstName": "Another",
"LastName": "Contact Email",
"EmailAddress": "here#there.com",
"IncludeInEmails": true
}
],
"HasAttachments": false,
}
]
}
Within Microsoft Flow I would like to grab the main contact email (Contacts.EmailAddress) as well as all of the secondary Contacts Emails (Contacts.ContactPersons[x].EmailAddress); and use that for the too field of down-flow email.
ContactPersons will not always be defined in every case, but Contacts.EmailAddress should be.
What is the best way to do this with a flow? Is there a way to concatenate data over a loop or something? I can't seem to find a way to do it.
Try using Data Operations (https://learn.microsoft.com/en-us/flow/data-operations).
You can start off with a Select, picking the EmailAddress field in the Map, and then redirecting that to a Join and using that output.

How to get the group name associated with username in service now by REST API

https://MYINSTANCE.now.com/api/now/table/sys_user_grmember?sysparm_display_value=all
{
"result": [
{
"sys_id": {
"display_value": "0055d61edb7fbe00115032dd7c961914",
"value": "0055d61edb7fbe00115032dd7c961914"
},
"sys_updated_by": {
"display_value": "SD1234",
"value": "SD1234"
},
"sys_created_on": {
"display_value": "09.07.2017 12:36:50",
"value": "2017-07-09 02:36:50"
},
"sys_mod_count": {
"display_value": "0",
"value": "0"
},
"sys_updated_on": {
"display_value": "09.07.2017 12:36:50",
"value": "2017-07-09 02:36:50"
},
"sys_tags": {
"display_value": "",
"value": ""
},
"user": {
"display_value": "Rahul Davis",
"link": "://MYINSTANCE.com/api/now/table/sys_user/cb154dd94f735e000d7f0ed11310c7a7",
"value": "cb154dd94f735e000d7f0ed11310c7a7"
},
"sys_created_by": {
"display_value": "SD1234",
"value": "SD1234"
},
"group": {
"display_value": "MAJOR_INCIDENT_MANAGEMENT_AU",
"link": "://MYINSTANCE.com/api/now/table/sys_user_group/2cc9e481db6b7200115032dd7c9619e3",
"value": "2cc9e481db6b7200115032dd7c9619e3"
}
}
]
}
and so on......
how can i get group name by giving username as rahul davis with sysparm with this API can anyone suggest me which one i have to use for this json format ??
First of all, you don't want to pull group membership based on a user's name, because name is not a unique value. Instead, if you can't get the user's sys_id, you might want to use their user ID. To do that, simply use a REST GET call on the following API:
https://[[INSTANCE]].service-now.com/api/now/table/sys_user_grmember?sysparm_query=user.user_name%3D[[USERNAME]]&sysparm_display_value=all
Simply replace [[INSTANCE]] with your instance name, and [[USERNAME]] with the username you're looking for. In this line above, you can see the segment in italic (sysparm_query=user.user_name%3D[[USERNAME]]) is the query. I got it, by navigating to sys_user_grmember.list from the application navigator, and running a query by dot-walking from the user field, to the user's used ID field in the query, and checking for a specific user ID.
Also, if you're looking for the group name, just append &sysparm_fields=group.name to your query URI.
You can use the "REST API Explorer" in ServiceNow to construct REST queries using the table, or other APIs, really easily in the future, if you ever need some quick help! :-)

How to handle assertion property content for differenrt responses?

I would like to handle assertion property content according to below responses, for both success and failure.
Success response:
{
"task": "userLogin",
"response": {
"code": 0,
"status": "success",
"error_message": "",
"success_message": "",
"data": {
"userId": "65",
"username": "indian",
"email": "test#gmail.com",
"token": "b0aef6139ffdc1041e01f7587a0dcf61",
"userType": "trial",
"profile_picture": "test.png"
}
}
}
Failure response: will have only the data node missing, and remaining nodes will be present.
"data":
{
"userId": "65",
"username": "indian",
"email": "test#gmail.com",
"token": "b0aef6139ffdc1041e01f7587a0dcf61",
"userType": "trial",
"profile_picture": "test.png"
}
You can use a very simple XPath assertion, keeping in mind that internally SoapUI converts everything into XML representation.
XPath:
exists(//*:data)
Expected:
true
Update based on your comments.
Your original requirement was not clear. The node is present it is just empty. In that case the XPath assertion would be:
empty(//*:data)
Expected:
false
Handy XPath reference.