Call a GitHub API endpoint and get the resulting JSON response

Calls any GitHub API endpoint. You must provide your GitHub Personal token (get one from Out parameters provide the status code and the full response JSON if valid, otherwise the raw response body. Documentation:

Supported platforms ios, android, mac
Author @tommeier
Returns A hash including the HTTP status code (:status), the response body (:body), and if valid JSON has been returned the parsed JSON (:json).

2 Examples

result = github_api(
  server_url: "",
  api_token: ENV["GITHUB_TOKEN"],
  http_method: "GET",
  path: "/repos/:owner/:repo/readme",
  body: { ref: "master" }
# Alternatively call directly with optional error handling or block usage
    server_url: "",
    api_token: ENV["GITHUB_TOKEN"],
    http_method: "GET",
    path: "/repos/:owner/:repo/readme",
    error_handlers: {
      404 => proc do |result|
        UI.message("Something went wrong - I couldn't find it...")
      '*' => proc do |result|
        UI.message("Handle all error codes other than 404")
  ) do |result|
    UI.message("JSON returned: #{result[:json]}")


Key Description Default
server_url The server url. e.g. '' (Default: '')
api_token Personal API Token for GitHub - generate one at *
http_method The HTTP method. e.g. GET / POST GET
body The request body in JSON or hash format {}
raw_body The request body taken vertabim instead of as JSON, useful for file uploads
path The endpoint path. e.g. '/repos/:owner/:repo/readme'
url The complete full url - used instead of path. e.g. ''
error_handlers Optional error handling hash based on status code, or pass '*' to handle all errors {}
headers Optional headers to apply {}
secure Optionally disable secure requests (ssl_verify_peer) true

* = default value is dependent on the user's system

To show the documentation in your terminal, run

fastlane action github_api

View source code

Back to actions