Live demo
All API methods require that public API key
and/or private API key
be supplied as query arguments. You can find your keys on the API page of the JotURL back office.
Check the authentication type of each API method, login
means you need only the public API key
, key
means that you have to provide both public API key
and private API key
; furthermore, you have to use HTTPS when calling methods with key
authentication.
In this page you can find some examples (Objective-C / iOS, PHP, Windows 8 Metro Style App - C#) on how to use the JotURL API.
Interactive demo
URL | |
API methods | Basic methodsAdvanced methodsURL Hub |
Output format | |
HTTP method | |
Public API key | |
Private API key | |
Controller URL | |
Short URL | |
Condition | |
Password (max 15 chars) | |
Valid from (YYYY-MM-DD HH:MM) | |
Valid to (YYYY-MM-DD HH:MM) | |
URL to be used after expiration | |
Delete short URL after expiration | |
Long URL | |
Alias | |
Domain | |
URL group | |
WARNING: this API method requires HTTPS! |
URL (GET)
Response
jQuery/AJAX example code
This code is provided as an example. Do not use in real applications, since it does not guarantee the confidentiality of your API keys.
Objective-C / iOS example code
@interface JotURL :NSObject{ NSMutableData*responseData; } @property(nonatomic,retain)NSMutableData*responseData; @end @implementation JotURL @synthesize responseData; - initClient { return self; } -(void) connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response { [responseData setLength:0]; } -(void) connection:(NSURLConnection*)connection didReceiveData:(NSData*)data { [responseData appendData: data]; } -(void) connection:(NSURLConnection*)connection didFailWithError:(NSError*)error { //show error NSLog(@"Error = %@", [error localizedDescription]); } -(void) connectionDidFinishLoading:(NSURLConnection*)connection { //process content NSLog(@"Ok = %@", [[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding]); } -(NSString*) escapeParam:(NSString*)v { return(NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)v, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); } -(void) addPostParam:(NSString**)d :(NSString*)k :(NSString*)v { NSString* p =[k stringByAppendingString:@"="]; p =[p stringByAppendingString:[self escapeParam: v]]; if([*d length]!=0)*d =[*d stringByAppendingString:@"&"]; *d =[*d stringByAppendingString: p]; } -(void) responsePOST { responseData =[[NSMutableData alloc] initClient]; NSString* url =@"%url%"; NSMutableURLRequest*request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString: url]]; [request setHTTPMethod:@"POST"]; [request setCachePolicy: NSURLCacheStorageNotAllowed]; NSString* data =@"";- %data%
[request setHTTPBody:[data dataUsingEncoding: NSUTF8StringEncoding]]; NSURLConnection* connection =[[NSURLConnection alloc] initWithRequest: request delegate: self]; if(!connection){ NSLog(@"Connecton error"); } } @end
<li class="li1"><div class="de1"> <span class="br0">[</span>self addPostParam<span class="sy0">: &</span>data <span class="sy0">:</span> <span class="co3">@</span><span class="st0">"%key%"</span> <span class="sy0">:</span> <span class="co3">@</span><span class="st0">"%value%"</span><span class="br0">]</span>;</div></li>
@interface JotURL :NSObject{ NSMutableData*responseData; } @property(nonatomic,retain)NSMutableData*responseData; @end @implementation JotURL @synthesize responseData; - initClient { return self; } -(void) connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response { [responseData setLength:0]; } -(void) connection:(NSURLConnection*)connection didReceiveData:(NSData*)data { [responseData appendData: data]; } -(void) connection:(NSURLConnection*)connection didFailWithError:(NSError*)error { //show error NSLog(@"Error = %@", [error localizedDescription]); } -(void) connectionDidFinishLoading:(NSURLConnection*)connection { //process content NSLog(@"Ok = %@", [[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding]); } -(NSString*) escapeParam:(NSString*)v { return(NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)v, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); } -(void) addGetParam:(NSString**)u :(NSString*)k :(NSString*)v { NSString* p =[k stringByAppendingString:@"="]; p =[p stringByAppendingString:[self escapeParam: v]]; if(![*u hasSuffix:@"?"])*u =[*u stringByAppendingString:@"&"]; *u =[*u stringByAppendingString: p]; } -(void) responseGET { responseData =[[NSMutableData alloc] initClient]; NSString* url =@"%url%?";- %data%
NSURLRequest*request =[NSURLRequest requestWithURL:[NSURL URLWithString: url]]; NSURLConnection* connection =[[NSURLConnection alloc] initWithRequest: request delegate: self]; if(!connection){ NSLog(@"Connecton error"); } } @end
<li class="li1"><div class="de1"> <span class="br0">[</span>self addGetParam<span class="sy0">: &</span>url <span class="sy0">:</span> <span class="co3">@</span><span class="st0">"%key%"</span> <span class="sy0">:</span> <span class="co3">@</span><span class="st0">"%value%"</span><span class="br0">]</span>;</div></li>
PHP example code
<?php
try {
$data = array(
%data%
);
//generates URL-encoded query string
//<a href="http://it2.php.net/manual/en/function.http-build-query.php">http_build_query</a>
$data = http_build_query($data);
$context_options = array(
'http' => array(
'method' => '%http%',
'header' => implode("\r\n", array(
"Content-type: application/x-www-form-urlencoded",
"Content-Length: " . strlen($data)
)),
'content' => $data
)
);
//creates a stream context
//<a href="http://it2.php.net/manual/en/function.stream-context-create.php">stream_context_create</a>
$ctx = stream_context_create($context_options);
if (!$ctx) {
throw new Exception("Problem creating stream context, " . print_r(error_get_last(), true));
}
$url = '%url%';
//sends an https request
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, " . print_r(error_get_last(), true));
}
//reads remainder of a stream into a string
//<a href="http://it2.php.net/manual/en/function.stream-get-contents.php">stream_get_contents</a>
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url," . print_r(error_get_last(), true));
}
fclose($fp);
//outputs response
echo $response;
}
catch (Exception $e) {
//output exception information
echo '<pre>' . print_r($e, true) . '</pre>';
}
?>
'%key%' => '%value%'
Windows 8 Metro Style App - C# example code
- private void setContent(string msg)
- {
- //process content
- }
- private void setError(string msg)
- {
- //show error
- }
- private async void apiTest_POST()
- {
- try
- {
- HttpContent httpContent = new FormUrlEncodedContent(new[]
- {
%data%- });
- string url = "%url%";
- Uri resourceUri;
- if (!Uri.TryCreate(url, UriKind.Absolute, out resourceUri))
- {
- throw new Exception("Invalid URL");
- }
- HttpClient httpClient = new HttpClient();
- HttpResponseMessage response = await httpClient.PostAsync(resourceUri, httpContent);
- string content = await response.Content.ReadAsStringAsync();
- setContent(content);
- }
- catch (HttpRequestException hre)
- {
- setError(String.Format("{0}: {1}", hre.Message, hre.InnerException.Message));
- }
- catch (TaskCanceledException)
- {
- setError("Request cancelled");
- }
- }
<li class="alt"><span> <span class="keyword">new</span><span> <span class="class">KeyValuePair</span><</span><span class="keyword">string</span><span>, </span><span class="keyword">string</span><span>>(</span><span class="string">"%key%"</span><span>, </span><span class="string">"%value%"</span><span>)%comma% </span></span></li>
<span>,</span>
- private void setContent(string msg)
- {
- //process content
- }
- private void setError(string msg)
- {
- //show error
- }
- private async void apiTest_GET()
- {
- try
- {
- string url = "https://api.joturl.com/a/v1/expand?";
- %data%
- Uri resourceUri;
- if (!Uri.TryCreate(url, UriKind.Absolute, out resourceUri))
- {
- throw new Exception("Invalid URL");
- }
- HttpClient httpClient = new HttpClient();
- HttpResponseMessage response = await httpClient.GetAsync(resourceUri);
- string content = await response.Content.ReadAsStringAsync();
- setContent(content);
- }
- catch (HttpRequestException hre)
- {
- setError(String.Format("{0}: {1}", hre.Message, hre.InnerException.Message));
- }
- catch (TaskCanceledException)
- {
- setError("Request cancelled");
- }
- }
<li class="alt"><span> url += <span class="string">"%key%="</span><span> + <span class="class">Uri</span>.EscapeDataString(</span><span class="string">"%value%"</span><span>)</span>%comma%<span>; </span></span></li>
<span> + </span><span class="string">"&"</span>