Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Activix CRM Upload a Recording
See more Activix CRM Examples
Upload a recording for an existing communication.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.HttpRequest,
Chilkat.HttpResponse,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
req: THttpRequest;
pathToFileOnDisk: string;
http: THttp;
resp: THttpResponse;
jsonResponse: TJsonObject;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
req := THttpRequest.Create;
req.HttpVerb := 'POST';
req.Path := '/api/v2/communications/COMMUNICATION_ID/recording';
req.ContentType := 'multipart/form-data';
req.AddHeader('Accept','application/json');
pathToFileOnDisk := 'qa_data/CantinaBand3.wav';
success := req.AddFileForUpload('recording',pathToFileOnDisk);
if (success = False) then
begin
WriteLn(req.LastErrorText);
Exit;
end;
http := THttp.Create;
http.AuthToken := 'ACCESS_TOKEN';
resp := THttpResponse.Create;
success := http.HttpSReq('crm.activix.ca',443,True,req,resp);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
WriteLn('Response Status Code: ' + resp.StatusCode);
jsonResponse := TJsonObject.Create;
jsonResponse.Load(resp.BodyStr);
jsonResponse.EmitCompact := False;
WriteLn(jsonResponse.Emit());
if (resp.StatusCode >= 300) then
begin
WriteLn('Failed.');
Exit;
end;
// Sample output...
// {
// "message": "Recording uploaded successfully."
// }
//
req.Free;
http.Free;
resp.Free;
jsonResponse.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.