API Platform 3 does not return null data in response body - api-platform.com

In API Platform 2.7 the response body contained fields that had a null value, after upgrading to API Platform 3 the response body does not contain fields that have a null value. Is this deliberate or due to a configuration change I need to make.
I executed the same call from the api/docs page for 2.7 and 3.0 I expected the results to be the same.
API Platform 2.7 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"email": null,
"title": null,
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"suffix": null,
"photoMedia": null,
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"addressLineTwo": null,
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
"mobileNumber": null,
"workNumber": null
}
API Platform 3.0 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
}

Relates to this question
You only need to set skip_null_values to false in your normalization_context, because starting 3.0.0 beta 1 they decided it would become true by default.
If you need it to be false for all resources, you can set the default in your config/packages/api_platform.yaml:
api_platform:
...
defaults:
normalization_context:
skip_null_values: false

Related

Nifi - Route the JSON based on the Array Name

I am new to Nifi, i hv a requirement where we get multiple JSON inputs with different Header Names. I have to parse the JSON and insert into different tables based on the Header value.
Not sure how to use RouteonContent processor or EvaluateJSON Path processor
Input 1
{
"Location": [
{
"country": "US",
"division": "Central",
"region": "Big South",
"locationID": 1015,
"location_name": "Hattiesburg, MS (XF)",
"location_type": "RETAIL",
"location_sub_type": "COS",
"store_type": "",
"planned_open_date": "",
"planned_close_date": "",
"actual_open_date": "2017-07-26",
"actual_close_date": "",
"new_store_flag": "",
"address1": "2100 Lincoln Road",
"address2": "",
"city": "Hattiesburg",
"state": "MS",
"zip": 39402,
"include_for_planning": "Y"
},
{
"country": "US",
"division": "Central",
"region": "Big South",
"locationID": 1028,
"location_name": "Laurel, MS",
"location_type": "RETAIL",
"location_sub_type": "COS",
"store_type": "",
"planned_open_date": "",
"planned_close_date": "",
"actual_open_date": "",
"actual_close_date": "",
"new_store_flag": "",
"address1": "1225 5th street",
"address2": "",
"city": "Laurel",
"state": "MS",
"zip": 39440,
"include_for_planning": "Y"
}
]
Input 2
{
"Item": [
{
"npi_code": "NEW",
"cifa_category": "XM",
"o9_category": "Accessories"
},
{
"npi_code": "NEW",
"cifa_category": "XM0",
"o9_category": "Accessories"
}
]
Use the website https://jsonpath.com/ to figure out the proper JSON expression. But what you could potentially do is use: if the array contains either $.npi_code then do X and if it contains $. country, then do Y

Validation of each field in JSON response using karate API

I want to validate particular fields in the response whether it is integer or float(ex: fullbathrooms field). I tried below code but getting match failed error. Could you please help here ?.....Thanks
Given path '/property-client'
And request {"address": <address>,"city": <city>,"state": <state>,"zipCode": <zipCode>}
When method post
Then status 200
And print response
And match response == {fullbathrooms:'#number'}
Examples:
|read('testFile1.csv')|
Error : match failed: EQUALS
Actual response:
{
"success": true,
"message": {
"version": "1.0",
"response": {
"id": "94568859",
"type": "express",
"responseheader": null,
"reportdata": {
"property": {
"source": null,
"type": null,
"dom": null,
"propertytype": "Single Family Residence",
"standardtype": null,
"address": {
"documentid": null,
"number": "150",
"directional": null,
"street": "BRIDGE",
"suffix": "RD",
"postdirectional": null,
"unit": "",
"city": "HILLSBOROUGH",
"state": "CA",
"zip": "94010",
"zipplus4": "6908",
"fulladdress": "150 BRIDGE RD, HILLSBOROUGH, CA 94010"
},
"info": {
"type": null,
"fips": "6081",
"county": "San Mateo",
"bedrooms": "5",
"bathrooms": "6.50",
"fullbathrooms": "6.50",
"totalrooms": "0",
"livingarea": "7750",
"totallivingarea": "7750",
"landarea": "41382",
"landareatype": null,
"pool": "true",
"landvalue": "6904800",
"improvementvalue": "3284414",
"assessedvalue": "10189214",
"assessedyear": "2021",
"taxvalue": "11746898",
"taxyear": "2021",
"deliquentyear": null,
"yearbuilt": "2011",
"propertytax": null,
"approxage": "11",
"parcelnumber": "032-400-110",
"titlecompany": null,
"geocode": {
"latitude": "37.563272",
"longitude": "-122.334442",
"geoqualitycode": ""
}
}
Please take some time to read the documentation: https://github.com/karatelabs/karate#match-contains
I'm not going to refer to your response dump (which by the way is not valid JSON), but give you a simple example. Please pay attention to the structure of your JSON. And note that the 6.50 is a string not a number in your response.
* def response = { "foo": { "bar": { "fullbathrooms": "6.50" } } }
* match response.foo.bar == { fullbathrooms: '#string' }
If you want to validate numbers within strings, please refer other answers, for example: https://stackoverflow.com/search?q=%5Bkarate%5D+number+regex

Select random name from the JSON response in JMeter

In the response body I have the following JSON, which contains and id and as a child element a name and I want to select random name and its corresponding id every time I run my test, how to do it?
May be through a post processer or json extractor, I am new to JMeter.
{
"entities": {
"chairs": {
"a99a921e-9ced-43eb-8521-a8e972c5afee": {
"id": "a99a921e-9ced-43eb-8521-a8e972c5afee",
"accountId": "02a39418-2936-4696-9f3f-02f503128ac7",
"description": null,
"isActive": true,
"pmsId": "5079767850816079897",
"name": "PranayOP",
"createdAt": "2021-03-18T17:46:53.253Z",
"updatedAt": "2021-03-18T17:46:53.253Z",
"deletedAt": null
},
"eb125d3a-739f-479c-b803-dbffb6a871d0": {
"id": "eb125d3a-739f-479c-b803-dbffb6a871d0",
"accountId": "02a39418-2936-4696-9f3f-02f503128ac7",
"description": null,
"isActive": true,
"pmsId": "-3332289498024566266",
"name": "OVERFLOW",
"createdAt": "2021-03-16T00:42:35.115Z",
"updatedAt": "2021-03-16T00:42:35.115Z",
"deletedAt": null
},
"36891051-1edf-46ea-a167-68d39a8a70f5": {
"id": "36891051-1edf-46ea-a167-68d39a8a70f5",
"accountId": "02a39418-2936-4696-9f3f-02f503128ac7",
"description": null,
"isActive": true,
"pmsId": "-4453494259576621766",
"name": "OP55",
"createdAt": "2021-03-20T02:19:00.494Z",
"updatedAt": "2021-03-20T02:19:00.494Z",
"deletedAt": null
},
"85a2564e-7cd1-4e69-be5d-a979b5e56cd5": {
"id": "85a2564e-7cd1-4e69-be5d-a979b5e56cd5",
"accountId": "02a39418-2936-4696-9f3f-02f503128ac7",
"description": null,
"isActive": true,
"pmsId": "8283273375660346038",
"name": "OP02",
"createdAt": "2021-03-16T00:42:34.832Z",
"updatedAt": "2021-03-16T00:42:34.832Z",
"deletedAt": null
}
}
},
"result": [
"a99a921e-9ced-43eb-8521-a8e972c5afee",
"eb125d3a-739f-479c-b803-dbffb6a871d0",
"36891051-1edf-46ea-a167-68d39a8a70f5",
"85a2564e-7cd1-4e69-be5d-a979b5e56cd5"
]
}
Add JSON JMESPath Extractor as a child of the request which returns the above JSON
Configure it as follows:
here is the textual representation of the JMESPath query just in case:
entities.chairs.*.[name,id]
That's it, each time it will get the random name/id combination in form of ["OP55","36891051-1edf-46ea-a167-68d39a8a70f5"]
which can be referenced as ${nameAndId} where required
More information: The JMeter JSON JMESPath Extractor and Assertion: A Guide

Duplicate ID in PUT url when editing Restangular model in ui-router custom path

currently I'm setting up restangular to edit my model. Formerly it was ok when I'm not using custom url to show the form, like
http://example.com/admin/clients (I just load the form there).
But, then I use ui-router to setup the URL like this
http://example.com/admin/clients/{clientId}/edit
When I do model.put() or model.save(), the resulting PUT url is wrong. It become like this
PUT http://referral.dev/admin/clients/f2aa1490-5a8f-11e5-b936-b3a54e0c9925/f2aa1490-5a8f-11e5-b936-b3a54e0c9925
It should be like this:
PUT http://referral.dev/admin/clients/f2aa1490-5a8f-11e5-b936-b3a54e0c9925
What I do wrong?
For convenience, here is debug from restangular object:
{
"restangularCollection": false,
"$object": {
"id": "f2aa1490-5a8f-11e5-b936-b3a54e0c9925",
"referrer_id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Claudia.Kertzmann#hotmail.com",
"first_name": "Isabelle",
"last_name": "Herzog",
"mobile": "450.357.8579x621",
"stage": "member",
"stage_at": "2015-09-09 00:00:00",
"previous_stages": [
{
"stage": "lead",
"stage_at": "2015-08-30 00:00:00"
}
],
"total_investment": 190000,
"email_token": "caf34dddfe00f36b180d459236830934",
"confirmed": false,
"unsubscribed": false,
"transfered_at": null,
"previous_referrers": [],
"created_at": "2015-09-14 03:23:20",
"updated_at": "2015-09-14 03:23:20",
"referrer": {
"id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Eulalia.Pacocha#Dickens.biz",
"name": "Esperanza Aufderhar Sr.",
"mobile": "658.549.0277",
"role": "referrer",
"organization_id": "f0577b10-5a8f-11e5-984f-f120de15e3c1",
"last_login_at": "0000-00-00 00:00:00",
"suspended": 0
},
"route": "f2aa1490-5a8f-11e5-b936-b3a54e0c9925",
"reqParams": null,
"restangularized": true,
"fromServer": true,
"parentResource": {
"route": "admin/clients",
"parentResource": null
},
"restangularCollection": false
}
}
And, here is the restangular object if don't use custom URL (which working):
{
"id": "f2aa1490-5a8f-11e5-b936-b3a54e0c9925",
"referrer_id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Claudia.Kertzmann#hotmail.com",
"first_name": "Isabelle",
"last_name": "Herzog",
"mobile": "450.357.8579x621",
"stage": "member",
"stage_at": "2015-09-09 00:00:00",
"previous_stages": [
{
"stage": "lead",
"stage_at": "2015-08-30 00:00:00"
}
],
"total_investment": 190000,
"email_token": "caf34dddfe00f36b180d459236830934",
"confirmed": false,
"unsubscribed": false,
"transfered_at": null,
"previous_referrers": [],
"created_at": "2015-09-14 03:23:20",
"updated_at": "2015-09-14 03:23:20",
"referrer": {
"id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Eulalia.Pacocha#Dickens.biz",
"name": "Esperanza Aufderhar Sr.",
"mobile": "658.549.0277",
"role": "referrer",
"organization_id": "f0577b10-5a8f-11e5-984f-f120de15e3c1",
"last_login_at": "0000-00-00 00:00:00",
"suspended": 0
},
"route": "admin/clients",
"reqParams": null,
"restangularized": true,
"fromServer": true,
"parentResource": null,
"restangularCollection": false
}
I've tried manually set $object.route to "admin/clients" but the PUT url is still the same.
Thanks.. :)
I've solved it. Formerly I was using:
var models = Restangular.all('admin/clients');
Then use
models.one($stateParams.clientId).get()
to get the model.
The correct way, is use Restangular.one to load model, eg. like this:
vm.model = Restangular.one('admin/clients', $stateParams.clientId).get();

How to get filtered activity stream using Yammer API?

Yammer Activity Stream is available at:
https://www.yammer.com/api/v1/streams/activities.json?access_token=
This successfully results in all the recent activities like:
{
"items": [
{
"id": "/users/www.yammer.com-341514-1508953644/rollups/45191477209921-45191477209921",
"unseen": true,
"icon": "/images/notifications/page_add.png",
"icon_name": null,
"category": "file-create",
"message": "[[user:1508783078]] uploaded [[uploaded_file:24511980]].",
"heading": "",
"created_at": "2014/10/02 07:07:42 +0000",
"objects": [],
"actions": [],
"subject": {
"type": "uploaded_file",
"id": 24511980
},
"meta": null,
"client_type": "unknown",
"client_url": "https://www.yammer.com",
"client_icon": "https://mug0.assets-yammer.com/mugshot/images/16x16/3rd_party.png",
"client_large_icon": "https://mug0.assets-yammer.com/mugshot/images/75x75/3rd_party.png",
"image": "https://mug0.assets-yammer.com/mugshot/images/48x48/no_photo.png",
"third_party": false
},
{
"id": "/users/www.yammer.com-341514-1508953644/rollups/45191475863746-45191475863746",
"unseen": true,
"icon": "/images/notifications/page_add.png",
"icon_name": "page",
"category": "file-download",
"message": "[[user:1508783078]] downloaded [[uploaded_file:24373320]] from the [[group:3455089]] group.",
"heading": "",
"created_at": "2014/10/02 07:07:00 +0000",
"objects": [
{
"id": 24373320,
"type": "uploaded_file"
}
],
"actions": [],
"subject": {
"type": "uploaded_file",
"id": 24373320
},
"meta": null,
"client_type": "unknown",
"client_url": "https://www.yammer.com",
"client_icon": "https://mug0.assets-yammer.com/mugshot/images/16x16/3rd_party.png",
"client_large_icon": "https://mug0.assets-yammer.com/mugshot/images/75x75/3rd_party.png",
"image": "https://mug0.assets-yammer.com/mugshot/images/48x48/no_photo.png",
"third_party": false
},
]}
QUESTION:
I am trying to get all the recent activities after a certain time-stamp or after a certain offset. Is there any query parameter for that?
this is
older_than="/users/www.yammer.com-341514-1508953644/rollups/45191475863746-45191475863746"
that would return all the activities older than the last activities you shew in your sample return value

Resources