Import short URLs
Since it’s quite possible that you are already using some other URL shortener, starting with v2.4.0, it is possible to import short URLs directly into Shlink.
Import is performed from the command line, by running the short-urls:import
command.
This command will guide you through the import process, asking you to provide the source from which you want to import, together with all required information for this process to succeed.
The import command can be run as many times as you want, as Shlink is smart enough to not import the same link from the same source more than once, ensuring data consistency.
However, there’s a couple considerations:
- The process has been optimized as much as possible, trying to avoid memory leaks. However, it is recommended to reserve at least 512Mb to PHP when running this process.
- The import process is transactional and all-or-nothing. If there’s an uncontrolled error, the import will be rolled-back.
- In order to determine if a visit has already been imported, Shlink relies on their date, assuming you will usually import on top of an “empty” instance. If this is not the case, it could end up ignoring visits that are not actually imported yet, just because they are older than other existing visits.
Supported sources
These are the sources from which you can currently import:
- Bitly (since Shlink v2.4.0)
- YOURLS (since Shlink v2.10.0)
- Standard CSV (since Shlink v2.6.0)
- Shlink instance (since Shlink v2.7.0)
- Kutt.it (since Shlink v3.1.0)
Bitly
Bitly’s importing is done through their API. That means that, depending on how many URLs you need to import, you could hit some API limit.
However, they allow up to 150 requests per minute for free accounts, and the number is even higher for paid plans.
On every API call, 50 URLs are imported, which means you won’t hit the limit if you have less than 7500 URLs.
If you hit the limit, shlink will print a “continue token” that can be used to skip already imported URLs, and therefore, avoid the limit to be hit again.
When you have waited a couple of minutes for the limit to clear, you can run the import command again, but providing the “continue token” when requested.
Running the command will generate an output similar to this:
YOURLS
Shlink allows importing short URLs, and optionally visits, from a YOURLS instance using its API.
There’s a couple of limitations on imported data, as YOURLS does not store by default visitors IP address or geoloaction.
Warning
YOURLS’ API does not expose enough actions for Shlink to fetch all data. Because of that, you first need to install the yourls-shlink-import-plugin
in YOURLS itself. You can download it from its repository and follow the instructions there.
Running the command will generate an output similar to this:
Standard CSV
In order to simplify importing links from arbitrary sources, Shlink supports importing from a simple CSV file.
The only 2 required columns in the CSV file are Long URL
and Short code
, but it also accepts the optional Title
, Domain
and Tags
columns.
The Tags
one should contain a list of pipe-separated items, as in foo|bar|baz
.
This is an example of a valid CSV file:
Running the command will generate an output similar to this:
Shlink instance
If at some point you need to migrate your Shlink instance, or you want to change the database engine for any reason, this will help you import your short URLs from another Shlink instance.
The importing will be done by making use of Shlink’s built-in REST API. It will import links, their tags and domains, and also their visits if you choose to.
In order for this to work, you need to keep your old Shlink instance publicly accessible, otherwise you will not be able to import.
Running the command will generate an output similar to this:
Note
Starting with v3.4.0, Shlink also allows to import orphan visits from the original Shlink instance.
This importing source is available since Shlink 2.7.0, but it can import from older Shlink versions.
Kutt.it
Shlink allows importing short URLs, and optionally visits, from a self-hosted kutt instance, or the SaaS https://kutt.it, using its API.