Sample code for 30+ languages & platforms
PowerBuilder

Create a New Table in an Azure Storage Account

See more Azure Table Service Examples

Creates a new table using the Azure Table Service REST API.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_AzAuth
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
string ls_Odata_metadata
string ls_Odata_type
string ls_Odata_id
string ls_Odata_editLink
string ls_TableName

li_Success = 0

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

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Implements the following CURL command:

// curl -X POST \
//   -H "Content-Type: application/json" \
//   -H "Accept: application/json;odata=fullmetadata" \
//   -H "Prefer: return-content" \
//   -d '{   
//     "TableName":"mytable"  
// }' https://myaccount.table.core.windows.net/Tables

// Use the following online tool to generate REST code from a CURL command
// Convert a cURL Command to REST Source Code

// IMPORTANT: Make sure to change "myaccount" to your actual Azure Storage Account name.
// URL: https://myaccount.table.core.windows.net/Tables
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("myaccount.table.core.windows.net",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

// Provide Azure Cloud credentials for the REST call.
loo_AzAuth = create oleobject
li_rc = loo_AzAuth.ConnectToNewObject("Chilkat.AuthAzureStorage")

loo_AzAuth.AccessKey = "AZURE_ACCESS_KEY"
// The account name used here should match the 1st part of the domain passed in the call to Connect (above).
loo_AzAuth.Account = "myaccount"
loo_AzAuth.Scheme = "SharedKey"
loo_AzAuth.Service = "Table"

// This causes the "x-ms-version: 2019-07-07" header to be automatically added.
loo_AzAuth.XMsVersion = "2019-07-07"
li_Success = loo_Rest.SetAuthAzureStorage(loo_AzAuth)

// Note: The application does not need to explicitly set the following
// headers: Content-Length, x-ms-date, Authorization.  These headers
// are automatically set by Chilkat.

// Note: The above code does not need to be repeatedly called for each REST request.
// The rest object can be setup once, and then many requests can be sent.  Chilkat will automatically
// reconnect within a FullRequest* method as needed.  It is only the very first connection that is explicitly
// made via the Connect method.

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

// The following JSON is sent in the request body.

// {
//   "TableName": "mytable"
// }

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

loo_Json.UpdateString("TableName","mytable")

loo_Rest.AddHeader("Accept","application/json;odata=fullmetadata")
loo_Rest.AddHeader("Prefer","return-content")
loo_Rest.AddHeader("Content-Type","application/json")

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Rest.FullRequestSb("POST","/Tables",loo_SbRequestBody,loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
    Write-Debug "Response Status Code = " + string(li_RespStatusCode)
    Write-Debug "Response Header:"
    Write-Debug loo_Rest.ResponseHeader
    Write-Debug "Response Body:"
    Write-Debug loo_SbResponseBody.GetAsString()
    destroy loo_Rest
    destroy loo_AzAuth
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

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

loo_JsonResponse.LoadSb(loo_SbResponseBody)

loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()

ls_Odata_metadata = loo_JsonResponse.StringOf("~"odata.metadata~"")
ls_Odata_type = loo_JsonResponse.StringOf("~"odata.type~"")
ls_Odata_id = loo_JsonResponse.StringOf("~"odata.id~"")
ls_Odata_editLink = loo_JsonResponse.StringOf("~"odata.editLink~"")
ls_TableName = loo_JsonResponse.StringOf("TableName")


destroy loo_Rest
destroy loo_AzAuth
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JsonResponse