onesignal

add image to push notification in oneSignal via rest api


What is the key for adding image on push notification to IOS? I tried imageUrl, but does not seem to work. I used the UI from their website, and that worked.

{
      app_id: process.env.ONE_SIGNAL_ID,
      include_external_user_ids: d.emails,
      headings: { en: d.headings },
      subtitle: { en: d.subtitle },
      contents: { en: d.contents },
      app_url: "https://google.com",
      web_url: "https://google.com",
      ios_badgeType: "Increase",
      image_url:
        "https://cdn.pixabay.com/photo/2018/01/21/01/46/architecture-3095716_960_720.jpg"
    },

Solution

  • After some ) time here (two or three hours spent), I figure out what you should do. Basically, to add the image on the notification, you should add the ios_attachments, as the documentation mention

    ios_attachments : {"id": <link to your image>}

    However, if the link does not end with a valid image extension (i.e. jpg, png, and, etc), you should add ?filetype=file.jpg at the end of the URL.

    Thus, your final payload should be:

    ios_attachments : {"id": <link to your image>?filetype=file.jpg}

    For more information see this troubleshooting post