Warning: This page is about Google's older APIs, the Google Data APIs; it's relevant only to the APIs that are listed in the Google Data APIs directory, many of which have been replaced with newer APIs. For information about a specific new API, see the new API's documentation. For information about authorizing requests with a newer API, see Google Accounts Authentication and Authorization.
How to use the FileMaker 17 Data API – Video Tutorial. With the removal of the ability to control the PHP or XML API from the FileMaker Server Admin Console and only allowing you to enable/disable it via the command line, it’s pretty clear that FileMaker sees the Data API as the future.
Ryan Boyd, Google Data APIs TeamSeptember 2007
- Authenticating to a Google Data Service
Introduction
At heart, Google Data APIs use Atom feeds and entries (XML) as a data format and HTTP as a protocol for data transmission - extending the Atom Publishing Protocol. We publish a number of client libraries to make interacting with Google Data APIs easier. However, you're always welcome to use lower-level tools to work with our services, and it's pretty easy to do with a little guidance.
cURL is a command-line application for performing requests using a variety of protocols including HTTP. cURL is often used by developers to test Google Data services, as it supports the HTTP functionality required to interact with the APIs at a low level.
cURL only provides support for performing the HTTP communication, so knowledge of the Google Data protocol, the service-specific protocol and the XML data format used is a prerequesite for working with the application. Some other tools are mentioned in this article for making these tasks easier.
This article uses examples based upon the Picasa Web Albums data API. However, all these examples can be readily applied to other Google Data APIs.
Obtaining and installing cURL
cURL is commonly available on a default install of many UNIX/Linux platforms. Try typing
curl
in your favorite shell to see if the tool is installed and is in your PATH
. If you don't have the tool installed, visit the download page on the cURL website to obtain the official source or a user-contributed binary package. Note that the command-line tool uses the libcurl
library, which may be offered as a separate download package, so, if you're not compiling from the source, be sure to download a 'binary' package instead of a 'libcurl' package. The SSL-enabled packages are required if you wish to use cURL to acquire authentication tokens or to access some Google Data services which require using SSL for requests.Authenticating to a Google Data Service
Authenticated Google Data requests are performed by adding an HTTP header to the request which contains either a ClientLogin (desktop/mobile apps) or AuthSub (web apps) authentication token. For the purposes of testing using cURL, ClientLogin is the easier method and is documented below. AuthSub authentication headers could be used with cURL, but the more-advanced process of obtaining the tokens is out of scope for this article.
Using ClientLogin
ClientLogin is intended for installed (desktop/mobile) applications. With this method of authentication, the application using Google Data APIs directly handles the username and password of the user.
An authentication request for ClientLogin takes a username, password, and service name as form post variables. These variables are passed as the
Email
, Passwd
, and service
arguments, respectively. This request yields a response with several tokens, one of which can be used to make requests to the Google Data service. Note that data arguments passed with curl
must be URL-encoded if they contain non-ASCII characters, which often appear in Email
and Passwd
arguments. You can ask curl
to URL-encode these arguments by using the --data-urlencode
flag.Example Request:
Example Response:
Please see the ClientLogin documentation for specific information on the parameters used in the above request. In this example, the service we're using is the Picasa Web Albums data API. The service name (
service
) is lh2
. The service names for other Google Data services can be found in the Google Data APIs FAQ page.The value of the
Auth
token in the above response is the only value needed for authentication to Google Data services. The value of this token is formed into an HTTP header which is then used for each request to a Google Data service.Note: The method of escaping newline characters with backslash characters (') above does not work in the Windows command shell, so you must enter the entire command on one line if you're running
curl
on Windows.Retrieving feeds and entries
In Google Data APIs, retrieving feeds and entries is done by performing an HTTP
GET
on a URL, with an optional set of query parameters. Because we are performing a GET
request, only the auth header and the URL are required to be passed to curl
. The example below will continue using the Picasa Web Albums data API and is used to retrieve a list of albums owned by the authenticated user. Note that we have shortened the auth token to ABCDEFG
in this example, but the full token (e.g. EUBBIacA
...32JKOuGh
from above) should be used in its place.This will return an unformatted blob of XML:
There are some decent tools for formatting this output to make it more human-readable, including tidy. The easiest way to use tidy is to pipe the output from the curl command to tidy like the following:
This results in a much more readable feed, like the following:
Individual entries can be retrieved in the same way by providing the URL for the entry, as opposed to a feed URL.
Updating entries
Entries in Google Data APIs are updated by doing an
HTTP PUT
to the edit URL with a new copy of the entry's XML in the body of the request.- Retrieve the entry using the
atom:link/@rel='self'
URL value - Update the entry locally to make the needed changes
PUT
the entry back to the server, using theatom:link/@rel='edit'
URL value
1. Retrieving the entry
The entry can be retrieved using one of the two URLs bolded in the feed block above. The URL needed is the
href
value for the link
element with a rel='self'
.2. Updating the entry locally
After you retrieve the entry, the entry needs to be updated using a local text editor or application to make any needed changes to the entry. In the command above to retrieve an entry, we did not pipe the results to
tidy
as we have done in the previous examples. The result is XML that represents the same data, but has different formatting than the version piped to tidy
. For the purposes of hand editing an entry, using tidy
can often make working with the XML easier.Note: Please remember to include all XML namespace definitions which are used as attributes to the
atom:entry
when you post your new entry. Omitting these will cause parsing exceptions. Also, tidy
will replace the spaces between the namespace definitions with newline characters. While this is valid XML, Google Data services do not accept it at this time. If you are using tidy
, please be sure to add additional spaces between these attributes on the entry
element.3. Updating the entry on the server
Using the
edit
URL, you need to PUT
a copy of the entry to the service using cURL. A header to indicate the type of content being sent to the server needs to be added. The following snippet assumes that the file with the updated entry is saved in updated_entry.xml.Creating entries
Entries in Google Data APIs are created by doing an
HTTP POST
to the post URL with a new entry. The atom:id
is assigned by the server, and thus not necessary to include in new entries. The easiest way to create a new entry is to take an old entry and modify it. The following example will do just that.- Retrieve a template entry using the
atom:link/@rel='self'
- Modify the template entry locally to remove unnecessary information and make the needed changes
POST
the entry back to the server, using thepost
URL for the feed. This is either found in the retrieved feed as thehref
value for thelink
element with arel='http://schemas.google.com/g/2005#post'
, or in the documentation for the service on http://code.google.com.
1. Retrieve a template entry
A single entry can be retrieved using the
href
value of a link
element with a rel='self'
in the same way as an entry was retrieved before updating it in the above example.The response, after using
tidy
will look something like:2. Modify the template entry
We want to create an album called 'Curling in Canada' with pictures from our recent curling match. Google Data allows you to drop Atom elements that the server supplies values for, so to create this simple template entry, we'll remove the
atom:id
, atom:published
, atom:updated
, atom:author
, and the various atom:link
elements in the feed. This will give us a stripped-down template entry. The entry then needs to be modified to represent the new album we are creating:Note: Please remember to include all XML namespace definitions which are used as attributes to the
atom:entry
when you post your new entry. Omitting these will cause parsing exceptions. Also, tidy
will replace the spaces between the namespace definitions and replace them with newline characters. While this is valid XML, Google Data services do not accept it at this time. If you are using tidy
, please be sure to add additional spaces between these attributes on the entry
element.3. Posting the new entry to the server
The
curl
command for posting a new entry to the server is very similar to updating an existing entry except that the URL is different:![Curl Is Required To Use The Filemaker Api. Curl Is Required To Use The Filemaker Api.](/uploads/1/2/4/6/124698882/236172406.png)
If the post was successful, the resulting XML output is a copy of the newly-created entry. This entry will include things which the server generated at the time the entry was created, including the values for the
atom:id
, atom:published
, atom:updated
, and atom:link
elements. The resulting link
values can be used to edit or delete the entry, provided no additional changes are made in the interim.Deleting entries
Deleting entries is very similar to updating entries, except an
HTTP DELETE
method is used instead of an HTTP PUT
and no data is required to be sent. Also like the update request, the edit
URL is used as the target of the HTTP request.Uploading media objects
An important feature of the Picasa Web Albums data API and the Documents List data API is the ability to upload binary objects. cURL can easily accomplish uploading binary data and a slug header. However, the Documents List data API currently requires posting the XML along with the binary data as a MIME multipart message. Forming the multipart message is out of scope for this article.
The example below shows how to upload a picture called
sweeping_the_rock.png
to a Picasa Web Album with the title 'Sweeping the rock':Other command-line tools
Some developers prefer learning or debugging using other command-line tools.
Popular tools include:
- telnet, openssl are used for making raw socket connections (plain text and ssl-based, respectively) to web servers and can be used to interact with Google Data services. Note that not all Google Data services may support SSL. Here's how you open up the connections:
telnet picasaweb.google.com 80
(Picasa Web Albums data API)openssl s_client -connect www.google.com:443
(Google Calendar data API and other services on www.google.com)
POST
andPUT
operations will require computing the value for aContent-Length
header. You can use the UNIX toolwc
to compute this value. Place all the content of the HTTP body into a text file such astemplate_entry.xml
(example used above) and runwc -c template_entry.xml
. It is often difficult to debug if you accidentally use an incorrect value for theContent-Length
header. - wget is typically used to download data from a web server to a local file. However,
wget
has lots of options which make it capable of performing all the different types of requests needed to interact with Google Data services.. Here's an example of how to usewget
toPOST
a new album entry to Picasa Web Albums: - xsltproc is a tool to apply XSL transformations (XSLT) to XML documents. It can be used to easily extract desired bits of data from an XML entry or feed returned by Google Data APIs, or to generate new or updated entries.
Conclusion
As you've seen, cURL and several other command-line tools can be used to easily interact with Google Data services using raw XML and HTTP. Please join us in the API specific forums if you have any questions about using these tools with your favorite Google Data API.
I am having a difficult time formulating an 'AND' query with the FileMaker 17 API.
Reference:https://fmhelp.filemaker.com/docs/17/en/dataapi/index.html#perform-a-find-request
This is being passed into CURLOPT_POSTFIELDS.
What I'd like to have happen is that I retrieve 1 record for which the
uniqueID
is 'fooBar' and the anotherField
is 1.However, I get the same record if I pass:
So this is doing an 'OR' lookup.
How can I structure this request so that it performs an 'AND' lookup. In the case of my second example, the query should return no records, as every record in my table has a
uniqueID
?Updated post-answer:
In my analysis, it seems that the second query in my question simply is an AND for any uniqueID which contains literally nothing, which I guess Filemaker somehow interprets as being true for any record.
For someone coming from MySQL, this is very confusing behavior. And the documentation, while demonstrating this as a global property of FileMaker, is not apparent when looking at the Filemaker API documentation and examples.
jhchnc
jhchncjhchnc
3 Answers
You are doing an 'AND' find. If a field is empty in a find then it will not be searched on. In your counter example you were only searching for fields with anotherField:1. If you want to search on an empty field use '=' as it will only find empty words.
Not enough Rep to comment but for your previous answer:
For Filemaker finds on a uniqueID you would want to use ' . '=' will give you a word match while ' will give you an exact value match. See https://fmhelp.filemaker.com/help/12/fmp/en/html/find_sort.5.6.html
RushfireRushfire
Agreed re: the Data API documentation. To clarify, for folks who may be visiting this thread later:
Brian HammBrian Hamm
I know I literally ask this a moment ago, but it bears recording, as the Filemaker API documentation is pretty shoddy.
That returns the record I seek.
The addition of either
=
prevents the false positive, albeit in different ways.-- Updated to reflect the fine-grained details in Rushfire's answer.
jhchncjhchnc