Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Setting up a webpage to receive an HTTP Post

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Setting up a webpage to receive an HTTP Post

    We use Mandrill and want to use their Webhooks. Their webhook will send an HTTP Post to a web page when designated transactions occur (such as a bounce). Does anyone know how to set up a web page in Alpha to accept these HTTP posts?

    #2
    Re: Setting up a webpage to receive an HTTP Post

    I wanted to know the same thing but for a different purpose.

    Have you tried creating an a5w page and then point Mandrill at it? I wonder if the a5w page can read the body of the Post, just like it can read passed parameters?

    Comment


      #3
      Re: Setting up a webpage to receive an HTTP Post

      David is on the right track. The A5W page will see the POSTed data just like it sees query string parameters. You'll need to review the API documentation for the specific service to see exactly how they are sending the data. If the are sending name-value pairs in the body with either application/x-www-form-urlencoded or multipart/form-data format, the Application Server will create page variables for each. If they are sending in any other way (e.g. application/json), you can access the entire body as Request.Body and then handle it as needed.

      Lenny Forziati
      Vice President, Internet Products and Technical Services
      Alpha Software Corporation

      Comment


        #4
        Re: Setting up a webpage to receive an HTTP Post

        Thanks Lenny. I'll give it a try.

        Comment


          #5
          Re: Setting up a webpage to receive an HTTP Post

          Be sure to not include any HTML in your Post-listening page, just xbasic. My first four lines below will abort the page if not a POST transaction:

          IF request.body=="" .OR. upper(request.request_method)<>"POST" THEN
          ?"Sorry, you cannot run this page"
          end
          END IF
          '==your code to abort if NOT a Post from Mandrill
          cc = request.body
          '==your code to parse the response.
          '==your code to do something with the response
          Steve Wood
          See my profile on IADN

          Comment


            #6
            Re: Setting up a webpage to receive an HTTP Post

            Thanks Steve. Mandrill posts using JSON. Do you know what form the request.body returns. Is it a dot variable. I can't find anything on request.body either in the wiki or help menu.

            Comment


              #7
              Re: Setting up a webpage to receive an HTTP Post

              Thanks Steve.

              Comment


                #8
                Re: Setting up a webpage to receive an HTTP Post

                request.body contains exactly whatever text the page received. That's why you do not want any HTML on that page, it will "receive" that as well.

                So if the page is sent JSON, that's exactly what request.body will contain. Because it is JSON it is NOT going to contain any additional request variables, or at least not one-per-variable like Lenny was suggesting. That only works if the POST has named-pairs like &name=Steve.

                So you have to parse the JSON text. Search the documentation for "json" for some examples, its not something I have done much of at this point.
                Steve Wood
                See my profile on IADN

                Comment


                  #9
                  Re: Setting up a webpage to receive an HTTP Post

                  Jay - it's still just text. I've done this with a few different services. My starting point is to just capture the complete block of text and maybe save it to a file Save_To_File() to get an idea what you're dealing with. It also gives you a sample block of text to use to write any parsing code you want.

                  Mandrill should have some documentation about what they send, but I see examples out there too, such as this:

                  https://gist.github.com/ramonsmits/7563502
                  -Steve
                  sigpic

                  Comment


                    #10
                    Re: Setting up a webpage to receive an HTTP Post

                    Thanks guys. This gives me enough to get going.

                    Also, just found the A5 Function below. Seems to me that I can use this function, along with request.body, to populate an array of the messages that Mandrill will send and then step through the array to submit to my Sql table.

                    a5_JSON_PopulateArray()
                    Last edited by imjoken; 05-12-2014, 06:45 PM.

                    Comment


                      #11
                      Re: Setting up a webpage to receive an HTTP Post

                      A5_json_ExtractValues(), json_parse(), and extract_string() all possibly useful, in case you haven't found 'em. I do a fair amount of XML work and find the extract_string() to be darned convenient.
                      -Steve
                      sigpic

                      Comment


                        #12
                        Re: Setting up a webpage to receive an HTTP Post

                        So glad you asked this question Jay. I've been meaning to try this for a long time... just thinking about it...

                        So... here's the code in my a5w page... named... mandrilltest.a5w

                        Code:
                        <%A5
                        
                        	DIM cn as SQL::Connection
                        	dim flagResult as l 
                        	flagResult = cn.open("::Name::myConnection")
                        	if flagResult = .f. then 
                        		'dim errorMsg as c
                        		'errorMsg = "document.getElementById('errorMsg').innerHTML='Error: " + js_escape(cn.CallResult.text) + "';"
                        		'?"<script>" + errorMsg + "</script>"
                        		''ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text)
                        		end 
                        	end if
                        
                        	dim currData as c
                        	currData = mandrill_events
                        	'currData = "Testing"
                        
                        	'Specify if you are using Portable SQL syntax, or not
                        	'cn.PortableSQLEnabled = .t. 
                        
                        	dim args as SQL::Arguments
                        
                        	args.set("currData",currData)
                        	
                        	dim sqlStatement as c 
                        	sqlStatement = "INSERT INTO tblMandrillTest (TestData) VALUES (:currData)"
                        	flagResult = cn.Execute(sqlStatement,args)
                        
                        	if flagResult = .f. then 
                        		'dim errorMsg as c
                        		'errorMsg = "document.getElementById('errorMsg').innerHTML='Error: " + js_escape(cn.CallResult.text) + "';"
                        		'?"<script>" + errorMsg + "</script>"
                        		''ui_msg_box("Error",cn.CallResult.text)
                        		'cn.close()
                        		'end 
                        	end if 
                        
                        	cn.close()
                        
                        %>
                        My Mandrill Webhook looks like this...

                        Code:
                        http://www.mywebsite.com/mandrilltest.a5w
                        That's it. It actually works. 'Cause this stuff is pure voodoo... it's great.

                        You'll see for currData above I put in a static value at first... just to test the page. I just wanted to write a value to a table. So... do that and just run your page from a browser and check your table. If the static value is there your code is good.

                        Next, Mandrill sends off it's HTTP Post JSON in 1 Parameter named mandrill_events.

                        The JSON looks like this...

                        Code:
                        [
                           {
                              "event":"send",
                              "_id":"123b50e7219d476f123351f628a76123",
                              "msg":{
                                 "ts":1231231231,
                                 "subject":"Test",
                                 "email":"[email protected]",
                                 "tags":[
                        
                                 ],
                                 "opens":[
                        
                                 ],
                                 "clicks":[
                        
                                 ],
                                 "state":"sent",
                                 "smtp_events":[
                        
                                 ],
                                 "subaccount":null,
                                 "resends":[
                        
                                 ],
                                 "reject":null,
                                 "_id":"123b50e7219d476f123351f628a76123"",
                                 "sender":"[email protected]",
                                 "template":null
                              },
                              "ts":1231231231
                           }
                        ]
                        You can do something like this...

                        Code:
                        dim mandrillInfo as p
                        mandrillInfo = json_parse(currData)
                        And that will shove the JSON into a dot variable and then the world is yours.

                        This is very cool stuff.

                        No idea how you'd error check the XBasic for connections etc. But Mandrill has stuff in place in case the webhook fails... so... cool.
                        Last edited by Davidk; 05-12-2014, 09:23 PM.

                        Comment


                          #13
                          Re: Setting up a webpage to receive an HTTP Post

                          David, one minor tweak you may want to consider... Instead of exiting without doing anything if you cannot open the database connection, you may want to instead save Request.Body away as a text file in a known location. You can then process those files later in the event of a database issue instead of losing the information that was POSTed to your page.
                          Last edited by Lenny Forziati; 05-13-2014, 01:54 PM.

                          Lenny Forziati
                          Vice President, Internet Products and Technical Services
                          Alpha Software Corporation

                          Comment


                            #14
                            Re: Setting up a webpage to receive an HTTP Post

                            Thanks Lenny... yes... I was trying to think of something to do if it everything fell down. That would work nicely.

                            Comment


                              #15
                              Re: Setting up a webpage to receive an HTTP Post

                              Ah, thinking about "Disconnected" possibilities are we?
                              -Steve
                              sigpic

                              Comment

                              Working...
                              X