GSAK (Geocaching Swiss Army Knife)
Contents - Index

GcApi2 (function)

GcApi2(sApiCall,[sHttpMethod],[sJsontData],[sCaption]) : string

sApiCall - Required. The api call including any paramaters
sHttpMethod - Optional. If not given "Get" is assumed. Valid values are Get,Post,Put,Delete.
sJsonData - Optional. Formatted Json data. Only meaningful (and required) for Put and Post methods
sCaption - Optional. Progress dialog caption.

So as not to confuse with the old GcApi() function, we output to different table - GcApi2.

Here are a few simple examples to get you started

1. Get some information for the current user (note that "me" is used to reference the current user)
 

$data = gcapi2("users/me/?fields=username,hidecount,referencecode,geocacheLimits")
MsgOK Msg=$data




Also remember that this function outputs the data to the GcApi2 table (in the current database)



2. Show the first 50 trackables in the current user's inventory
 

$data = gcapi2("trackables?type=1&take=50&fields=referenceCode,iconUrl,name,ImageCount,goal,description,releasedDate,OriginCountry,ownerCode,HolderCode,IsMissing,type")
MsgOk msg=$data

 
3. Get the first 50 bookmark lists for the current user
 

$data = gcapi2("users/me/lists?types=bm&fields=referencecode,name,description,count,isShared,IsPublic&take=50")
MsgOk msg=$data

 
4. Update a bookmarks list (book mark code found via example 3)
 

$data = gcapi2("lists/BM1F21","put",$jsonlist)
<data> VarName=$jsonlist
{"referenceCode":"BM1F21","name":"Name update test","description":"test update","TypeId":2,"isShared":true,"isPublic":false}
<enddata>

 
Note: When using api calls that use the HTTP PUT method you must include the full resource. So you must include all the fields in the example even if you don't really want to change them (the onus is on you to make sure they are the same as before)

We have also added the system variable $_GcApi2Header

This variable will contain the Http header of the response (of the most recent GcApi2() call)

There may be more information in the header later down the track, but for the moment the only real use is access to the x-total-count value. From the Groundspeak docs:
 
 

An example of what the contents of this variable will look like:

For example, if we wanted to know how many caches have the word "zebra" in the name:
 

$data = gcapi2("geocaches/search/?q=name:zebra&take=1")
$total = RegExSub("x-total-count: (\d+)",$_GcApi2Header,1,1)
MsgOk Msg=Total 'Zebra' caches: $total


 

Note: This function generates tables which are suitable to use with sqlite. For more information see  this link


Alpha List         Category List


Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact