graphcustom

package
v0.5.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByIDRequestUrlTemplate

func ByIDRequestUrlTemplate(reqConfig GetRequestConfig) string

ByIDRequestUrlTemplate constructs a URL template for a single resource request using the provided configuration. The function combines the endpoint path with a resource ID and optional suffix to create a complete URL template. For example, if the config contains:

  • Endpoint: "/deviceManagement/configurationPolicies"
  • ResourceIDPattern: "('id')"
  • ResourceID: "12345"
  • EndpointSuffix: "/settings"

The resulting template would be: "{+baseurl}/deviceManagement/configurationPolicies('12345')/settings"

Parameters:

  • reqConfig: GetRequestConfig containing the endpoint path, resource ID pattern, actual ID, and optional suffix

Returns:

  • string: The constructed URL template ready for use with the Kiota request adapter

func GetRequestByResourceId

func GetRequestByResourceId(ctx context.Context, adapter abstractions.RequestAdapter, reqConfig GetRequestConfig) (json.RawMessage, error)

GetRequestByResourceId performs a custom GET request using the Microsoft Graph SDK when the operation is not available in the generated SDK methods or when using raw json is easier to handle for response handling. This function supports both Beta and V1.0 Graph API versions and automatically handles OData pagination if present.

e.g., GET https://graph.microsoft.com/beta/deviceManagement/configurationPolicies('191056b1-4c4a-4871-8518-162a105d011a')/settings

The function handles: - Construction of the Graph API URL with proper formatting - Setting up the GET request with optional query parameters - Sending the request with proper authentication - Automatic pagination if the response is an OData response with a nextLink - Combining paginated results into a single response - Returning the raw JSON response

Parameters:

  • ctx: The context for the request, which can be used for cancellation and timeout
  • adapter: The request adapter for sending the request
  • config: GetRequestConfig containing:
  • APIVersion: The Graph API version to use (Beta or V1.0)
  • Endpoint: The resource endpoint path (e.g., "/deviceManagement/configurationPolicies")
  • ResourceID: The ID of the resource to retrieve
  • ResourceIDPattern: The format for the resource ID (e.g., "('id')" or "(id)")
  • EndpointSuffix: Optional suffix to append after the resource ID (e.g., "/settings")
  • QueryParameters: Optional query parameters for the request

Returns:

  • json.RawMessage: The raw JSON response from the GET request. For paginated responses, returns a combined response with all results in the "value" array
  • error: Returns nil if the request was successful, otherwise an error describing what went wrong

Example Usage:

config := GetRequestConfig{
	APIVersion:        GraphAPIBeta,
	Endpoint:         "/deviceManagement/configurationPolicies",
	ResourceID:       "d557c813-b8e5-4efc-b00e-9c0bd5fd10df",
	ResourceIDPattern: "('id')",
	EndpointSuffix:   "/settings",
	QueryParameters: map[string]string{
		"$expand": "children",
	},
}

response, err := GetRequestByResourceId(ctx, adapter, config)
if err != nil {
	log.Fatalf("Error: %v", err)
}

fmt.Printf("Response: %+v\n", response)

func PostRequest

func PostRequest(
	ctx context.Context,
	adapter abstractions.RequestAdapter,
	config PostRequestConfig,
	factory s.ParsableFactory,
	errorMappings abstractions.ErrorMappings,
) (s.Parsable, error)

PostRequest performs a custom POST request using the Microsoft Graph SDK when the operation is not available in the generated SDK methods. This function supports both Beta and V1.0 Graph API versions and returns the parsed response model.

Parameters:

  • ctx: The context for the request, which can be used for cancellation and timeout
  • adapter: The RequestAdapter interface for making HTTP requests
  • config: PostRequestConfig containing:
  • APIVersion: The Graph API version to use (Beta or V1.0)
  • Endpoint: The resource endpoint path
  • RequestBody: The body of the POST request implementing serialization.Parsable
  • QueryParameters: Optional map of query parameters
  • factory: The factory function to create the response model
  • errorMappings: Optional error mappings for custom error handling

Returns:

  • s.Parsable: The parsed response model
  • error: Any error that occurred during the request

func PostRequestNoContent

func PostRequestNoContent(ctx context.Context, adapter abstractions.RequestAdapter, config PostRequestConfig) error

PostRequestNoContent performs a custom POST request that doesn't expect a response body. This is useful for operations that return 204 No Content.

Parameters are the same as PostRequest except it doesn't take a responseModel parameter and uses the SendNoContent method of the adapter.

Returns:

  • error: Returns nil if the request was successful (204 No Content received), otherwise returns an error describing what went wrong

func PutRequestByResourceId

func PutRequestByResourceId(ctx context.Context, adapter abstractions.RequestAdapter, config PutRequestConfig) error

PutRequestByResourceId performs a custom PUT request using the Microsoft Graph SDK when the operation is not available in the generated SDK methods. This function supports both Beta and V1.0 Graph API versions and expects a 204 No Content response from the server on success.

e.g., PUT https://graph.microsoft.com/beta/deviceManagement/configurationPolicies('d557c813-b8e5-4efc-b00e-9c0bd5fd10df')

The function handles: - Construction of the Graph API URL with proper formatting - Setting up the PUT request with the provided request body - Sending the request with proper authentication - Error handling and return

Parameters:

  • ctx: The context for the request, which can be used for cancellation and timeout
  • clients: The GraphClients instance containing both Beta and V1.0 client configurations
  • config: CustomPutRequestConfig containing:
  • APIVersion: The Graph API version to use (Beta or V1.0)
  • Endpoint: The resource endpoint path (e.g., "deviceManagement/configurationPolicies")
  • ResourceID: The ID of the resource to update
  • RequestBody: The body of the PUT request implementing serialization.Parsable

Returns:

  • error: Returns nil if the request was successful (204 No Content received), otherwise returns an error describing what went wrong

Example Usage:

config := CustomPutRequestConfig{
    APIVersion: GraphAPIBeta,
    Endpoint:   "deviceManagement/configurationPolicies",
    ResourceID: "d557c813-b8e5-4efc-b00e-9c0bd5fd10df",
    RequestBody: myRequestBody,
}
err := PutRequestByResourceId(ctx, clients, config)

Types

type GetRequestConfig

type GetRequestConfig struct {
	// The API version to use (beta or v1.0)
	APIVersion GraphAPIVersion
	// The base endpoint (e.g., "deviceManagement/configurationPolicies")
	Endpoint string
	// The endpoint suffix appended after the ID (e.g., "/settings"). Optional.
	EndpointSuffix string
	// The resource ID syntax format (e.g., "('id')" or "(id)")
	ResourceIDPattern string
	// The ID of the resource
	ResourceID string
	// Optional query parameters to include in the request
	QueryParameters map[string]string
}

GetRequestConfig contains the configuration for a custom GET request

type GraphAPIVersion

type GraphAPIVersion string

GraphAPIVersion represents Microsoft Graph API version

const (
	GraphAPIBeta GraphAPIVersion = "beta"
	GraphAPIV1   GraphAPIVersion = "v1.0"
)

type ODataResponse

type ODataResponse struct {
	// Value is the array of JSON messages returned by the request
	Value []json.RawMessage `json:"value"`
	//  NextLink is the URL for the next page of results used by pagination
	NextLink string `json:"@odata.nextLink,omitempty"`
}

ODataResponse represents the structure of an OData response

type PostRequestConfig

type PostRequestConfig struct {
	// The API version to use (beta or v1.0)
	APIVersion GraphAPIVersion
	// The base endpoint (e.g., "/deviceManagement/configurationPolicies")
	Endpoint string
	// The request body
	RequestBody s.Parsable
	// Optional query parameters for the request
	QueryParameters map[string]string
}

PostRequestConfig contains the configuration for a custom POST request

type PutRequestConfig

type PutRequestConfig struct {
	// The API version to use (beta or v1.0)
	APIVersion GraphAPIVersion
	// The base endpoint (e.g., "/deviceManagement/configurationPolicies")
	Endpoint string
	// The ID of the resource
	ResourceID string
	// The request body
	RequestBody s.Parsable
}

PutRequestConfig contains the configuration for a custom PUT request

type PutResponse

type PutResponse struct {
	StatusCode int
	Error      error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL