Using swagger-codegen with Marketo

October 10, 2016 | by

Swagger-codegen is a powerful Java library which can generate both server stubs and API clients from swagger definitions.  This can dramatically ease the difficulty and cost of generating clients for any specific language.  To get started and generate your first client, you’ll first want to grab an instance-specific copy of one of Marketo’s Swagger Definitions.  Go here and input the Munchkin ID from the instance you want to test with. Start with the identity definition.

Now that you have a definition specific for your instance, you’ll need to download and install swagger-codegen.  The process is specific to your operating system, and you can get the instructions here

With the default settings, codegen will output a client covering all of the provided endpoints and models.  These are typically managed through a class called DefaultApi, containing methods for calling the available endpoints with examples provided in a ‘docs’ folder (not all languages include templates for this by default).

Now let’s build the first client.  Create a folder where you want your code to live, and go there in your terminal session and use the generate command to build a client in the language that you want (we’ll assume you’ve used the homebrew install method):

This will output the client code into your desired location.

Now let’s look at using this to call the identity endpoint and get an access token:



  •  

  •  

Now that we know how to get authorized, we’ll take a look into more advanced use cases of auto-generated clients in the coming weeks.