I am trying to get the phone number in studio liquid-template.No matter what pattern I turn into it never extract the data.considering the data is a return object from a http post
{{widgets.http_1.parsed.attributes.phone}}
{{widgets.http_1.parsed["attributes"].phone}}
{{widgets.http_1.parsed.[attributes].phone }}
{{widgets.http_1.body["attributes"].phone }}
{{widgets.http_1.body.attributes.phone}}
{{widgets.http_1.parsed["attributes"].phone}}
{accountSid=ac, activityName=Offline, activitySid=wa,
attributes={
"onlyOutboundCallMode": false,
"routing": {
"skills": [
"english"
]
},
"email": "#gmail.com",
"phone":"12323"
},
available=false}
For deeply nested objects, you will need to parse the data outside Studio. Take a look at the Studio execution logs of your Studio flow. See if the HTTP Request widget was able to parse the JSON structure.
Returning this structure worked for Studio which parsed it:
let respObj = {
accountSid: "ac",
activityName: "Offline",
activitySid: "wa",
attributes: {
onlyOutboundCallMode: false,
routing: {
skills: [
"english"
]
},
email: "#gmail.com",
phone:"12323"
},
available: false}
Result in Studio:
"parsed": {
"accountSid": "ac",
"activityName": "Offline",
"activitySid": "wa",
"attributes": {
"onlyOutboundCallMode": false,
"routing": {
"skills": [
"english"
]
},
"email": "#gmail.com",
"phone": "12323"
},
"available": false
}
Related
I'm trying to make a query that gets all the prices that starts with '12'.
I have a collection like this:
{
"place": "Costa Rica",
"name": "Villa Lapas",
"price": 1353,
},
{
"place": "Costa Rica",
"name": "Hotel NWS",
"price": 1948,
},
{
"place": "Costa Rica",
"name": "Hotel Papaya",
"price": 1283,
},
{
"place": "Costa Rica",
"name": "Hostal Serine",
"price": 1248,
},
And I want my results like this:
{
'prices': [
1248,
1283
]
}
I'm converting all the prices to string in order to use a regex function. But I don't understand very well how to use the regex in my query.
My query returns:
{ "prices" : null }
{ "prices" : null }
Could someone please guide me? :)
db.collection.aggregate([
{'$project': {
'_id': 0,
'price': {'$toString': '$price'}
}},
{'$project': {
'prices': {'$regexFind': { 'input': "$price", 'regex': '^12' }}
}}
]).pretty();
You are almost correct.
db.test.aggregate([
{'$project': {
'_id': 0,
'prices': {'$toString': '$price'}
^^^ -> I meant this
}},
{'$match': {
'prices': {'$regex': '^12' }
^^^ -> same here
}}
])
You need to use $match with $regex which yields the result as you expected.
If you use regexFind, it works on all matching docs and returns null where input doesn't match the pattern
And
In the first project you have price instead prices. If you refer the first project name in the second project, then pipeline matches.
I am having a postman collection which consists of request and test cases for each requests. I have two test case for each request. one for validating status code and other for validating response time. I need to execute status code test case frequently and response time test case results occasionally.How to achieve it without modifying the collection for every run and is it achievable in providing any option in terminal?
collection.json
{
"name": "Metadata",
"item": [
{
"name": "info",
"event": [
{
"listen": "test",
"script": {
"id": "32cf67e7-5d42-4231-86fe-e7fffa32c855",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"pm.test(\"Response time is less than 300ms\", function () {",
" pm.expect(pm.response.responseTime).to.be.below(300);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{tokenAdmin}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/api/m0/metadata/info",
"host": [
"{{url}}"
],
"path": [
"api",
"m0",
"metadata",
"info"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
}
For a very basic flow, you can use moment to check which day it currently is and if that matches the condition, it will run the responseTime test.
let moment = require('moment'),
date = moment().format('dddd');
// Runs on each request
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// Only runs on a Friday
if (date === 'Friday') {
pm.test("Response time is less than 1000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(1000);
});
}
Moment has lots of different options available to you and might work if you want to only run that check at the end of the sprint or on a given day.
I have this scope defined in my order.json which has relation with branch and customer along with other properties.
"name": "Order",
"properties":{...},
"relations": {...},
"acls": {...},
"scope": {
"include": [
{"relation": "branch", "scope": { "fields": "BranchName" } },
{"relation": "customer", "scope": { "fields": "CustomerName" } }
]
}
This works well as expected in all GET requests with following results
[
{
"OrderDate": "2018-01-12T17:52:21.000Z",
"CustomerId": 39,
"BranchId": 5,
"CustomerRef": "Order by Phone",
...
"CreatedBy": 1,
"id": 1,
"branch": {
"BranchName": "aaaa",
"id": 5
},
"customer": {
"CustomerName": "xxxx",
"id": 39
}
}
]
I was expecting a similar result, however, the response array received after a successful POST request does not include BranchName and CustomerName info from the related models.
Am I doing it correctly? or is there any other way to get back information from related models after a Create/Update operation. I am just trying to avoid another GET request immediately after Create/Update.
You can use the Operation hook after save.
Order.observe('after save', function(ctx, next) {
if (ctx.instance) {
ctx.instance.relatedmodel = someFunctionToGetRelatedModel();
}
next();
});
Whatever is inside the ctx.instance should be included in loopbacks responses.
You just have to figure out how to seamlessly pull the related model details, you want to include.
If an article has several comments (think thousands over time). Should data.relationships.comments return with a limit?
{
"data": [
{
"type": "articles",
"id": 1,
"attributes": {
"title": "Some title",
},
"relationships": {
"comments": {
"links": {
"related": "https://www.foo.com/api/v1/articles/1/comments"
},
"data": [
{ "type": "comment", "id": "1" }
...
{ "type": "comment", "id": "2000" }
]
}
}
}
],
"included": [
{
"type": "comments",
"id": 1,
"attributes": {
"body": "Lorem ipusm",
}
},
.....
{
"type": "comments",
"id": 2000,
"attributes": {
"body": "Lorem ipusm",
}
},
]
}
This starts to feel concerning, when you think of compound documents (http://jsonapi.org/format/#document-compound-documents). Which means, the included section will list all comments as well, making the JSON payload quite large.
If you want to limit the number of records you get at a time from a long list use pagination (JSON API spec).
I would load the comments separately with store.query (ember docs), like so -
store.query('comments', { author_id: <author_id>, page: 3 });
which will return the relevant subset of comments.
If you don't initially want to make two requests per author, you could include the first 'page' in the authors request as you're doing now.
You may also want to look into an addon like Ember Infinity (untested), which will provide an infinite scrolling list and automatically make pagination requests.
My backed is giving me some information about the reply in a meta field. For example, when going to #/phoneNumbers/phonelocations/index a request to /api/phonelocations is sent, and this is the data received:
{
"meta": {
"api_action": "find_all",
"api_id": "phonelocations",
"content_type": "application/json",
"error_code": 200,
"errors": [
{
"admin_message": "",
"code": 200,
"message": ""
}
],
"message": "Successfully read phonelocations",
"success": true
},
"phonelocations": [
{
"_id": "0",
"city": "Berlin",
"count": 10,
"country": "DE",
"country_name": "Germany",
"loctype": "GEO",
"loctype_human": "Geographical number",
"subtype": "49GEO",
"subtype_human": "German geographical number",
"type": "phonelocation-faketype"
},
...
]
}
This is present in all replies coming from the backend. I would like to use the message in _reply_meta.message to display it to the user. Is there a standard way in Ember to access the meta information of the replies?
Just use store.metadataFor(type), in your case:
var meta = this.store.metadataFor('phonelocation');
// all metadata is in meta object
meta.message // => "Successfully read phonelocations"
See this in action http://jsfiddle.net/marciojunior/3vfQD/