Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the api support ntfy file attachments? #157

Closed
gorrilla10101 opened this issue Dec 24, 2023 · 10 comments
Closed

Does the api support ntfy file attachments? #157

gorrilla10101 opened this issue Dec 24, 2023 · 10 comments
Labels
question Further information is requested

Comments

@gorrilla10101
Copy link

Question

I looked through the documentation for ntfy on apprise and it appears that you are supposed to pass attach to get an image from a url. When calling the API, I can't seem to get it to work.

Here is an example curl

 curl 'https://{url_to_apprise_api}/notify/apprise' --header 'Content-Type: application/json' --data '{
    "tag": "testing",
    "title": "test",
    "body": "body",
    "attach": "{url_to_image}"

}'
@gorrilla10101 gorrilla10101 added the question Further information is requested label Dec 24, 2023
@caronc
Copy link
Owner

caronc commented Dec 24, 2023

Try this:

curl -X POST \
    -F 'urls=ntfy://details ' \
    -F 'body=test message' \
    -F attach=@Screenshot-1.png \
    http://localhost:8000/notify

If you've saved your configuration in the API, then:

curl -X POST \
    -F 'body=test message' \
    -F attach=@Screenshot-1.png \
    http://localhost:8000/notify/{key}/

@caronc
Copy link
Owner

caronc commented Jan 27, 2024

I haven't heard back in a while, so i'm closing off this ticket

@caronc caronc closed this as completed Jan 27, 2024
@flinthamm
Copy link

Hi @caronc and first off, thanks for building this brilliant project and the ongoing development.
In terms of this issue, is there any reason why you do not give an external url in your examples (as per @gorrilla10101), as this works correctly if you use the Ntfy API directly but not through your Apprise API? I've tried using "attach" as a post field and using a JSON string but the picture does not appear in the push message,
It also seems to ignore "Markdown" regardless of putting the Markdown field set to "yes" in either the header, as a field or in a JSON string.

@caronc
Copy link
Owner

caronc commented Feb 3, 2024

Hi @flinthamm,

The markdown feature i hadn't realized it even existed, so I plan to solve this one, no worries here.

As for the attachments not working from the testing API, I'll give it a look and keep you posted. I'll reopen this ticket.

@caronc caronc reopened this Feb 3, 2024
@caronc
Copy link
Owner

caronc commented Feb 3, 2024

@flinthamm I merged the markdown support into Apprise. It won't show into the Apprise API for a wee bit until i can get another release going. However there are instructions in the Dockerfile attached with this project you can uncomment and build against the latest Apprise branch if you need it sooner.

As per the second issue with Attachments:

  1. I took the latest version of the Apprise API off of docker and started it up. I attached an image using just the testing area of the API and uploaded it successfully (sending it off to ntfy:// as the end point):

    Prep
  2. Then i opened up Ntfy on my phone and there the image was delivered properly:

    Screenshot_20240203-134552

Can you share with me what you may be doing differently? I can't seem to reproduce your issue.

@GMNDS
Copy link

GMNDS commented Feb 13, 2024

Hi @caronc I recently discovered Apprise and it's an amazing tool, thanks for creating this. I'm trying the same problem using curl, to send an attachment.

The way shown above really works. However, the problem is when using curl with urls specifically (I haven't tried it with files, as I don't think I will need it)

Using this command does not work:

curl -X POST -F 'urls=ntfy://ntfy.mydomain.tld/test123' \
    -F 'title=test title' \
    -F 'body=test body' \
    -F attach=https://raw.githubusercontent.com/walkxcode/dashboard-icons/0eaf38572d4b8a2485228eb5da98d356ca47f653/svg/uptime-kuma.svg \
    "https://appr.mydomain.tld/notify/"

the result is:

image

Now if I use the cli with docker it works correctly:

docker container exec -it apprise-api apprise --body="Test Message" \
    apprises://appr.domain.tld/apprise/?tags=all \
    --attach=https://raw.githubusercontent.com/caronc/apprise/master/apprise/assets/themes/default/apprise-logo.png 

image

I also tried with json , the result is that the message still does not appear:

    curl -X POST -d '{"body":"Test message","title":"Test Title", "attach": "https://raw.githubusercontent.com/caronc/apprise/master/apprise/assets/themes/default/apprise-logo.png "}' \
    -H "Content-Type: application/json" \
    "https://appr.domain.tld/notify/apprise?tags=all"

image

@caronc
Copy link
Owner

caronc commented Feb 18, 2024

So upon investigating this more, i think the issue is the confusion around the word attach, you should be using attachment when just passing through the API.

However, when using curl's @ switch basically over-rides the -F variable assignment and identifies it as a file (and no longer becomes part of the payload itself.

# Using -F (it doesn't matter what it's called); this works:
curl -X POST \
    -F 'body=test message' \
    -F attach=@Screenshot-1.png \
    "https://appr.domain.tld/notify/apprise?tags=all"

# This does too:
curl -X POST \
    -F 'body=test message' \
    -F file=@Screenshot-1.png \
    "https://appr.domain.tld/notify/apprise?tags=all"

# and this does to; the thing is the @ with curl takes that variable and creates a new
# file/type section of the payload.  In the below, only `body` gets pass
curl -X POST \
    -F 'body=test message' \
    -F anything=@Screenshot-1.png \
    -F another=@Screenshot-2.png \
    "https://appr.domain.tld/notify/apprise?tags=all"

Now... when just passing using the API Payload, you must use attachment variable. Here is some of the examples you used (but fixed):

   # JSON Version
   curl -X POST -d '{"body":"Test message","title":"Test Title", "attachment": "https://raw.githubusercontent.com/caronc/apprise/master/apprise/assets/themes/default/apprise-logo.png "}' \
    -H "Content-Type: application/json" \
    "https://appr.domain.tld/notify/apprise?tags=all"

  # Form Version
curl -X POST \
    -F 'body=test message' \
    -F 'attachment=https://raw.githubusercontent.com/caronc/apprise/master/apprise/assets/themes/default/apprise-logo.png' \
    http://localhost:8000/notify/{key}/

Let me know if this helps 🚀

@caronc
Copy link
Owner

caronc commented Feb 18, 2024

I'm adding an attach keyword to just act as an alias of attachment; this will help with the confusion i think a bit.

Edit: use caronc/apprise:edge docker container to get the latest.

@GMNDS
Copy link

GMNDS commented Feb 20, 2024

Thanks for the example, I must have missed this information in the documentation.

It's working perfectly, thank you.

@caronc
Copy link
Owner

caronc commented Feb 20, 2024

Great, closing this ticket off as complete

@caronc caronc closed this as completed Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants