Xbase++
Xbase++
OpenAI (ChatGPT) Delete File
See more OpenAI ChatGPT Examples
Show how to delete a file from a user organization's OpenAI files.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cId
LOCAL cV_object
LOCAL nDeleted
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Implements the following CURL command:
// curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \
// -X DELETE \
// -H "Authorization: Bearer $OPENAI_API_KEY"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Adds the "Authorization: Bearer $OPENAI_API_KEY" header.
// This is NOT a real key. Change the "sk-vi...." to your own key.
oHttp:AuthToken := "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"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("DELETE", "https://api.openai.com/v1/files/file-gFg12JZEpenPTF7Nb8jXgH1B", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
RETURN
ENDIF
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oResp:Header
? "Failed."
oHttp:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": "file-XjGxS3KTG0uNmNOK362iJua3",
// "object": "file",
// "deleted": true
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
cId := oJResp:StringOf("id")
cV_object := oJResp:StringOf("object")
nDeleted := oJResp:BoolOf("deleted")
oHttp:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()