BitlyDeveloper
Navigation

Generate Libraries Using OpenAPI 3.0

The OpenAPI Specification was created to define a standard interface description for APIs that is not specific to any one programming language. Using the recommended OpenAPI Generator tool, you can generate libraries to access the Bitly API in the language of your choice. The following steps will help you understand that process.

Generate the code

  1. Download Bitly’s API specification.

  2. Install OpenAPI Generator.

  3. Choose a supported language from the Generators List.

  4. Utilize the CLI to generate the code. This command will generate code based on the Bitly API in Golang.
    openapi-generator generate -i v4.json -g go -o go/

  5. You can now use the generated library in your project.

Example: Using the library to shorten a link

You will have a lot of code to sort through, so here's a sample implementation that calls the /v4/shorten endpoint using a generated library. While these code examples are in Golang, Java, and Javascript languages, they should provide enough context that you can apply them to any language.

//initialize the api client
ApiClient apiClient = new ApiClient();
((HttpBearerAuth) apiClient.getAuthentication("bearerAuth")).setBearerToken("{ACCESS_TOKEN}");
BitlinksApi bitlinksApi = new BitlinksApi(apiClient);

//build the request
Shorten shorten = new Shorten();
shorten.setDomain("{CUSTOM_DOMAIN}");
shorten.setGroupGuid("{GROUP_GUID}");
shorten.setLongUrl("{LONG_URL}");

try {
    BitlinkBody bitlinkBody = bitlinksApi.createBitlink(shorten);
    System.out.println("SUCCESS! Link=" + bitlinkBody.getLink());
} catch (ApiException e) {
    //handle error
    e.printStackTrace();
}