Visual Basic 6.0 Google Cloud Storage: Create Bucket

Back to Index

Creates a new bucket.

Documentation: https://cloud.google.com/storage/docs/json_api/v1/buckets/insert

CURL Command

curl -X POST https://www.googleapis.com/storage/v1/b?project=MY_CLOUD_STORAGE_PROJECT \
    --header "Authorization: Bearer CLOUD_STORAGE_TOKEN" \
    --header "Content-Type: application/json" \
    --data '{"name": "chilkat-test-bucket"}'

Visual Basic 6.0 Example

Dim rest As New ChilkatRest
Dim success As Long

'  URL: https://www.googleapis.com/storage/v1/b?project=MY_CLOUD_STORAGE_PROJECT
Dim bTls As Long
bTls = 1
Dim port As Long
port = 443
Dim bAutoReconnect As Long
bAutoReconnect = 1
success = rest.Connect("www.googleapis.com",port,bTls,bAutoReconnect)
If (success <> 1) Then
    Debug.Print "ConnectFailReason: " & rest.ConnectFailReason
    Debug.Print rest.LastErrorText
    Exit Sub
End If

'  See the Online Tool for Generating JSON Creation Code
Dim json As New ChilkatJsonObject
success = json.UpdateString("name","chilkat-test-bucket")

success = rest.AddHeader("Authorization","Bearer CLOUD_STORAGE_TOKEN")
success = rest.AddHeader("Content-Type","application/json")

Dim sbRequestBody As New ChilkatStringBuilder
success = json.EmitSb(sbRequestBody)
Dim sbResponseBody As New ChilkatStringBuilder
success = rest.FullRequestSb("POST","/storage/v1/b?project=MY_CLOUD_STORAGE_PROJECT",sbRequestBody,sbResponseBody)
If (success <> 1) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

Dim respStatusCode As Long
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Status Code = " & respStatusCode
    Debug.Print "Response Header:"
    Debug.Print rest.ResponseHeader
    Debug.Print "Response Body:"
    Debug.Print sbResponseBody.GetAsString()
    Exit Sub
End If

Dim jsonResponse As New ChilkatJsonObject
success = jsonResponse.LoadSb(sbResponseBody)

'  See the Online Tool for Generating JSON Parse Code

Dim kind As String
kind = jsonResponse.StringOf("kind")
Dim id As String
id = jsonResponse.StringOf("id")
Dim selfLink As String
selfLink = jsonResponse.StringOf("selfLink")
Dim projectNumber As String
projectNumber = jsonResponse.StringOf("projectNumber")
Dim name As String
name = jsonResponse.StringOf("name")
Dim timeCreated As String
timeCreated = jsonResponse.StringOf("timeCreated")
Dim updated As String
updated = jsonResponse.StringOf("updated")
Dim metageneration As String
metageneration = jsonResponse.StringOf("metageneration")
Dim location As String
location = jsonResponse.StringOf("location")
Dim storageClass As String
storageClass = jsonResponse.StringOf("storageClass")
Dim etag As String
etag = jsonResponse.StringOf("etag")

Sample JSON Response Body

{
  "kind": "storage#bucket",
  "id": "chilkat-test-bucket",
  "selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-test-bucket",
  "projectNumber": "5332332985",
  "name": "chilkat-test-bucket",
  "timeCreated": "2018-10-23T11:52:52.464Z",
  "updated": "2018-10-23T11:52:52.464Z",
  "metageneration": "1",
  "location": "US",
  "storageClass": "STANDARD",
  "etag": "CAE="
}