Skip to content

POST (create new item) with nested data #1363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GonZOO82 opened this issue Sep 12, 2017 · 7 comments
Closed

POST (create new item) with nested data #1363

GonZOO82 opened this issue Sep 12, 2017 · 7 comments

Comments

@GonZOO82
Copy link

I would like POST with nested data, but don't succeed.

Sample:

{
    "title": "test",
    "cover": {  //ManyToOne connection to MediaItem Entity
        "id": 1 // This MediaItem is exist
    }
}

Response: Update is not allowed for this operation.

but when I update item (PUT) then process is good.

I don't want to use this code:

{
    "title": "test",
    "cover": "/media_item/1"
}
@soyuka
Copy link
Member

soyuka commented Sep 12, 2017

What format are you using (ie Accept header)?

@GonZOO82
Copy link
Author

I try application/json and application/ld+json

json --> {"id":1} . --> Update is not allowed for this operation.
ld+json --> {"@id":1} --> Update is not allowed for this operation.

json --> {"@id":1} . --> try run SQL nested data INSERT command
ld+json --> {"id":1} --> try run SQL nested data INSERT command

@soyuka
Copy link
Member

soyuka commented Sep 12, 2017

What works with json-ld:

POST /books

{
  "cover": "/covers/1",
  "title": "foo"
}

About json I'm investigating.

@soyuka
Copy link
Member

soyuka commented Sep 12, 2017

api-platform/api-platform#249 not supported yet with plain IDs.

@GonZOO82
Copy link
Author

@soyuka not supported when I POST data, but supported in PUT method?!

if (!$normalization && !isset($context['api_allow_update'])) {
    $context['api_allow_update'] = Request::METHOD_PUT === $request->getMethod();
}

If I PUT data with nested content then it's successful.

Video: https://youtu.be/kEuzdS4z3wk

@mab05k
Copy link
Contributor

mab05k commented Oct 31, 2017

I was able to get something like this to work by adding "api_allow_update=true" in my deserialization context.

Example

AppBundle\Entity\Resource:
    attributes:
        normalization_context:
            groups: [ 'resource.read' ]
        denormalization_context:
            api_allow_update: true
            groups: [ 'resource.write' ]

This allowed me to POST in data with full object references when I had embedded objects. It worked for me using JSON, LD+JSON, and HAL+JSON.

jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 3, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 3, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 4, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 11, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 11, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 11, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 11, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 11, 2018
jdeniau added a commit to jdeniau/api-platform-core that referenced this issue Jan 12, 2018
@Simperfit
Copy link
Contributor

This seems to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants