Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Microsoft Graph -- List Users

See more Microsoft Graph Examples

Retrieve a list of Microsoft Graph user objects.

For more information, see https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Variant vReq
    Handle hoReq
    String sUrl
    Variant vResp
    Handle hoResp
    Integer iStatusCode
    Handle hoJson
    Boolean iSuccess
    Variant vSbResponse
    Handle hoSbResponse
    Boolean iSuccess
    String sOdata_id
    String sDisplayName
    String sGivenName
    String sJobTitle
    String sMail
    String sMobilePhone
    String sOfficeLocation
    String sPreferredLanguage
    String sSurname
    String sUserPrincipalName
    String sId
    Integer j
    Integer iCount_j
    String sOdata_context
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Get an access token with the required scope using client credentials...
    // See How to Create Microsoft Graph App (in Azure Portal) for Client Credentials Authentication
    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Send ComAddParam To hoReq "client_secret" "CLIENT_SECRET"
    Send ComAddParam To hoReq "client_id" "CLIENT_ID"
    Send ComAddParam To hoReq "scope" "https://graph.microsoft.com/.default"
    Send ComAddParam To hoReq "grant_type" "client_credentials"

    // Use your own tenant ID, for example 4d8fdd66-66d1-43b0-ae5c-e31b4b7de5cd
    Move "https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token" To sUrl
    Get pvComObject of hoReq to vReq
    Get ComPostUrlEncoded Of hoHttp sUrl vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iStatusCode
    Showln "Response status code = " iStatusCode

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoad Of hoJson sTemp1 To iSuccess
    Send Destroy of hoResp

    // -----------------------------------------------------
    // Use the access token obtained from above.
    // Note: We don't need to re-fetch a new access token every time.  An access token is valid 
    // for some amount of time, typically an hour (3600 seconds)

    // Use your previously obtained access token here:
    Get ComStringOf Of hoJson "access_token" To sTemp1
    Set ComAuthToken Of hoHttp To sTemp1

    Get ComAuthToken Of hoHttp To sTemp1
    Showln "access token: " sTemp1

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse
    If (Not(IsComObjectCreated(hoSbResponse))) Begin
        Send CreateComObject of hoSbResponse
    End

    Get pvComObject of hoSbResponse to vSbResponse
    Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/users" vSbResponse To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoSbResponse to vSbResponse
    Get ComLoadSb Of hoJson vSbResponse To iSuccess
    Set ComEmitCompact Of hoJson To False

    Get ComLastStatus Of hoHttp To iTemp1
    Showln "Status code = " iTemp1
    Get ComLastStatus Of hoHttp To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComEmit Of hoJson To sTemp1
        Showln sTemp1
        Showln "Failed."
    End

    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1

    // Sample output
    // {
    //   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
    //   "value": [
    //     {
    //       "@odata.id": "https://graph.microsoft.com/v2/6d8ddd66-68d1-43b0-af5c-e31b4b7dd5cd/directoryObjects/fca490d8-5918-4201-8079-c5dcbeafcdc9/Microsoft.DirectoryServices.User",
    //       "businessPhones": [
    //       ],
    //       "displayName": "Joe Sample",
    //       "givenName": "Joe",
    //       "jobTitle": null,
    //       "mail": null,
    //       "mobilePhone": null,
    //       "officeLocation": null,
    //       "preferredLanguage": null,
    //       "surname": "Sample",
    //       "userPrincipalName": "admin_chilkatsoft.com#EXT#@adminchilkatsoft.onmicrosoft.com",
    //       "id": "fca490d8-5918-4201-8079-c5dcbeafcdc9"
    //     }
    //   ]
    // }

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    Get ComStringOf Of hoJson '"@odata.context"' To sOdata_context
    Move 0 To i
    Get ComSizeOfArray Of hoJson "value" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJson To i
        Get ComStringOf Of hoJson 'value[i]."@odata.id"' To sOdata_id
        Get ComStringOf Of hoJson "value[i].displayName" To sDisplayName
        Get ComStringOf Of hoJson "value[i].givenName" To sGivenName
        Get ComStringOf Of hoJson "value[i].jobTitle" To sJobTitle
        Get ComStringOf Of hoJson "value[i].mail" To sMail
        Get ComStringOf Of hoJson "value[i].mobilePhone" To sMobilePhone
        Get ComStringOf Of hoJson "value[i].officeLocation" To sOfficeLocation
        Get ComStringOf Of hoJson "value[i].preferredLanguage" To sPreferredLanguage
        Get ComStringOf Of hoJson "value[i].surname" To sSurname
        Get ComStringOf Of hoJson "value[i].userPrincipalName" To sUserPrincipalName
        Get ComStringOf Of hoJson "value[i].id" To sId
        Move 0 To j
        Get ComSizeOfArray Of hoJson "value[i].businessPhones" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJson To j
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop



End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.