(Vault.Consumers)
- Create - Create consumer
- List - Get all consumers
- Get - Get consumer
- Update - Update consumer
- Delete - Delete consumer
Create a consumer
package main
import(
"context"
"os"
sdkgo "github.com/apideck-libraries/sdk-go"
"github.com/apideck-libraries/sdk-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := sdkgo.New(
sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
sdkgo.WithConsumerID("test-consumer"),
sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
)
res, err := s.Vault.Consumers.Create(ctx, "test_consumer_id", &components.ConsumerMetadata{
AccountName: sdkgo.String("SpaceX"),
UserName: sdkgo.String("Elon Musk"),
Email: sdkgo.String("[email protected]"),
Image: sdkgo.String("https://www.spacex.com/static/images/share.jpg"),
})
if err != nil {
log.Fatal(err)
}
if res.CreateConsumerResponse != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
consumerID |
string | ✔️ | Unique consumer identifier. You can freely choose a consumer ID yourself. Most of the time, this is an ID of your internal data model that represents a user or account in your system (for example account:12345). If the consumer doesn't exist yet, Vault will upsert a consumer based on your ID. | test_consumer_id |
metadata |
*components.ConsumerMetadata | ➖ | The metadata of the consumer. This is used to display the consumer in the sidebar. This is optional, but recommended. | |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.VaultConsumersAddResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.BadRequestResponse | 400 | application/json |
apierrors.UnauthorizedResponse | 401 | application/json |
apierrors.PaymentRequiredResponse | 402 | application/json |
apierrors.NotFoundResponse | 404 | application/json |
apierrors.UnprocessableResponse | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
This endpoint includes all application consumers, along with an aggregated count of requests made.
package main
import(
"context"
"os"
sdkgo "github.com/apideck-libraries/sdk-go"
"log"
)
func main() {
ctx := context.Background()
s := sdkgo.New(
sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
sdkgo.WithConsumerID("test-consumer"),
sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
)
res, err := s.Vault.Consumers.List(ctx, nil, nil)
if err != nil {
log.Fatal(err)
}
if res.GetConsumersResponse != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
cursor |
*string | ➖ | Cursor to start from. You can find cursors for next/previous pages in the meta.cursors property of the response. |
limit |
*int64 | ➖ | Number of results to return. Minimum 1, Maximum 200, Default 20 |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.VaultConsumersAllResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.BadRequestResponse | 400 | application/json |
apierrors.UnauthorizedResponse | 401 | application/json |
apierrors.PaymentRequiredResponse | 402 | application/json |
apierrors.NotFoundResponse | 404 | application/json |
apierrors.UnprocessableResponse | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Consumer detail including their aggregated counts with the connections they have authorized.
package main
import(
"context"
"os"
sdkgo "github.com/apideck-libraries/sdk-go"
"log"
)
func main() {
ctx := context.Background()
s := sdkgo.New(
sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
sdkgo.WithConsumerID("test-consumer"),
sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
)
res, err := s.Vault.Consumers.Get(ctx, "test_user_id")
if err != nil {
log.Fatal(err)
}
if res.GetConsumerResponse != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
consumerID |
string | ✔️ | ID of the consumer to return | test_user_id |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.VaultConsumersOneResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.BadRequestResponse | 400 | application/json |
apierrors.UnauthorizedResponse | 401 | application/json |
apierrors.PaymentRequiredResponse | 402 | application/json |
apierrors.NotFoundResponse | 404 | application/json |
apierrors.UnprocessableResponse | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Update consumer metadata such as name and email.
package main
import(
"context"
"os"
sdkgo "github.com/apideck-libraries/sdk-go"
"github.com/apideck-libraries/sdk-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := sdkgo.New(
sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
sdkgo.WithConsumerID("test-consumer"),
sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
)
res, err := s.Vault.Consumers.Update(ctx, "test_user_id", components.UpdateConsumerRequest{
Metadata: &components.ConsumerMetadata{
AccountName: sdkgo.String("SpaceX"),
UserName: sdkgo.String("Elon Musk"),
Email: sdkgo.String("[email protected]"),
Image: sdkgo.String("https://www.spacex.com/static/images/share.jpg"),
},
})
if err != nil {
log.Fatal(err)
}
if res.UpdateConsumerResponse != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
consumerID |
string | ✔️ | ID of the consumer to return | test_user_id |
updateConsumerRequest |
components.UpdateConsumerRequest | ✔️ | N/A | |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.VaultConsumersUpdateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.BadRequestResponse | 400 | application/json |
apierrors.UnauthorizedResponse | 401 | application/json |
apierrors.PaymentRequiredResponse | 402 | application/json |
apierrors.NotFoundResponse | 404 | application/json |
apierrors.UnprocessableResponse | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Delete consumer and all their connections, including credentials.
package main
import(
"context"
"os"
sdkgo "github.com/apideck-libraries/sdk-go"
"log"
)
func main() {
ctx := context.Background()
s := sdkgo.New(
sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
sdkgo.WithConsumerID("test-consumer"),
sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
)
res, err := s.Vault.Consumers.Delete(ctx, "test_user_id")
if err != nil {
log.Fatal(err)
}
if res.DeleteConsumerResponse != nil {
// handle response
}
}
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
consumerID |
string | ✔️ | ID of the consumer to return | test_user_id |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.VaultConsumersDeleteResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.BadRequestResponse | 400 | application/json |
apierrors.UnauthorizedResponse | 401 | application/json |
apierrors.PaymentRequiredResponse | 402 | application/json |
apierrors.NotFoundResponse | 404 | application/json |
apierrors.UnprocessableResponse | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |