Using the Method SDK

Method provides a publicly available SDK in python and typescript. This page includes instructions for authenticating and constructing clients in these languages. The API Reference section lists the available endpoints along with their arguments and responses.

Python SDK Usage

The Method SDK is published to pypi. Example code to initialize a MethodClient and make a simple API call is:

1from method_security import MethodClient
2
3def construct_client_and_get_issue_details(source, issue_id):
4 # Replace "my-hostname" with the hostname of your Method instance
5 base_url = f"https://my-hostname.method.delivery"
6 client = MethodClient(base_url=base_url)
7
8 issue_details = client.v1.issues.get_issue(id=issue_id)
9 return issue_details

The get_issue endpoint used in this example is documented in the API Reference section, which includes all available endpoints, as well as their arguments and responses.

This example assumes that the OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET environment variables have been set for authentication, as described in the Authentication section below.

A small example project using the Method SDK can be found in the method-sdk-examples repository on github.

Authentication

The Method SDK uses the OAuth 2.0 Client Credentials flow for authentication. Callers of the SDK are configured with an OAuth 2.0 client ID and client secret, which are used to acquire access tokens. The SDK acquires access tokens and uses them to make API calls automatically; callers of the SDK do not need to call authentication endpoints directly.

To configure authentication for an application using the Method SDK:

  1. Request the creation of an OAuth 2.0 client for your application from Method Support.
  2. Method Support will create this client and provide you with its client ID and client secret.
  3. Set environment variables in your application’s environment called OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET. Their values are the client ID and client secret provided in Step 2 respectively. The SDK will detect these variables and use them to acquire access tokens automatically.

It is also possible to acquire access tokens manually using the OAuth 2.0 client ID and client secret, and use those when calling API endpoints. This can be useful for testing, but note that access tokens expire after a short duration, so production applications should use the flow described above.

TypeScript SDK Usage

The TypeScript SDK will be published to npm shortly, at which point the documentation will be updated with example usage.