imagehttpxmlhttprequestbase64messagebird

Uploading a file to Message Bird API


Currently, I'm trying to integrate the message bird API into my automated app (https://developers.messagebird.com/).

I'm trying to upload files using the message bird API, as the documentation says I'm using this endpoint: https://messaging.messagebird.com/v1/files that returns me the id of the file that I uploaded, the problem is that when I try to join that ID with the endpoint to get the file (https://messaging.messagebird.com/v1/files/:id-of-the-file) and use that URL into the content of the message that I want to send (

content: {
   image:{
    url:"https://messaging.messagebird.com/v1/files/:id-of-the-file"
  }
}

), the message is not delivered and the webhook returns me a state of failed (that is the message wasn't delivered to the channel), I guess that it is because in order to get the file I need to authenticate myself but there is no way that I can authenticate myself just by sending the URL. Also, I've tried sending the URL as the base64 of the image but it didn't work either, I don't know if I'm doing it wrong or that is not the endpoint that I must use or what. If you could help me with that I would be really grateful :)

PD: When I make the request with postman sending the AccessKey in the headers it does return me the image


Solution

  • You should be uploading images to the messaging API endpoint only if you want to include them in email message. Once they have uploaded you can use the id's returned in either the inlineImage field, or the attachments field, as seen in this json example.

    If you are trying to send the image via another platform (ie whatsapp, telegram), you should be able to include the your image url as part of the request, like the example below.

    Not sure what endpoint you are using to send the message over, but this json is valid for the conversations /conversations/send endpoint. You can also use the same structure for the content field on these endpoints too (/conversations/start or /conversations/{id}/messages).

    { 
       "to":"+11111111",
       "channelId":"mychannelid",
       "type":"image",
       "content":{ 
          "image":{
            "url":"https://example.com/an_image.png"
          }
       }
    }
    

    Hopefully this resolves your issue! If it doesn't, can you provide a bit more information around what platform, and what endpoint you are using.

    Thanks

    Jen