Sample code for 30+ languages & platforms
PowerBuilder

curl with use of Local Manager Secrets for Credentials

See more CURL Examples

This example demonstrates how to retrieve secrets from the local credential manager instead of embedding them directly in your source code.

On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Sb
oleobject loo_JsonOAuth2
oleobject loo_HttpCurl
oleobject loo_ResponseJson
integer li_StatusCode

li_Success = 0

// This example will run the following curl command

// curl -X GET "https://graph.microsoft.com/v1.0/sites/{{sharepoint_hostname}}:/sites/{{site_name}}" \
//   -H "Authorization: Bearer ACCESS_TOKEN" \
//   -H "Accept: application/json"

loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_Sb
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Sb.AppendLn("curl -X GET ~"https://graph.microsoft.com/v1.0/sites/{{sharepoint_hostname}}:/sites/{{site_name}}~" ~")
loo_Sb.AppendLn("  -H ~"Authorization: Bearer ACCESS_TOKEN~" ~")
loo_Sb.AppendLn("  -H ~"Accept: application/json~"")

// Build the JSON that provides information for getting the OAuth2 access token using the OAuth2 client credentials flow.
loo_JsonOAuth2 = create oleobject
li_rc = loo_JsonOAuth2.ConnectToNewObject("Chilkat.JsonObject")

// The notation "!!sharepoint|oauth2|client_id" is a secrets specification string 
// that can have up to 4 components: !!appName|service|domain|username
// where appName and domain are optional.
// See Chilkat v11.5.0 — Secrets Integration
// Also see: Chilkat Secrets API

// The following example shows how to store (or update) the secrets used in this example
// Storing Secrets in the Local Manager

// We must enable secrets integration for Chilkat to auto-resolve when the string begins with "!!".
loo_JsonOAuth2.EnableSecrets = 1
loo_JsonOAuth2.UpdateString("oauth2.client_id","!!sharepoint|oauth2|client_id")
loo_JsonOAuth2.UpdateString("oauth2.client_secret","!!sharepoint|oauth2|client_secret")
loo_JsonOAuth2.UpdateString("oauth2.scope","https://graph.microsoft.com/.default")
loo_JsonOAuth2.UpdateString("oauth2.token_endpoint","!!sharepoint|oauth2|token_endpoint")

loo_HttpCurl = create oleobject
li_rc = loo_HttpCurl.ConnectToNewObject("Chilkat.HttpCurl")

// Provide the information for getting the OAuth2 access token from the token endpoint
// Note: The Authorization header specified in the curl command will be ignored and replaced using the OAuth2 access token obtained at runtime from the token endpoint.
loo_HttpCurl.SetAuth(loo_JsonOAuth2)

// The placeholders {{sharepoint_hostname}} and {{site_name}} represent variables that must be defined before execution.
// When DoYourThing runs the curl command, it automatically substitutes these placeholders with their corresponding values.
// Below are the values assigned to these variables:
loo_HttpCurl.SetVar("sharepoint_hostname","example.sharepoint.com")
loo_HttpCurl.SetVar("site_name","test")

// Run the curl command.
li_Success = loo_HttpCurl.DoYourThing(loo_Sb.GetAsString())
if li_Success = 0 then
    Write-Debug loo_HttpCurl.LastErrorText
    destroy loo_Sb
    destroy loo_JsonOAuth2
    destroy loo_HttpCurl
    return
end if

loo_ResponseJson = create oleobject
li_rc = loo_ResponseJson.ConnectToNewObject("Chilkat.JsonObject")

loo_ResponseJson.EmitCompact = 0

loo_HttpCurl.GetResponseJson(loo_ResponseJson)

li_StatusCode = loo_HttpCurl.StatusCode
Write-Debug "response status code: " + string(li_StatusCode)

Write-Debug loo_ResponseJson.Emit()


destroy loo_Sb
destroy loo_JsonOAuth2
destroy loo_HttpCurl
destroy loo_ResponseJson