Image Upload Code Sample - JavaScript with Request

Image Upload Sample Code - JavaScript with Request

The code below is using the request library to simplify handling of the HTTP request.

const fs = require('fs')
const request = require('request')

var url =
  'https://{domain_prefix.vendhq.com/api/2.0/products/{product_id}/actions/image_upload'

var options = {
  method: 'POST',
  uri: url,
  formData: {
    image: fs.createReadStream('{file_path}')
  },
  headers: {
    Authorization: 'Bearer {token}',
    'Content-Type': 'multipart/form-data'
  }
}

request.post(options, function optionalCallback (err, response, body) {
  if (err) {
    console.log(err)
  } else {
    console.log(body)
  }
})

Did this page help you?