Getting xml data and writing to db from external source - php

I have spent the past three days researching this... but Im still stuck.
I have a service provider that offers me a REST api. I need to:
Get the data from his api
Assign the data to variables in php
Write the data to my localhost sql database.
All that's required is the API KEY which has been provided to me.
Please could someone explain to me what method I should use to call and store the data in php.
Writing to the Database and handling the data once in php format is not a problem.
Thanks in advance

Since you want to consume a webservice you would have to make HTTP request using PHP.
There is many ways to do that but the most used(IMHO) is cURL. cURL function would allow you to easily make HTTP request and consume data from the webservice.

Related

Safely connecting to Cloudant using AngularJS (and possibly PHP)

I built a very simple AngularJS Shop App that creates product orders.
As of now, the app just sends orders via email to the customer and retailer using PHP, but I thought it might be good to learn a bit how to use databases, and store/retrieve this orders (which are arrays) into a Cloudant.
But then I realized that to connect to the Cloudant service, the call looks like this:
https://{username}:{password}#username.cloudant.com/DB
I assume this is not very safe at all, as the call and credentials would be visible for anyone.
Also, in the App there's no need at all for anyone to have an account or login, which would partially help with security.
As I have 0 experience with Node or any other backend system, I'm wondering: Is it possible to make secure calls to a Cloudant service using only AngularJS (or PHP to store the sensitive values)?
I've read a bit about the one db per user, but it doesn't seem to help in my case, where I need one single DB to store all my orders.
Any tips would be highly appreciated.
If you need to expose your credentials in your API calls, you better not do them from the front-end. If you're using Angular and PHP, the easiest way to hide your auth info from the public would be the following:
Create a PHP file and move your API code to the back-end.
This will be a bit of work, but in the end the service login should happen on the server. This file should receive requests from the client and transmit them to the remote service, then return its response to the client.
Use AJAX on the front-end to make calls to the above PHP file, and proceed displaying its response to the user like you would handle an API response.
This way your API credentials aren't exposed to anyone checking your page's HTML source and you can keep most of your front-end logic the way you have it set up already.
As #ppajer said, I strongly discourage to use AngularJS to do what you want to do. Leave it on the back-end and use ajax to make the calls. Take a look at this repo, it may help you: https://github.com/osipov/bluemix-cloudant-php-sample

how to query multiple endpoints with curl on sdata web serivce

I am trying make a request query to Sage sdata web service to the following endpoints tradingActivites and receipts as nothing is obvious on these docs
I have this so far localhost:5493/sdata/accounts50/GCRM/-/tradingActivities?where=accountReference eq "1200" &format=json that gives me all the transactions of this account but I also need the information from receipts endpoint as well.
Is it better to do two curl requests or what would be the correct syntax for querying this type of web service in the URL.
Thank you for reading this any help would be appreciated.
You would need to do two curl requests to get the data you need and then do whatever matching of data you need in PHP.
This is based off the information I have unless you can look through the docs and get a method that provides all the data you need.

Rest API feed access options

There is a REST API which I want to access and use the GET Method to get the data from xml and store it into MySQL. I thought to give PHP curl a try to request the data from API and setup a cronjob for the script run automatically on the given days. The problem is that the feed is not allowed to be accessed through browser. What other ways are there to get the data and store into mysql?
I used httpful client by nate good to solve this issue. Hope it helps other as well.

Accesing php web service and MySQL from Qt/C++ in android. How to send data to service?

I am pretty new with this. I am trying to develop some android application in Qt/Qml to query and update data to a database.
The problem I'm trying to solve:
There is a server with a MySQL database. The android application request some data. I use a very very basic php file that query in the database, format an XML and show that file starting with a header('Content-type: text/xml'); sentence, then some echo "<...>" sentences. This php file receives parameters via $_GET array and performs the query.
This is a little archaic but works fine. My client application use Qt/QML for android. It uses XmlListModel to obtain the data from the server and show that data in a ListView.
So far so good, but here is my real problem:
The user of the android application can change some data, and the modified data must be sent back to the server, who performs an update in the database.
My first attempt was to create another php file and send the data in the URI, get it via $_GET and perform the update to the database. This works but there could be many variables and the URI will become very large. I think might be better to send an XML (or JSON) from the client to the server, and put in that file the data for the update.
So, this is the question: How can I send an XML file from Qt/QML to the server? How does the php file obtain that data? Or maybe there is another, better way for doing this.
Every example I find just shows the server-to-client part, or is written in Java, and I don't know java enough.
Additional notes:
After I can solve this I will fight with security: SSL, avoiding SQL injection or anything, but that will be in another question if necessary.
I didn't use SOAP or similar because the first ideas was simple. Also, I have never used SOAP before. If this is the right way, I would be very grateful if you show me how to use it from Qt/QML in android.
Of course, I can use C++ for the client application since it is using Qt.
I use Qt since I already know it and the app might be useful in desktop as well.
Sorry if I made any english mistake.
Thank you in advance.

Android : Confused/Lost with Call a PHP webservice with Send & Receive

From my android app, I want to call php web services. At times, I just need some data from php, sometime get data based on some parameter passed. I prefer to use RAW Api like HttpClient. I also plan to use mySql DB.
To call php web services, I got references from http://lukencode.com/2010/04/27/calling-web-services-in-android-using-httpclient/, and http://www.anddev.org/doing_http_post_with_android-t492.html, http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
I am STUCK at :
For eg: I pass 2 parameters with my url "http://......php?src=SOURCE&dest=DEST
REsult - Directions from SOURCE to DEST (at times result may be an array of strings, items, etc)
How to do send & receive data back in single request ?
How to write php for the same ?
Can the above accomplished using raw aPI or JSon or ksoap is required ? I have read that instead of using Jsoan or Soap, raw is the best approach.
Kindly help me to solve the confusion and proceed ahead wit hthe application.
Any help is highly appreciated.
Thanks
Yes,
alfasin, thru ur post and other sites I got things properly working.

Categories