Upload image on Zendesk using API

Hi!

I’m trying to upload image on Zendesk using API, but I’m facing some problems.

My request is successfull, but when I access to the image I just upload, the file seems corrupted or unreadable.

Here is my code :
First I’m creating a buffer and encode image in base64.

Then I send it into the API

Also, I have made some test with Postman, and that works well! So I think the problem comes when I encode the file.

Here is the Zendesk documentation about it : Attachments | Zendesk Developer Docs

Hi @victor_hypnia,

I’m sorry to hear you’re having trouble uploading images to Zendesk. Based on the code you provided, it seems like the issue might be related to the encoding of the image file. To help you with this, I’ll provide a Pipedream component that uploads an image to Zendesk using their API:

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    zendesk: {
      type: "app",
      app: "zendesk",
    },
    imageBuffer: {
      type: "string",
      label: "Image Buffer (Base64 encoded)",
    },
  },
  async run({ steps, $ }) {
    const base64Image = this.imageBuffer;
    const imageData = Buffer.from(base64Image, "base64");

    const response = await axios($, {
      method: "POST",
      url: `https://${this.zendesk.$auth.subdomain}.zendesk.com/api/v2/uploads.json?filename=image.png`,
      headers: {
        Authorization: `Bearer ${this.zendesk.$auth.oauth_access_token}`,
        "Content-Type": "application/binary",
      },
      data: imageData,
    });

    return response;
  },
});

This component accepts a base64 encoded image as input and uploads it to Zendesk using their API. Make sure to replace imageBuffer with your base64 encoded image data.

Please give this a try and let me know if it resolves your issue. If you still face any problems, feel free to reach out for further assistance.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.