Enables integration with Microsoft Graph.
The component handles authentication and HTTP requests, but you will need to refer to the the Graph API documentation to learn how each API is used. The Graph Explorer is also a valuable tool for experimenting with Graph APIs.
The system settings GraphDefaultTenantId and GraphDefaultCredentials may be used to set defaults for the credentials used to access Graph.
Used to dynamically overwrite the default authorization settings and credentials and to set a batch id.
Gets the initial commands to be performed by the component.
Possible value | Description |
---|---|
DELETE | |
GET | |
PATCH | |
POST | |
PUT |
Possible value | Description |
---|---|
beta | |
v1.0 |
Specifies custom request headers to send with the call. See the API documentation for each individual call to determine which, if any, headers it accepts. The Authorization header is automatically set by the component.
You can not specify any Content-* headers in this call. Those are specified by the Request data call instead.
Called once for each command. This call can optionally emit new commands to perform.
Possible value | Description |
---|---|
<XXX> | Any error code from Microsoft Graph |
Softadmin_ApplicationThrottled | The component tried to make a call disregarding previous returned @RetryAfter. The call has been ignored. |
Possible value | Description |
---|---|
DELETE | |
GET | |
PATCH | |
POST | |
PUT |
Possible value | Description |
---|---|
beta | |
v1.0 |
Call made when all commands have finished.
Deprecated. Use ADMIN_CancelMenuItem instead.
Id of the menuitem to execute if the user clicks Cancel in an ADMIN_FORCE dialog (the default being none). This value overrides cancelmenuitemid specified in the query string.
Alias of the menu group to show after execution (instead of former menu item). This value overrides any destination specified by the query string.
Deprecated. Use ADMIN_ForwardMenuGroup instead.
Id of the menu group to show after execution (instead of former menu item). This value overrides any destination specified by the query string.
Deprecated. Use ADMIN_ForwardMenuItem instead.
Id of the menu item to execute after execution (instead of former menu item). This value overrides any destination specified by the query string.
Displays a user friendly error message to the user.
Allows you to validate the parameters supplied by the user before any other SQL is run in the component. This call is only made if the component has visible parameters, the SQL is a stored procedure, and Validate parameters is checked.
Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.
Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.
The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.
If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.
CREATE OR ALTER PROCEDURE [Example].[Graph]
@Action varchar(max) = NULL,
@Id varchar(max) = NULL,
@ResponseJson nvarchar(max) = NULL,
@HttpStatusCode int = NULL,
@ErrorMessage varchar(max) = NULL,
@ErrorCode varchar(max) = NULL,
@RetryAfterUtc datetime2(2) = NULL
AS
BEGIN
SET XACT_ABORT ON;
IF @Action = 'Init'
BEGIN
RETURN;
END;
IF @Action = 'Commands'
BEGIN
SELECT
GC.Path AS Path,
'v1.0' AS ApiVersion,
GC.HttpMethod AS HttpMethod,
NULL AS BeginExtraParams,
GC.GraphCommandQueueId AS Id
FROM
dbo.GraphCommandQueue GC
LEFT JOIN (SELECT MAX(GS.RetryAfter) AS RetryAfter FROM dbo.GraphState GS) S ON 1 = 1
WHERE
SYSDATETIME() > ISNULL(S.RetryAfter, '1900');
RETURN;
END;
IF @Action = 'RequestData'
BEGIN
SELECT
GC.RequestJson
FROM
dbo.GraphCommandQueue GC
WHERE
GC.GraphCommandQueueId = @Id;
RETURN;
END;
IF @Action = 'StoreResponse'
BEGIN
BEGIN TRAN;
DELETE dbo.GraphState;
IF @RetryAfter IS NOT NULL
BEGIN
INSERT INTO dbo.GraphState
(
RetryAfter
)
VALUES
(
@RetryAfter
);
END;
COMMIT;
BEGIN TRAN;
IF @HttpStatusCode = 2XX
BEGIN
DELETE dbo.GraphCommandQueue
WHERE
GraphCommandQueueId = @Id;
END;
ELSE
BEGIN
UPDATE dbo.GraphCommandQueue SET
ResponseJson = @ResponseJson,
ErrorCode = @ErrorCode,
ErrorMessage = @ErrorMessage,
HttpStatusCode = @HttpStatusCode
WHERE
GraphCommandQueueId = @Id;
DECLARE @LogMessage varchar(max) =
CONCAT('Error occured when performing Action for dbo.GraphCommandQueue: GraphCommandQueueId:', @Id);
EXEC SoftadminApi.Log_LogError
@LogMessage = @LogMessage;
END;
COMMIT;
RETURN;
END;
IF @Action = 'Finished'
BEGIN
RETURN;
END;
END;
CREATE OR ALTER PROCEDURE Example.SyncPhotosFromGraph
@Action varchar(50),
@UserId int = NULL,
@HttpStatusCode int = NULL,
@ResponseJson varchar(max) = NULL,
@ResponseBinary varbinary(max) = NULL,
@ErrorCode varchar(300) = NULL,
@ErrorMessage varchar(max) = NULL,
@RetryAfterUtc datetime2(0) = NULL
AS
BEGIN
IF @Action = 'Init'
BEGIN
RETURN;
END;
IF @Action = 'Commands'
BEGIN
SELECT
'GET' AS HttpMethod,
CONCAT(
'/users/',
U.Username,
'/photos/64x64/$value'
) AS Path,
'/v1.0' AS ApiVersion,
1 AS SendCustomRequestHeaders,
1 AS ReceiveResponseHeaders,
1 AS ResponseIsBinary,
NULL AS BeginExtraParams,
U.UserId
FROM
SoftadminApi.[User] U
WHERE
U.IsEnabled = 1 AND
U.Username LIKE '%@%' AND
1=1; -- Add your own logic for deciding which users to sync here.
RETURN;
END;
IF @Action = 'RequestData'
BEGIN
RETURN;
END;
IF @Action = 'RequestHeaders'
BEGIN
-- Only fetch changed profile pictures.
SELECT
'If-None-Match' AS HttpHeaderName,
ETag AS HttpHeaderValue
FROM
SoftadminApi.UserPhoto
WHERE
UserId = @UserId;
RETURN;
END;
IF @Action = 'StoreResponse'
BEGIN
IF @HttpStatusCode = 304
BEGIN
-- The photo is unchanged since previous sync.
RETURN;
END;
IF @HttpStatusCode = 200
BEGIN
DECLARE
@ResponseContentType varchar(300) = (SELECT HttpHeaderValue FROM #ResponseHeaders WHERE HttpHeaderName = 'content-type'),
@ResponseETag varchar(300) = (SELECT HttpHeaderValue FROM #ResponseHeaders WHERE HttpHeaderName = 'etag');
BEGIN TRANSACTION;
DELETE SoftadminApi.UserPhoto WHERE UserId = @UserId;
INSERT SoftadminApi.UserPhoto
(
UserId,
UserPhoto,
UserPhotoContentType,
ETag,
UpdateDatetime
)
VALUES
(
@UserId,
@ResponseBinary,
@ResponseContentType,
@ResponseETag,
SYSDATETIMEOFFSET()
);
COMMIT TRANSACTION;
RETURN;
END;
IF @HttpStatusCode = 404
BEGIN
-- The user does not exist or does not have a photo.
RETURN;
END;
IF @HttpStatusCode BETWEEN 400 AND 599
BEGIN
-- Log unexpected errors.
DECLARE @LogMessage varchar(MAX) = CONCAT('Graph returned an error when fetching photo: ', @ErrorCode);
EXEC SoftadminApi.Log_LogError
@LogMessage = @LogMessage,
@LogTrace = @ErrorMessage,
@MenuItemId = 123; -- Use your own menu item id.
END;
RETURN;
END;
IF @ErrorCode IS NOT NULL OR @ErrorMessage IS NOT NULL
BEGIN
RAISERROR('%s %s', 16, 1,@ErrorCode, @ErrorMessage);
END;
END;