graphcustom

package
v0.11.0-alpha Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 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 RequestUrlTemplateConfig) 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 DeleteRequestByResourceId

func DeleteRequestByResourceId(ctx context.Context, adapter abstractions.RequestAdapter, reqConfig DeleteRequestConfig) error

DeleteRequestByResourceId performs a custom DELETE request using the Microsoft Graph SDK when the operation is not available in the generated SDK methods.

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

Parameters:

  • ctx: The context for the request, which can be used for cancellation and timeout
  • adapter: The request adapter for sending the request
  • config: DeleteRequestConfig 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 delete
  • ResourceIDPattern: The format for the resource ID (e.g., "('id')" or "(id)")
  • EndpointSuffix: Optional suffix to append after the resource ID

Returns:

  • error: Returns nil if the delete was successful, otherwise an error describing what went wrong

Example Usage:

config := DeleteRequestConfig{
	APIVersion:        GraphAPIBeta,
	Endpoint:         "deviceManagement/reusablePolicySettings",
	ResourceID:       "4f93da7a-431b-4d48-bbce-1660aa8b0be7",
	ResourceIDPattern: "('id')",
}

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

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 PatchRequestByResourceId

func PatchRequestByResourceId(ctx context.Context, adapter abstractions.RequestAdapter, config PatchRequestConfig) error

PatchRequestByResourceId performs a custom PATCH 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., PATCH https://graph.microsoft.com/beta/deviceManagement/deviceCategories('d557c813-b8e5-4efc-b00e-9c0bd5fd10df')

The function handles: - Construction of the Graph API URL with proper formatting - Setting up the PATCH 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
  • adapter: The RequestAdapter instance containing client configurations
  • config: PatchRequestConfig containing:
  • APIVersion: The Graph API version to use (Beta or V1.0)
  • Endpoint: The resource endpoint path (e.g., "deviceManagement/deviceCategories")
  • ResourceID: The ID of the resource to update
  • ResourceIDPattern: The pattern for formatting the resource ID (e.g., "/{id}" or "('id')")
  • EndpointSuffix: Optional suffix to append after the ID
  • RequestBody: The body of the PATCH 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 := PatchRequestConfig{
    APIVersion: GraphAPIBeta,
    Endpoint:   "/deviceManagement/deviceCategories",
    ResourceIDPattern: "/{id}",
    ResourceID: "d557c813-b8e5-4efc-b00e-9c0bd5fd10df",
    RequestBody: myRequestBody,
}
err := PatchRequestByResourceId(ctx, adapter, config)

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 DeleteRequestConfig

type DeleteRequestConfig 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
}

DeleteRequestConfig contains the configuration for a custom DELETE request

func (DeleteRequestConfig) GetEndpoint

func (d DeleteRequestConfig) GetEndpoint() string

func (DeleteRequestConfig) GetEndpointSuffix

func (d DeleteRequestConfig) GetEndpointSuffix() string

func (DeleteRequestConfig) GetResourceID

func (d DeleteRequestConfig) GetResourceID() string

func (DeleteRequestConfig) GetResourceIDPattern

func (d DeleteRequestConfig) GetResourceIDPattern() string

DeleteRequestConfig implements RequestUrlConfig interface

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

func (GetRequestConfig) GetEndpoint

func (g GetRequestConfig) GetEndpoint() string

func (GetRequestConfig) GetEndpointSuffix

func (g GetRequestConfig) GetEndpointSuffix() string

func (GetRequestConfig) GetResourceID

func (g GetRequestConfig) GetResourceID() string

func (GetRequestConfig) GetResourceIDPattern

func (g GetRequestConfig) GetResourceIDPattern() string

GetRequestConfig implements RequestUrlConfig interface

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 PatchRequestConfig

type PatchRequestConfig struct {
	// The API version to use (beta or v1.0)
	APIVersion GraphAPIVersion
	// The base endpoint (e.g., "/deviceManagement/deviceCategories")
	Endpoint string
	// The ID of the resource
	ResourceID string
	// Pattern for the resource ID (e.g., "/{id}" or "('id')")
	ResourceIDPattern string
	// Optional suffix to append after the ID
	EndpointSuffix string
	// The request body
	RequestBody s.Parsable
}

PatchRequestConfig contains the configuration for a custom PATCH request

func (PatchRequestConfig) GetEndpoint

func (p PatchRequestConfig) GetEndpoint() string

func (PatchRequestConfig) GetEndpointSuffix

func (p PatchRequestConfig) GetEndpointSuffix() string

func (PatchRequestConfig) GetResourceID

func (p PatchRequestConfig) GetResourceID() string

func (PatchRequestConfig) GetResourceIDPattern

func (p PatchRequestConfig) GetResourceIDPattern() string

Implement RequestUrlTemplateConfig interface for PatchRequestConfig

type PatchResponse

type PatchResponse struct {
	StatusCode int
	Error      error
}

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
	// Optional: the reference URL for ODATA - e.g. "https://graph.microsoft.com/beta/deviceAppManagement/mobileAppCategories/abc"
	ReferenceURL 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
}

type RequestUrlTemplateConfig

type RequestUrlTemplateConfig interface {
	GetResourceIDPattern() string
	GetResourceID() string
	GetEndpoint() string
	GetEndpointSuffix() string
}

RequestUrlTemplateConfig interface defines the common fields needed for building URLs

Jump to

Keyboard shortcuts

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