#!/usr/bin/perl # 2008-03-21 Interdubs API Example # # You need an API key before you can run this example. # Just drop me an email and I will generate you the key. # # This example will create a new login with a password # in the Interdubs segment that the API key points to. # # Documentation can be found at: # http://www.interdubs.com/wikanual/index.php/Api # # It's perl here, but could be anything. # The actual interface is a simple web page request. # # This example uses curl to communicate with the Interdubs host. # Other tools should work as well. # # After you got an API key an entered it here you can run this # example. If you want to see the logins being created then # change the simulation variable to 0 use strict; # You will need to get a key first my $api_key = ""; # The two parameters that we will use my $example_newlogin_name = "apitest"; my $example_newlogin_password = "password" . time(); # Here we use the API in simulation mode # change this to 0 once you want to cause the API to change things # set back to 1 if you simply want to test your interfaces etc my $simulation=1; # # Let's build the URL we will use # my $url; #the protocoll, we can use http or https #domain #API location # $url = "http://www.interdubs.com/api/?"; #the order does not really matter #don't forget to seperate the parameters with & # the key $url .= "idxapi_key" . "=" . "$api_key" ; $url .= "&"; # the function: what we like to do , here we create a login with folder $url .= "idxapi_function" . "=" . "create_login_wfolder"; $url .= "&"; # parameter1 for us thats the login name $url .= "idxapi_par1" . "=" . "$example_newlogin_name"; $url .= "&"; # parameter2 the password $url .= "idxapi_par2" . "=" . "$example_newlogin_password"; $url .= "&"; # if we run in simulation mode $url .= "idxapi_simulation" . "=" . "$simulation"; #$url .= "&"; last parameter has no need for & # we use curl, so let's see if we can find it. if (`which curl` eq ""){ die "$0 needs the program curl to be in the path"; } #variables that will receive the data returned from the call my $idxapi_login_id; my $idxapi_login_ak; my $idxapi_folder_id; my $idxapi_folder_ak; # we call the url wwe have generated via curl foreach my $l ( `curl '$url'`){ chomp ($l); # status returns check if ($l =~ /^IDXAPI_ERROR: (.*)/){ #internal error die "$url generated error: $1\n"; } if ($l =~ /^IDXAPI_FAILURE: (.*)/){ #something was wrong with the information provided the key, etc die "Please check your parameters, they caused a failure: $1\n"; } if ($l =~ /^IDXAPI_SIMOK: (.*)/){ # all went well, but nothing was done , since this was a simulation print "Sucessfully ran function $1 in simulation mode. Set simulation to 0 to actually execute.\n"; exit (0); } if ($l =~ /^IDXAPI_OK: (.*)/){ # success, we don't need to do anything ... } #the date we received we put into those variables we have set up if ($l =~ /^IDXAPI_LOGIN_ID: (.*)/){ $idxapi_login_id = $1; } if ($l =~ /^IDXAPI_LOGIN_AK: (.*)/){ $idxapi_login_ak = $1; } if ($l =~ /^IDXAPI_FOLDER_ID: (.*)/){ $idxapi_folder_id = $1; } if ($l =~ /^IDXAPI_FOLDER_AK: (.*)/){ $idxapi_folder_ak = $1; } } print "Sucessfully created a new login called $example_newlogin_name with a password $example_newlogin_password\n"; print "\n"; print "received the following info back: \n"; print " ID for login: $idxapi_login_id\n"; print " AK for login: $idxapi_login_ak\n"; print " ID for folder: $idxapi_folder_id\n"; print " AK for folder: $idxapi_folder_ak\n"; print "\n";