I would like to customize the JSON output of all the SymfonyForms in my Application. Since this is the first time I am building such an Application I am unsure about the best place to put the code to. Right now I see two options:
A custom Handler within the FOSRestBundle as described here
A Handler within the JMSSerializerBundle as mentioned here
I guess that both ways will do the Job, but which one should I prefer here in terms of flexibility and maintainability. As already said above, I would like to change the output for ALL forms and the validation errors in my application. It would be very nice if a little example would be provided.
Right now I get this output if a validation Error occurs:
{
"code": 400,
"message": "Validation Failed",
"errors": {
"children": {
"username": {},
"password": {
"children": {
"first": {},
"second": {}
}
},
"email": {
"errors": ["This value is already used."]
}
}
}
}
And would like to have something like that:
{
"code": …,
"message": …,
"errors": {
"<formname>": {
…
"email": "This value is already used." //errors concatenated to a string
…
}
}
}
Thanks in ahead!
Related
We are in the process of designing a custom build report for our client and have recently stumbled upon a behavior which we could not puzzle. Basically, we are not getting returned the following fields
ad_creative_name
ad_creative_text
ad_creative_title
when sending a GET request as follows:
https://api.linkedin.com/v2/adCreativesV2/136236994?projection=(*,reference~(*))
We're getting a 200 OK response as per below:
"variables": {
"data": {
"com.linkedin.ads.SponsoredInMailCreativeVariables": {
"content": "urn:li:adInMailContent:5139314"
}
}
},
"test": false,
"servingStatuses": [
"RUNNABLE"
],
"type": "SPONSORED_INMAILS",
"version": {
"versionTag": "6"
},
"reference": "urn:li:adInMailContent:5139314",
"changeAuditStamps": {
"lastModified": {
"time": 1624098658000
},
"created": {
"time": 1624035613000
}
},
"review": {
"reviewStatus": "APPROVED"
},
"campaign": "urn:li:sponsoredCampaign:179783044",
"reference!": {
"message": "Unsupported URN domain: li:adInMailContent",
"status": 501
},
"id": 136236994,
"status": "ACTIVE"
}
From the response, you may also notice that we are also getting this warning
"message": "Unsupported URN domain: li:adInMailContent",
"status": 501
We've tried different API requests variations, including specifying different creatives that are active, but to no avail. Also, we were not able to find any info regarding the error above, so we are uncertain what might be causing it.
Thanks!
I am running the following POSTrequest (GET won't work, if anyone was trying and landed here):
URL: https://firestore.googleapis.com/v1/projects/{{ firebaseProjectID }}/databases/(default)/documents:runQuery
The JSON payload I send:
{
"structuredQuery": {
"from": [
{
"collectionId": "items"
}
],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "inStock"
},
"op": "EQUAL",
"value": {
"booleanValue": true
}
}
}
}
}
I receive the following in return:
[
{
"readTime": "2020-04-19T19:38:00.808564Z"
}
]
Why do I receive not a list of documents? I certainly have matching documents.
I should receive all fields given that I entered no list of fields:
https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#Projection
Posting as Community Wiki, due to the talk that occurred in the comments of the question.
As discussed in the comments, between #RenaudTarnec and #Spurious, it seems that the problem was related to the path in the URL. Once it was corrected - might be related to the "allDescendants": true, but it should not - the call worked and returned the values as expected.
Based on the Google Discovery document, and RPC reference, it appears that the :write resource should be available for Firestore database interactions, but performing such a request to my (POST https://firestore.googleapis.com/v1beta1/projects/[my project]/databases/(default)/documents:write) results in:
[
{
"error": {
"code": 400,
"message": "Invalid value (Object), ",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid value (Object), "
}
]
}
]
}
}
]
Is this possible? A related SO answer alludes to this being available as a means of field transforms, the same reason I require this, but I cannot construct valid a JSON body to succeed in the request. Currently, variations on the following don't work as expected when trying a minimum successful response:
{
"writes": [
{
"update": {
"name": "projects/{projectId}/databases/[my project]/documents/exampleId",
"fields": {
"example": {
"integerValue": 100
},
"timestamp": {
"nullValue": null
}
},
"transform": {
"document": "projects/[my project]]/databases/(default)/documents/examples/exampleId",
"fieldTransforms": [
{
"fieldPath": "timestamp",
"setToServerValue": "REQUEST_TIME"
}
]
}
}
}
]
}
First of all, note that you should use the v1 version of the REST API, not the betas.
To create a document, you would use the createDocument method, while to update a document you would use the patch one.
For the document creation you should therefore make a POST HTTP Request to the following URL
https://firestore.googleapis.com/v1/projects/<your-project-id>/databases/(default)/documents/<the-desired-collection>
with the following Request body:
{
fields: {
example: {
integerValue: 100
}
}
}
You need to use documents:commit instead of documents:write
also the name field should be in this format:
"name": "projects/projectID/databases/(default)/documents/collectionName/DocumentId"
See this post.
I'm trying to write the Firebase realtime database ValueEventListener for the following dataset. I've gone thru the documentation but couldn't the figure out way to read the data for the following scenario i.e latest message under every person object. Seems we can use orderByValue() and limitToFirst() to get the latest message under a specific child (person object), but here I'm trying to read the latest messages under multiple child objects.
Dataset:
{
"messages":{
"person-1":{
"shdjkashdjash":
{
"message": "Hi",
"date": 1544061643815
},
"ashakjshasasjhda":
{
"message": "Hello",
"date":1544061724422
}
},
"person-2":{
"ahsgfasgfhagf":
{
"message": "How are you",
"date": 1544061773193
},
"sfjksfsaflashf":
{
"message": "Hey",
"date":1544061777661
}
},
"person-3":{
"fashfahfahf":
{
"message": "This is the sample example",
"date": 1544061784096
},
"sdfsfhshfsjhfshf":
{
"message": "Firebase messages",
"date":1544061789927
}
}
}
}
I am trying to understand
https://developers.google.com/apis-explorer/#p/datastore/v1beta1/datastore.datasets.blindWrite
but I always get
503 Service Unavailable
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 503,
"message": "Backend Error"
}
}
Can you provide a example as simple as possible I can paste to verify it actually works?
I tried something like this.
{
"mutation": {
"insertAutoId": [
{
"key": {
"path": [
{
"kind": "person",
"name": "gert"
}
]
}
}
]
}
}
Assuming that you followed one of the first two activation flows described in the documentation. And created the project recently, an App Engine application should be already associated with your project.
You need to:
Click Authorize your request using OAuth 2.0
Leave https://www.googleapis.com/auth/userinfo.email scope checked
Add https://www.googleapis.com/auth/datastore under Add additional scopes (optional)
Click Authorize and grant the permission
Specify the datasetId parameter (same as your project-id)
Use insert or upsert instead of insertAutoId if the key is complete (kind w/ name or id).
Example:
POST https://www.googleapis.com/datastore/v1beta1/datasets/my-dataset-id/blindWrite...
Content-Type: application/json
Authorization: Bearer ...
X-JavaScript-User-Agent: Google APIs Explorer
{
"mutation": {
"insert": [
{
"key": {
"path": [
{
"kind": "Foo",
"name": "iamfoo"
}
]
}
}
]
}
}
200 OK
{
"kind": "datastore#blindWriteResponse",
"mutationResult": {
"indexUpdates": 1
}
}