contenta_jsonapi icon indicating copy to clipboard operation
contenta_jsonapi copied to clipboard

Example of making a Recipe Post including image?

Open justinlevi opened this issue 7 years ago • 3 comments

Is there an example anywhere of making a POST request for the recipe content type and attaching an image to the entity reference field?

justinlevi avatar Dec 08 '17 00:12 justinlevi

Not an example per se, but the official JSON API documentation (https://www.drupal.org/docs/8/modules/json-api) will explain how to upload files.

e0ipso avatar Dec 08 '17 11:12 e0ipso

@e0ipso Thanks for the reminder about the documentation. I forgot D.O. actually had some good documentation for the JSON API.

One follow up question though, creating a POST request to create an image entity with a base64 image is easy enough, and creating a POST request to create a new node/resource is easy enough.

Are there any "gotchas" or "blockers" for creating a node w paragraph media image entities? Do you know if this is currently possible and has anyone done this yet?

Thanks so much for all your hard work on this!

##POST request with relationships URL: http://example.com/jsonapi/node/article

Request body

{
  "data": {
    "type": "node--article",
    "attributes": {
      "title": "Article by admin",
      "body": {
        "value": "Custom value",
        "format": "plain_text"
      }
    },
    "relationships": {
      "uid": {
        "data": {
          "type": "user--user",
          "id": "{{UUID of user 1}}"
        }
      }
    }
  }
}

source: https://www.drupal.org/docs/8/modules/json-api/creating-new-resources-post

justinlevi avatar Dec 08 '17 12:12 justinlevi

Search for the "Incredible decoupled performance using Subrequests" article in your Contenta knowledge hub.

e0ipso avatar Dec 08 '17 14:12 e0ipso