Image Upload Code Sample - JavaScript with Superagent

Image Upload Code Sample - JavaScript with Superagent

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

const request = require('superagent')

request
  .post(
    'https://{domain_prefix}.vendhq.com/api/2.0/products/{product_id}/actions/image_upload'
  )
  .set('Authorization', 'Bearer {vend_token}')
  .set('Content-Type', 'multiprt/form-data')
  .attach('image', '{file_path}')
  .end(function (err, res) {
    if (err) {
      console.log(err)
    } else {
      console.log(res.body)
    }
  })

Did this page help you?