I'm currently rather new to PHP and working on a project for my job that will take information about leads when they are updated from the sharpspring API and put it into Insightly's API. Sharpsrings API has a function, subscribeToLeadUpdates, that takes a url as a parameter and says it will POST the list of leads to the url whenever it is updated but I am confused about how exactly this works and how I would work with that information. Each time it POSTs will it run the script for the url that I gave it? I subscribed a url of a droplet I set up to test it with a dummy script that should just create a file whenever it is ran, and then tried testing it by updating a lead but nothing happened. Also if I update a lead and then run the script manually with a var_dump($_POST) it just dumps an empty array. Any help is greatly appreciated
I ran their subscribe method and it returned
"{"result":{"success":true},"error":null,"id":""}"
That is correct, and means your request was accepted as valid.
There has to be some kind of activity with a lead that would trigger them trying to POST data to URL you sent...
Related
I am new to the term webhook, and i understand that it is a normal HTTP POST request, so when i send the data to an endpoint it utilizes this data and i can test this on a tool like (webhook.site), and what is noticeable on webhook.site it shows me directly the posted data on the real time. I need some help to know how this real time updates can be done using a custom webhook. If i created a PHP file that with will receive a posted data i don't know how to update the page upon request automatically.
I am a beginner and learning for example to submit a form to create an order (using POST method), edit an order (using PUT method), delete an order (using DELETE method) or search for an order (using GET method) targeting a restful web service. The order info is captured by the server script (probably PHP) and depending on the http method the order is either inserted, updated or deleted respectively. I have no knowledge of how the script does it.
My 2 questions are:
when I POST, PUT or DELETE, the server script could successfully perform the operation on the database (or) be unsuccessful in making changes to the database. How will I know if the script performed the database operation successfully or failed or there was some other error so that I can display a status to the user of the app accordingly?
(I understand that for a GET request the script sends the data requested in JSON or XML and I need to parse the JSON and display it to the app user. I just dont understand how it works for POST, PUT or DELETE. Will I receive a json for info or should I look somewhere else to able to provide a useful response to the app user).
I see POST being used instead of GET to get JSON response. My understanding is that POST is for insert operation only. Am I missing something? Why POST is being used in real time sometimes.
Thank you for your time in advance!
When the script finishes you send back a status code (200 is okay, 500-Internal server error, 404-Not found etc) and a message (json in your case)
"I see POST being used instead of GET to get JSON response", depends on what type of processing you are referring to. If you need a resource (a specific entity) you make a GET request, but if you need to make a custom process or a search then POST might be good for you
P.S: A good read on implementing a API an here. Check out the status codes used in the example, you can change your implementation based on your needs
My question maybe unheard of or may even be impractical.
But, I believe it is practical and acceptable.
Problem: PHP request and response in background thread.
Problem constraints:
You know it uses POST method.
It has two fields fname and lname as html ids that need to be filled.
You get response in the same page i.e. index.php .
Pseudocode to solve the problem:
Open the website in background. Something like openURL("xyz(dot)com");
Read the data sent in html format.
Change the value of the fields fname and lname to required fields "Allen" and "Walker."
Now, submit the fields back to the server. ( Page has a submit button.)
Note: PHP code has a standard if-else check to check for those values. If the field is properly set, it then says "Success" else "Failed"
Again, get the response sent by the server.
Check if "Success" was returned.
If "success" was returned, UPDATE UI thread for saying "JOB done".
Else, "Job failed."
Note: I am not talking about using a WebView. Everything happens via a service or AsyncTask.
Now, this is a simple question, and any ideas or a direction is acceptable.
So, to recap. You have to open a webpage in background, change its field, submit it back and then get the response.
I know we can open a website and get its content. But, I would also like to know if what I said is possible or not. And, I know it is possible. And, that I only lack the knowledge on Java Web API, could you please guide me on this.
Thank You. And, Have a Good day!
use this link for best solution of calling web service without using WebView.
In this example fname and lname sent in namevaluepairs we get responce in json formet and parse json and get data also json parse defined in examples.
What you are trying to achieve is to create a webservice call using a AsyncTask.
Like you have mentioned, you can make a post request within the AsyncTask, passing in the variables required for the request.
You can find a good example as shown: Sending HTTP Post Request with Android
I am confused what approach to take when updating a status e.g delivery on our client's system. On normal process, they provide us URL where we will post back the delivery data.
The problem now is what if we update the delivery data, then we'll have to notify our client's system too so the change of delivery status on their system happens real time instead of the cron job (check delivery status).
Should this be a
header('Location:http://path/to/client/parse_update_delivery_status.php');
once all the updating on our system is done or a
cURL.... //http post to client's url for updating delivery status on their system based on what we passed here
approach?
I'd really appreciate your input! :) Thanks!
I'm pretty certain that would have to be done with cURL, and at the very least would work much better using curl. Does parse_update_delivery_status.php receive data from an HTTP POST?
Using a location header causes the browser to redirect to that script, and no data gets passed along with it (unless you add it to the query string). If an update was performed, a person could potentially stop their browser from loading the redirect by hitting stop fast enough. Also, chances are that script won't output anything meaningful to the user so they would be left with a blank page or data on their screen that they don't understand and would have to use the back button to return to your site.
If the update was run from a cron job or PHP CLI script, then the headers have no meaning anyway.
This should be done as a cURL operation. The reason for this is your update scripts shouldn't be held responsible for handling browser operations like redirects; their job should just be to update whatever they need to update. By using cURL you can move all of your code which handles whatever status codes are returned by the update script into something which presents that data to the user, instead of intermingling that with your update script. By using this approach, you can keep your update script clean and allow it to be called by multiple sources without worrying about misleading redirects.
What is the best way of spitting out the view file in codeigniter and still doing some work on the server? The situation basically is:
I have a payPal checkout where user goes to paypal and clicks Pay Now! A set_express_checkout() is called to start things off.
The user is returned to the Thank You page.
I have to call a Get_express_checkout_details() and a do_checkout() before showing him the Thank you page and this is 2 calls to a pretty slow payPal server.
My problem is, that when the user clicks on Pay Now! button, he is redirected back to my site but hangs at payPal for at least 5 seconds (while my server makes the 2 requests) before he can se anything. So the question is: Where should I make these two calls so the user doesnt have to wait so long before anything is shown to them?
I think using AJAX request is justwhat youwant. The idea is the following:
Output your page to client not performing any paypal requests
Create additional page/method that only performs paypal request and outputs data as json
On the outputted page place AJAX call to that new page
Process the response to know, if the request was successful.
For ajax calls youmight want to have a look at jQuery.ajax. Most convenient way to output json data from PHP is using json_encode PHP function.
You could enable hooks and use the 'post_system' hook to make your two calls to the slow server. See http://codeigniter.com/user_guide/general/hooks.html for more information.
However this will leave you with no easy way of showing any result of the two calls.