Skip to main content

Calling an API

Overview

In this tutorial, we will walk through the steps needed to make an API call in Shipyard. This guide will accomplish that using Shipyard's native HTTP Blueprint. If you'd rather use your own Python script, the steps are provided to do that as well.

We will be calling GitHub's API to create an issue in a repository.

By the end of this tutorial, you'll be able to:

  • Call an API using the Request native Blueprint
  • Call an API using a Python code Vessel

Steps

Step 1: Generating API Key

  1. Head here and follow GitHub's guide to create an API Key.
  2. Under Repository Permissions, change the access for Issues to have read and write access and Metadata to have read-only access.

Step 2: Calling GitHub's API

  1. In Shipyard, click New Fleet in the top left corner.
  2. Select a Project for this Fleet to be placed in and click Select Project. This will take you to the Fleet Builder.
  1. Under HTTP, select Requests. This will create a Vessel for you in the Fleet Builder.
  2. Under Vessel Name, enter Create GitHub Issue.
  3. Under Method, select POST.
  4. Under URL, enter https://api.github.com/repos/YOUR_GITHUB_USERNAME/YOUR_REPOSITORY_NAME/issues and insert your username and repository name in the marked spots.
  5. Under Content Type, select application/x-www-form-urlencoded.
  6. Under Authorization Header, enter token YOUR_API_CREDENTIAL, replacing YOUR_API_CREDENTIAL with your actual API credential from GitHub.
  7. Under Message, enter {"title":"YOUR_REPOSITORY_NAME","body":"Test Issue"}, replacing YOUR_REPOSITORY_NAME with your actual repository name.

info

You can connect a Vessel to the Request Vessel to receive the API response by sending response.txt with Slack or Email or storing it in a Cloud Storage Container.

  1. Click Save & Finish on the bottom right of your screen. This will take you to a page letting you know that your Fleet has been created successfully.
  2. Click Run Now. This will take you to the Fleet Log page for your Fleet run.

Step 3: Verify that the Issue was Created

  1. Once the Fleet has finished running successfully, click the green rectangle from the gantt chart to view the Vessel log.
  2. The Vessel log confirms that the request was successfully sent to the API.

  1. Over in Github, navigate to the repository where you created the issue.
  2. Select Issues.

  1. You can see the Issue that we created using the API listed.

success

You've successfully used Shipyard to create an issue in GitHub using an API call.