Hi All,

Hopefully someone can point me towards the right direction. We have a SaaS platform and trying to integrate our system with Drupal 7 backend. We want to create taxonomies with a vocabulary and I am getting this error and not sure what needs to be done to fix it. I am not a drupal developer and hence maybe its a module which need to be installed etc

I am passing the below dataset (POST request)

POST URL: {HOST}/taxonomy_term.json
Data JSON:

{
"vid": "1",
"name": "My First Tag",
"vocabulary_machine_name": "keywords"
}

Response:

406 Not Acceptable: Missing bundle: machine_name

Ref: https://drupal.stackexchange.com/questions/120580/how-to-create-taxonomy...

I have tried many other combinations, but no success yet.

Hope someone can help.

Thanks

Comments

rohit_mel created an issue. See original summary.

dpp972’s picture

Hello,

I have excatly the same problem when i want to create taxomy term via RESTWS API (POST request).

Did you find any solution ?

Thanks

dpp972’s picture

Hi !

I found a solution. I simply disabled the bundle keys check from restws module resource creation process.

When a post request is sent and the restws api need to create a new resource (node or, in this case, taxonomy term), it uses the create() method from RestWSEntityResourceController class. This class is written in "restws.entity.inc" file inside the module directory.

I analyzed the code and it seems that, in order to the creation request succeed, both bundle keys and entity keys need to be set in the values array (corresponding to the request parameters set inside the POST request body).

But, in the case of taxonomy terms, bundle keys are not required to create the entity (there is only 1 bundle key for taxonomy terms : "machine_name". I think drupal need it for other purpose than creation...).

So, i added another condition for the bundle keys check process : entity type needs to be different from "taxonomy_term" ( see below)

The original code :

public function create(array $values) {
    // Make sure that bundle information is present on entities that have
    // bundles.
    $entity_info = entity_get_info($this->entityType);
    if (isset($entity_info['bundle keys'])) {
      foreach ($entity_info['bundle keys'] as $bundle_key) {
        if (!array_key_exists($bundle_key, $values)) {
          throw new RestWSException('Missing bundle: ' . $bundle_key, 406);
        }
      }
    }

    [...]
}

The new code :

public function create(array $values) {
    // Make sure that bundle information is present on entities that have
    // bundles.
    $entity_info = entity_get_info($this->entityType);
    if ($this->entityType != 'taxonomy_term' && isset($entity_info['bundle keys'])) {
      foreach ($entity_info['bundle keys'] as $bundle_key) {
        if (!array_key_exists($bundle_key, $values)) {
          throw new RestWSException('Missing bundle: ' . $bundle_key, 406);
        }
      }
    }

    [...]
}

As you can see, i just added "$this->entityType != 'taxonomy_term' &&" to the bundle check condition and it works properly now !

Hope it will help somebody !

Thanks.

avpaderno’s picture

Issue tags: -taxonomy_term
lokapujya’s picture

Status: Active » Closed (works as designed)

Solution suggested in comment #3