kylebrowning / waterwheel.swift

The Waterwheel Swift SDK provides classes to natively connect iOS, macOS, tvOS, and watchOS applications to Drupal 7 and 8.
MIT License
412 stars 93 forks source link

Error while creating comments #151

Closed deepakml closed 7 years ago

deepakml commented 7 years ago

Hi,

I am using waterwheel-swift to connect my app with Drupal 8, it works really well. The only issue i am having is when creating comments. I get 400 status error.

I am using the following code

`let body = [
    "entity_type": [
        [
            "value": "node"
        ]
    ],
    "entity_id": [
        [
            "target_id": self.nodeID
        ]
    ],
    "field_name": [
        [
            "value": "field_x"
        ]
    ],
    "comment_body": [
        [
            "value": "How are you?"
        ]
    ]
]

waterwheel.entityPost(entityType: .Comment, params: body as paramType) { (success, response, json, error) in
    if (success) {
        print(response)
    } else {
        print(error)
    }
}`

and my comments rest config is

  langcode: en
  status: true
  dependencies:
    module:
      - basic_auth
      - comment
      - csv_serialization
      - hal
      - serialization
      - user
  id: entity.comment
  plugin_id: 'entity:comment'
  granularity: method
  configuration:
    GET:
      supported_formats:
        - csv
        - hal_json
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie
    POST:
      supported_formats:
        - csv
        - hal_json
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie
    DELETE:
      supported_formats:
        - csv
        - hal_json
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie
    PATCH:
      supported_formats:
        - csv
        - hal_json
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie

Please let me know if there is something wrong with my code.

Thank you Deepak

deepakml commented 7 years ago

The following code did the trick, the issue was, i was not passing comment_type

 let body = [
    "entity_type": [
        [
            "value": "node"
        ]
    ],
    "entity_id": [
        [
            "target_id": self.nodeID
        ]
    ],
    "field_name": [
        [
            "value": "comment_x",  // Machine name of the field on the node
            "format": "no_html"
        ]
    ],
    "comment_body": [
        [
            "value": "How are you?"
        ]
    ],
    "comment_type": [
        [
            "target_id": "comment_x"  // Machine name of the comment bundle 
        ]
    ],
    "uid": [
        [
            "target_id": self.UID
        ]
    ],
]