On Drupal 9.4 here and I want to create taxonomy terms via the api. Is there a good example of what I need to POST to an API end point?

1 Answer 1


Yes, make sure you have taxonomy REST services enabled at: /admin/config/services/rest

From there, you need to just POST to the following url: mydomain.com/taxonomy/term?_format=json

The format of the json you need the following only: (fyi, its in javascript for a nodejs file running in the cli.)

const postData = JSON.stringify({
  vid: [{ target_id: 'vocabulary_name', target_type: 'taxonomy_vocabulary' }], 
  name: [{ value: "some name here" }], 

Just pass that data into https request. Keep in mind to add in your user / pass authentication.

const options = {                                                                                                                                                                                  
  hostname: 'mydomain.com',                                                                                                                                                                    
  path: '/taxonomy/term?_format=json',                                                                                                                                                             
  method: 'POST',                                                                                                                                                                                  
  headers: {                                                                                                                                                                                         
    'Content-Type': 'application/json',                                                                                                                                                              
    'Authorization': 'Basic ' + Buffer.from('myuser:password').toString('base64'),                                                                                                              
    'Content-Length': Buffer.byteLength(postData),                                                                                                                                                 
  },                                                                                                                                                                                             };      

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.