Listing Msg_type in http request with binary

Hello, I am using Lark for my company messaging and lark is able to receive image using webhook.
however, it require incoming webhook to define msg_type.

may i know how do i define it using http request note.

Hi @Benjamin123, I hope you’re having a good day?

I have not used Lark before, but it from the screenshot you are sharing it seems like they are expecting a JSON request body. So something like this should work (you can just copy and paste the below JSON code into your workflow):

This would result in the documented body:
image

Hope this helps :smiley: Let me know if you have any further queries on this!

hello mutedJam,

thank you for your guide… actually i was trying to send the gmail attachment ( jpeg ) through http request node.

I tried sending binary data and i am unable to find my binary too.

According to the picture you attached, image_key is the ID of an image previously uploaded to Lark. That means that you cannot reference the image from Gmail. You need to upload the Gmail attachment to Lark and then reference that ID that Larks returns when sending a message. There might be another endpoint that lets you send a message using binary data, but could not check the docs since they are in Chinese, and for some reason, my browser does not translate it.

Hello Ricardo,

After reading your comment, and I re read the documents from Lark again. I think i am beginning to understand the document a bit better… :grinning:

1 Like

Hello ,

With Ricardo guide, i am able to get the image key using postman to try out.

However, I face another challenges with the HTTP Request Node. I wasn’t able to find the bearer token in authentication for http request node

secondly, i need to enter 2 value in body.

May i know what should i do ?

You have to use the header authentication. And then you set it up like the image below:

Sadly the HTTP node has a limitation when using multipart-formdata. You can either send binary data or key-value pairs, which is what you need to do. We are well aware of this limitation and will address it in the next version of the node. In the meantime you can do is to do the request from a function node. The function node should be similar to the one below.

const request = require('request-promise-native');

const binaryData = items[0].binary.data;

const metadata = {
  name: binaryData.fileName,
  parent: { id: 123 }
}

const options = {
  uri: 'https://internal.users.n8n.cloud/webhook-test/2/webhook/webhook',
  headers: {
    'content-type': 'multipart/form-data',
  },
  formData: {
    file: {
      value: Buffer.from(binaryData.data, 'base64'),
      options: {
	    filename: binaryData.fileName,
	    contentType: binaryData.mimeType,
	  },
 	},
    attributes: JSON.stringify(metadata),
  },
  method: 'POST',
}

await request(options);

return [{ json: {} }]

I managed to get the file send to Lark using postman… :grinning_face_with_smiling_eyes:

now lets try using n8n…

but i see, using function node has a lot of code and i am not good in code…

am i suppose to change anything that suite my senario?

You have two options. Either you create a node for Lark or use the request library directly in the function node.

Hello Ricardo,

I only has very basic in coding…may i ask if i have to change the following only?

actually i wasn’t very clear. do you mean i will be using function node to upload the file to lark directly instead of using the http request node.

Hello @RicardoE105 , i am trying to upload file using function node using the guide that you have provided.
Below is photo of uploading using postman.

in function node, I have make changes as shown in photo below.

below is the http node before function node to get jpeg file.

However, when i run the function node, I get the feedback “Entries exist but they do not contain any JSON data.”

May i know if there is anything i have set up wrongly?

In the formData object, you need to rename file to image, remove attributes, and add a property called image_type with the value “message”

Hello @RicardoE105 I made some modification, i guess i am still wrong…

I am still getting the error as following

Image_type it’s under the image property, and it should be under the formData property. And you need to delete the attributes property.

Hello @RicardoE105
below is requirement to upload file to lark .

I have make some changes to function node as following.

and tried out with webhook.site to check out the post message. and it seems to me that all required data are there.

if everything is done correctly, i should be returned with a response body as following

When i try out the workflow, however, I am returned with empty json instead.

You get empty because you are returning empty.

The last two lines:

await request(options)

return [{ json: {} }]

Change them to:

const response = await request(options);

return [{ json: response }]
1 Like

@RicardoE105 thank you very much for your help… it is working now…