API for Developers

WGG URL Shortener API Guide:


Registering for an API Key

As before, an API key is required for requests to be processed by the system. Once a user registers, an API key is automatically generated for this user and can be found in the settings page. The API key must attached to request via the api parameter (see full example below).


Sending a request for shortening a URL

To send a request, the user must use the following format where the variables api and url are required. To request a custom alias, simply add &custom= at the end.

  GET https://wgg.co/api?api=[APIKEY]&url=[URL_to_be_shortened]&custom=[Optional_custom_alias]


  GET https://wgg.co/api?api=ok7nC2Ul8P7x&url=https://www.youtube.com/watch?v=81sOz9TTmko&custom=MySong

Server response

As before, the response will encoded in JSON format (default). This is done to facilitate cross-language usage. The first element of the response will always tell if an error has occurred (error: 1) or not (error: 0). The second element will change with respect to the first element. If there is an error, the second element will be named “msg”. which contains the source of error, otherwise it will be named “short” which contains the short URL.

In case the there was no errors the server responds as follow:



In case there was an error the server responds as follow:

  "msg":"A valid API key is required to use this service."

Using plain text format:

You can now request the response to be in plain text by just adding &format=text at the end of your request. This will return just https://wgg.co/DkZOb instead of the JSON response.

IMPORTANT: Note that if an error occurs, it will not output anything.


Using the API in PHP

To use the API in your PHP application, you have to send a GET request through file_get_contents() or cURL: Both are reliable methods. You can see a sample code below using file_get_contents():

  // Using JSON Response
  $apiKey = "ok7nC2Ul8P7x";
  $longURL = "https://www.youtube.com/watch?v=81sOz9TTmko";
  $customAlias = "mylink";
  $api_url="https://wgg.co/api?api=" . $apiKey."&url=" . $longURL . "&custom=" . $customAlias;
  $res= @json_decode(file_get_contents($api_url),TRUE);
    echo $res["msg"];
    echo $res["short"];
  // Using Plain Text Response
  $apiKey = "ok7nC2Ul8P7x";
  $longURL = "https://www.youtube.com/watch?v=81sOz9TTmko";
  $customAlias = "mylink";
  $api_url="https://wgg.co/api?api=" . $apiKey."&url=" . $longURL . "&custom=" . $customAlias;
  $res= @file_get_contents($api_url);
    echo $res;