How do I debug a webhook POST? - php

A webhook is sending me a POST, and I want to do some debugging on it. Currently I'm looping over the array and then sending a mail() to myself instead of printing (because how could I see what's printed to the page?), but I'm betting there's a more efficient way.
Any suggestions?

https://requestbin.com/ lets you create a temporary URL that will show you all the HTTP request data sent to it.

There are multiple options for debugging:
Use a debugger with an IDE, like netbeans. This will run the application and figure out where things are going wrong.
Use logfiles of your server, or generated by application exceptions
Collect your debug information with a buffer and put it in a file in your public directory. Overwrite with every new request.

I know this is quite an old question but if you want to see what kind of responses you are going to get from webhooks or you need to need to access the developer environment then there are a selection of tools that can help you.
RequestBin is probably one of the simplest to use by, providing a unique URL that you can then set this as your endpoint for Event notifications. Using this URL you can check to see what responses you are receiving.
You can generate a unique URL by creating a RequestBin.
An Example URL is this:
http://requestb.in/XXXXXXXX
This will be used to receive Event Notification Data and Receive Inbound Parse Data.
The results will then be found by heading to your RequestBin unique URL.
Ngork is also a tool that is useful for creating a local tunnel to your machine. This makes testing webhooks locally easy.
To setup install and enter the following in your CLI (after signing up first):
$ ngork 3000
This would open a connection to the port 3000 that is on your local machine, then at a URL you can put your URL for your PARSE Webhook or Event Webhook.
$ ngrok -subdomain=myappname 3000
Runscope is a tool for debugging APIs. It acts as a proxy, collecting all data sent to it and passes it on to another point. You may then, later, review what was sent to the API you’re debugging.
Source : https://sendgrid.com/docs/API_Reference/Webhooks/debug.html

http://httpresponder.com/ works also, and lets you configure a canned response if you need one.

You can use https://www.reliablewebhook.com/. They also have a plugin for Visual Studio Code for local debugging.

Related

Testing if a POST api endpoint is working with PHP

I have a ticketing system and I just enabled an API endpoint that points to a custom PHP file I created. Everytime I update a ticket it sends the data to this endpoint saying its updated. How do I test if it actually is sending any data? Supposedly its doing a POST to that php file. I was thinking of sending this POST data to a a plain text file in the same folder to test.
But is there a better way to do this to test what that end point is sending?
Did you try checking the network tab in chrome dev tools. There you can look up under "doc" or "XHR" which post headers have been sent.
You need to log your inputs, outputs, or anything you want. There is a good log library you can use that name is Monolog but you can use the buffer or write in output using var_dump or write directly in a log file.
Also, you can use the XDebug to debug your codes

How do I add a webhook to my local magento website in mailchimp without exposing the URL publicly (for SEO reasons)?

I am using the magemonkey extension from Ebizmart and when i save my config in the admin i get the following error:
Could not add Webhook "http://example.com/monkey/webhook/index/wkey//" for list "Test Mailing List", error code 508, We couldn't connect to the specified the URL. Please double check and try again.
I did some digging and arrived at the conclusion (duh) that mailchimp cannot see my local environment so it's unable to add the webhook. Is it possible for me to configure this locally for testing purposes or do I have to wait until the site is live (sounds pretty strange to me)?
UPDATE: I reached out to Mailchimp and got the following response. Seems like they won't add a host entry to recognize my test environment. The only way to accomplish this would be to use a handshake key.
Thanks for reaching out to MailChimp support. I can certainly understand the concern here and will be happy to help.
Unfortunately, any webhooks being used must be publically available and there would not be a way to add a host entry in MailChimp so that the URL can be used.
If your testing environement allows for HandShake keys, one options might be to add that on to the url: (can't add more than 2 links)
At MailChimp we definitely appreciate testing and encourage it with our users and I will be sure to pass this feedback along to our developers so that testing in closed environments might be a bit easier. I also wanted to provide a link to our feedback form in case you wanted to leave some feedback for our developers directly: (can't add more than 2 links)
If you have any additional questions or concerns, feel free to reach back out and we will be happy to help.
Thank you,
Mikey
Use https://ngrok.com/, available for all platforms.
It allows you to tunnel requests to your local dev machine. It's very easy to use, just download and run:
ngrok http 80
Then it'll show you the forwarding URL (where xxx is randomly generated):
Forwarding https://xxxxxxxx.ngrok.io -> localhost:80
Use https://xxxxxxxx.ngrok.io as the begining of your webhook callback URL.
Once it's running, a web interface is available at http://127.0.0.1:4040 that shows metrics and let's you replay requests.

DocuSign Connect XML Export Using Custom Listener

I'm new to both DocuSign and the Rest API. I'm attempting to familiarize myself with how DocuSign connects and downloads using a custom listener (in PHP) with the API Walkthrough located at http://iodocs.docusign.com/APIWalkthrough/getEnvelopeDocuments. I see that it downloads the PDF and the Certificate, but not the XML. I did a var_dump on the $data in the curl_exec and saw that it was all returned in a string with the XML present. My question is what's the best way to extract the XML data and why doesn't it download the XML file also? I apologize for any ignorance on my part. Thanks for any help and/or direction.
EDIT: My assumption is that it's returning a combined PDF, instead separate files (which is what we want). Is the index "envelopeDocuments" set in the RequestPDF function? In the API code I can't find this.
The REST API Walkthrough that you have referenced is not related to DocuSign Connect at all. In the DocuSign platform there are two ways to get information about your envelopes - you can pull envelope data every so often, or you can have the envelope data pushed to you as they are completed, declined, etc. The walkthrough that you've referenced is the first method (i.e. it shows how to pull envelope data when you want). DocuSign Connect works in the reverse in that, based on how you configure it, it sends you data as events happen.
For starters, to configure Connect settings login to your account at demo.docusign.net, click your profile icon in the top right, and go to
Preferences -> Connect
On that page you will be able to select on of your Connect configurations (or create one if needed) and then configure for which users you want data pushed, on what events, and other settings.
In terms of setting up your listener, you can use any language that can successfully listen for http events (so your choice of PHP should be fine) but there's just a couple of things you'll need to ensure. For starters, you need to make sure you are listening or the proper port. In the DEMO system you can test on http (port 80) or https (port 443), but please note that in production (www.docusign.net) only https is allowed. Also note that you will not be able to test using a localhost URL. You need a real URL that can be reached from the outside world.
Your best bet for info and getting started is the page from the DocuSign Dev Center which describes Connect and links to it's guide. Please see here for more info:
http://www.docusign.com/developer-center/explore/connect

The 'easiest' method to get MySQL on localhost in my Android Application

I've successfully managed to use POST to run a PHP script on my website, which allows the phone application to add a new entry to the database (MySQL), and delete an entry.
The next step is the one I have been struggling with for the last few hours now, and that is getting the information FROM the DB onto the phone!
I would like a method that initially just connects to the DB upon starting the activity and populating listview or something will all entries, and later down the line I plan on copying the information to a SQLite DB within the phone.
What is the easiest method I can look into for achieving this?
I can be resourceful but I just need to know what I'm looking for!
you have many options.
higher level abstraction over HTTP (REST/SOAP/etc) like already mentioned
HTTP as a proxy for plaintext/CSV data (without abstraction)
a direct JDBC connection from android device to the MySQL
database data export/import
I guess you're looking for option 3. That is syncing a remote database to local (SQlite on android) and then working with local data? In this case you just get a mysql-client jar (JDBC drivers) into your app and you can start. There're some restrictions though, like Sébastien Renauld already mentioned in the comment. Yet, those issues can be worked around, i.e. with custom configuration of MySQL or with option (2) which can be implemented in generic way (write once)
In general you need to create server API: choose some format to talk to between your web service and android application.
Then you'll always be need to request some data from server, that will be returned to you in format described above in a body of network response of some sort.
Next all you need is parse this data and populate to your adapters or whatever.
Note that networking operation might take quite some time depending on your connection, so you can't wait while it ends to show your UI - you need to do this in async manner, and give user a feedback that data is retrieving.
Nowadays json format passed in body of http post requests are quite popular. Take a look at this tutorial on how to parse json on android and this video about how to create json api in php.
Of course you can try to connect to remote MySQL server directly.. It really is more simple solution in some cases (you don't need to code server-side api), but might be not so accessible because standard MySQL ports aren't opened in all networks. Also your API server might hide some implementation details on how is data stored in reality, thus allowing you to migrate for example from MySQL to PostgreSQL without pain for android application.
Don't forget to secure your data from unauthorized access!
EDIT
It's 2017 and what would be the easiest option now is to use opensource project which will provide rest api for your database, for instance ArrestDB or postgrest
I personaly had to develop this following REST API Service (based on Laravel framework, which I call it lRapi) for an iOS and Android devices, and works great (the version in use for the apps, is much more complex).
https://github.com/w0rldart/lRapi
There are plenty Models and Controllers there that you may use to get started. Responses are JSON formatted, with proper headers.
I still have to add some more documentation to it, but there is some on the main example view, which you may access by just setting the virtual host and opening the root page in browser.
Laravel is a MVC PHP Framework, and it's really easy to get used to it.
This a good way to avoid to do most of the work, and just focus on implementing what else you need.

Querying A Server And Receiving XML Responses In PHP

I'm trying to write an API for a website, whose Flash app gets data from a server and presents it to the user. I've been told that I can "have a look web trafic you will the responses from the server are all just basic xml".
This might be the wrong question to ask but, I'm not entirely sure what I've been told to do here. Can I simply use PHP to open the page with the Flash app on, and intercept the XML responses being sent to it? How might that happen?
Alternatively, am I coming at this the wrong way? Do I need to instead know what server the Flash app is accessing, and then open up a connection to that?
This feels like a bad SO question, but I'm at a complete loss. The advice I was given was quite vague so I don't know where to look.
To see the server response in the web traffic, just use the "Net" tab of the firebug plugin of firefox.
It should display the request of the flash app with the response from the server which should be in XML.
EDIT
You will also know with firebug from which URL the response is coming from and you can then mimic the request of the flash app with your own php script.

Categories