2 Replies Latest reply on Apr 9, 2016 10:10 AM by SaraB

    Bind variables not set

    SaraB

      Hi

       

      I have a POST RESTful API which I've created through APEX. We're using this as a webhook for receiving emails from a 3rd party, so have no control over the post.

       

      When I output the bind variables that should be set, some are and some aren't populated. The 3rd party is posting multipart/form-data and I've used request.bin to get details of what is being posted (:body was empty in the API).

       

      It seems that when there is an attachment only those variables that are before the attachment are set. Here's a very simplified example:

      --xYzZY
      Content-Disposition: form-data; name="to"
      
      
      another@example.com
      --xYzZY
      Content-Disposition: form-data; name="from"
      
      
      my.name@example.com
      --xYzZY
      Content-Disposition: form-data; name="attachment1"; filename="example.txt"
      Content-Type: text/plain
      
      
      This is a test text file, for example only.
      --xYzZY
      Content-Disposition: form-data; name="subject"
      
      
      The message subject
      --xYzZY
      Content-Disposition: form-data; name="attachments"
      
      
      {"attachment1":{"filename":"example.txt","type":"application/octet-stream"}}
      --xYzZY--
      

       

      With this example the vaiables :to and :from have values. But the variables :subject and :attachments are null.

       

      Any ideas why those after the attachment wouldn't have a value? Or why :body would also be empty?

       

      Many thanks for your time,

      Sara

        • 1. Re: Bind variables not set
          Kris Rice-Oracle

          Hi,

          This would be a curl example of POSTing form data to ORDS.  Seems there's 2 things going on.  1) we don't deal with multipart file uploads and 2) when form data is sent there is no :body since it's parsed apart.

           

          What is the service you are using?  I see a webhooks git hub project but guessing that's not it.

          • 2. Re: Bind variables not set
            SaraB

            Hi Kris

             

            We've used webhooks from a number of different 3rd parties for different functionality. It's unfortunate that no two places seem to do it the same, it's a bit like HTTP requests being x-www-form-urlencoded, JSON, XML etc. But this is the first one that's really caused us problems.

             

            Anyway, the one that is causing us problems is SendGrid Incoming Mail (https://sendgrid.com/docs/API_Reference/Webhooks/parse.html). We use SendGrid to send mail and they can also handle incoming mail, but don't have a mailbox. Instead they have a webhook where the incoming mail is forwarded to the webhook. I don't know whether knowing this will provide much help as to test it out you need a SendGrid account and a mail domian pointed at the SendGrid server.

             

            However, you should be able to reproduce the problem using Postman by sending a number of items with a couple of files in the middle.

             

            I've also tried to create my own procedure to handle this, but this hit problems immediately as the procedure parameters need to be named the same as the form items. I could easily pass the subject to my procedure, but there is no way of getting to and from as I would need to have parameters in my procedure called this.

             

            BTW - I've worked around this problem by using a node.js server, which reads the post information and builds a JSON object which is then passed to a RESTful API. I know that the JSON object is built correctly (as we build it), so there is no problem getting the information in the API. It's just unfortunate that I've had to go outside of Oracle to handle this.

             

            Also, I did hit another problem in that one of the form parameters was attachment-info, which you can't pick up in Oracle due to the hyphen (you get a nasty error). When I build the JSON object I replace hyphens with underscores to avoid the issue.

             

            Thanks for your help.

             

            Kind regards

            Sara