npm package: @fern-api/auth0-management-snippets
Description: Generate usage snippets for Auth0 Management SDKs
Author: Fern
Latest version: 0.0.6

# Auth0 Management Snippets SDK

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)

The Auth0 Management Snippets SDK produces valid usage snippets from arbitrary request data for the Auth0 Management API.

## Supported Languages

The SDK supports generating code snippets for the following languages:
- **TypeScript** - Node.js/TypeScript SDK snippets
- **Go** - Go SDK snippets

## Usage

The SDK can be used as follows:

```typescript
import { SnippetResolver } from "@fern-api/auth0-management-snippets";

const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const users = typescript.endpoint("GET /users");
const response = await users.generate({
    auth: {
        type: "bearer",
        token: "<YOUR_API_KEY>"
    },
    queryParameters: {
        per_page: 10,
        page: 0
    }
});
```

The generated `response.snippet` will be set to the following:

```typescript
import { ManagementClient } from "@fern-api/auth0-management-snippets";

async function main() {
    const client = new ManagementClient({
        token: "<YOUR_API_KEY>",
    });
    await client.users.list({
        perPage: 10,
        page: 0,
    });
}
main();
```

### Go Usage

To generate Go snippets, specify `"go"` as the language:

```typescript
import { SnippetResolver } from "@fern-api/auth0-management-snippets";

const resolver = new SnippetResolver();
const go = resolver.sdk("go");
const users = go.endpoint("GET /users");
const response = await users.generate({
    auth: {
        type: "bearer",
        token: "<YOUR_API_KEY>"
    },
    queryParameters: {
        per_page: 10,
        page: 0
    }
});
```

The generated `response.snippet` will be set to the following:

```go
package example

import (
    client "github.com/auth0/go-auth0/management/client"
    option "github.com/auth0/go-auth0/management/option"
    context "context"
    management "github.com/auth0/go-auth0/management"
)

func do() () {
    client := client.NewClient(
        option.WithToken(
            "<YOUR_API_KEY>",
        ),
    )
    client.Users.List(
        context.TODO(),
        &management.ListUsersRequestParameters{
            PerPage: management.Int(
                10,
            ),
            Page: management.Int(
                0,
            ),
        },
    )
}
```

## More Examples

### Get Action by ID

```typescript
const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const action = typescript.endpoint("GET /actions/actions/{id}");
const response = await action.generate({
    auth: {
        type: "bearer",
        token: "<YOUR_API_KEY>"
    },
    pathParameters: {
        id: "action_123"
    }
});
```

Generated snippet:

```typescript
import { ManagementClient } from "@fern-api/auth0-management-snippets";

async function main() {
    const client = new ManagementClient({
        token: "<YOUR_API_KEY>",
    });
    await client.actions.get("action_123");
}
main();
```

## Default snippets

You can call the `generate` method without a request payload to retrieve the default example
of the endpoint like so:

```typescript
import { SnippetResolver } from "@fern-api/auth0-management-snippets";

const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const users = typescript.endpoint("POST /users");
const response = await users.generate();
```

The generated snippet will include required fields with example values:

```typescript
import { ManagementClient } from "@fern-api/auth0-management-snippets";

async function main() {
    const client = new ManagementClient({
        token: "<token>",
    });
    await client.users.create({
        connection: "connection",
    });
}
main();
```

Note that the result will omit optional properties, so if a request is entirely composed of
optional values, you're better off providing your own request payload.

## Sync Methods

The SDK also exposes a `generateSync` method for users that don't have access to `async` and `await` in specific contexts.
It uses the same parameters as `generate` and can be invoked like so:

```typescript
import { SnippetResolver } from "@fern-api/auth0-management-snippets";

const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const users = typescript.endpoint("GET /users")
const response = users.generateSync({ ... });
```

## Endpoint Filtering

For performance, the `endpoint` method filters the provided API specification to only contain the
selected endpoint (e.g. `GET /users`). This means you can reuse the filtered result with a
simple variable for the endpoint like so:

```typescript
// The 'users' variable acts upon an API specification that only contains the 'POST /users' endpoint.
const users = typescript.endpoint("POST /users")

// Generate multiple snippets using the same instance.
const one = users.generateSync({ ... });
const two = users.generateSync({ ... });
...
```