Create a post with image in Ghost

Hi there,

What’s the HTML content I must use to create a post in Ghost with an image?

Also, can I embed markdown syntax in the content of the node?

Any help is appreciated.

Thank you.

Hey @ronykris!

The node supports the format that Ghost supports - HTML and Mobile Doc. Since the Ghost API doesn’t support Markdown you can parse markdown syntax directly. If your incoming data is in Markdown, you can use a Markdown converter API or something similar to convert the content to HTML and then create a post.

Never mind about the markdown. How do I upload an image?

I am afraid that functionality is not available in the node at the movement. You can however use the HTTP Request node to upload an image.

thats a great suggestion. Can you please point me to a sample workflow to see how an image could be uploaded via HTTP Request node?

I don’t have a complete workflow, but here’s the HTTP Request node that you can use.

You will have to configure your credentials and the URL.

{
  "nodes": [
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "jsonParameters": true,
        "options": {
          "bodyContentType": "multipart-form-data"
        },
        "sendBinaryData": true
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1260,
        300
      ],
      "credentials": {
        "httpHeaderAuth": "Ghost"
      }
    }
  ],
  "connections": {}
}

Thank you. Where do I assign the file for upload?

You need to use the name of the property that holds the binary data (the image). Where is the image coming from? Are you downloading using the HTTP node?

I will be downloading the image to my filesystem using a shell node that executes a curl command. Eventually I plan to upload it to ghost.

Sorry, I did not understand how to use the name of the property that holds image data. Can you point me to an example please?

I will be downloading the image to my filesystem using a shell node that executes a curl command. Eventually I plan to upload it to ghost.

Why is the curl command needed when you can use the HTTP node to download the image?

Sorry, I did not understand how to use the name of the property that holds image data. Can you point me to an example please?

That is just the way binary data (images, files, etc) works in n8n. If you use HTTP for instance and download an image, that image is going to be download to a property (usually called data). You are going to use this property to reference the image in any node that supports uploading data.

Let me know if something it’s still not clear.

wrt the curl command; no special reason, but I have a working shell node that does it.

So, are you recommending that I use HTTP request node for the download as well?

Yes, that would make things (in my opinion) simpler.

@RicardoE105
So, as recommended, I created a HTTP Req node to Get a file (image) from my private Github repo, created the appropriate credentials with github access token and chose Header based authentication in the HTTP Request node.

But the node execution always fails with a 403.

Below is the cause of the error:

Any idea, why the requests are not going through? I have ensured I have the correct Github API tokens in the credential section of the workflow. The request goes through via curl though.

If you receive 403 then the problem is related to the credentials. If you are 100% sure that they are correct, then you maybe send them wrong. I would check again the documentation.

@jan
I am sure you are right. But I’m not able to figure out what am I incorrectly sending.

So, like I explained before, I am trying to Get a file (image) from my git repo using a http request node.

I have tried the following types of authentication:

  1. Basic Auth
    User: my github user
    Password: my personal access token

  2. Header Auth
    Name: Authorization
    Value: token xxxxxxxxxxxxxxxxxxx
    I have also tried the following combination in Header based auth
    Name: token
    Value: tokenstring

None of the above seemed to get me through. What is it that I am doing wrong?

Hey @ronykris!

Are you using the GitHub API to fetch the file? You won’t be able to get the file directly via the file’s URL since it is a private file.

Also, did you try using the GitHub node? You will be able to get your file via the node.

Hi @harshil1712
Yes, I had initially attempted the github node, but it doesn’t have an operation listed to Get a file from the repo. Pasted below is a screen shot of the options.

The Get Operation will allow you to get the file. There seems to be a typo in the description of the operation.

Hey @harshil1712 ,
Thank you! that was easy :slight_smile:

Now going back to my original intent of creating a post with the image I retrieved from github in ghost; it appears that if I use a HTTP Request node i’d also have to create the jwt token manually and pass to the api call, is that the right understanding?

I was referring the token creation example mentioned in Ghost documentation here (Ghost Admin API Documentation).

Hey @ronykris!

That’s a tricky part with the Ghost API. I followed their instructions and created the JWT token via CLI and used it in the HTTP Request node. I am not sure if there is a way to that directly in n8n.