Back to Collection Items
var
http: HCkHttp;
success: Boolean;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
expirationDate: PWideChar;
fileViewUrl: PWideChar;
isPasswordRequired: Boolean;
password: PWideChar;
sharingType: PWideChar;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');
resp := CkHttp_QuickRequest(http,'PUT','https://domain.com/services/data/v{{version}}/connect/files/:FILE_ID/file-shares/link');
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));
respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkHttpResponse__header(resp));
Memo1.Lines.Add('Failed.');
CkHttpResponse_Dispose(resp);
Exit;
end;
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "expirationDate": null,
// "fileViewUrl": "https://<my_domain>/sfc/p/2o000000i6mB/a/2o00000022S3/y2zsu9pHtEVIa49w6ElaXdjXz_GxBSzRVwe645_Z.dw",
// "isPasswordRequired": false,
// "password": null,
// "sharingType": "V"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
expirationDate := CkJsonObject__stringOf(jResp,'expirationDate');
fileViewUrl := CkJsonObject__stringOf(jResp,'fileViewUrl');
isPasswordRequired := CkJsonObject_BoolOf(jResp,'isPasswordRequired');
password := CkJsonObject__stringOf(jResp,'password');
sharingType := CkJsonObject__stringOf(jResp,'sharingType');
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/connect/files/:FILE_ID/file-shares/link
Postman Collection Item JSON
{
"name": "Files Shares Link",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disabledSystemHeaders": {}
},
"request": {
"method": "PUT",
"header": [
],
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/connect/files/:FILE_ID/file-shares/link",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"connect",
"files",
":FILE_ID",
"file-shares",
"link"
],
"variable": [
{
"key": "FILE_ID",
"value": ""
}
]
},
"description": "A description of a file shared as a link. Create, access, and delete a file’s share link.\n\nhttps://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_files_shares_link.htm"
},
"response": [
{
"name": "Successful Files Shares Link",
"originalRequest": {
"method": "PUT",
"header": [
],
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/connect/files/:FILE_ID/file-shares/link",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"connect",
"files",
":FILE_ID",
"file-shares",
"link"
],
"variable": [
{
"key": "FILE_ID",
"value": "0692o00000woaRkAAI"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Mon, 20 Nov 2023 16:38:31 GMT"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=63072000; includeSubDomains"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Robots-Tag",
"value": "none"
},
{
"key": "Cache-Control",
"value": "no-cache,must-revalidate,max-age=0,no-store,private"
},
{
"key": "Content-Type",
"value": "application/json;charset=UTF-8"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"expirationDate\": null,\n \"fileViewUrl\": \"https://<my_domain>/sfc/p/2o000000i6mB/a/2o00000022S3/y2zsu9pHtEVIa49w6ElaXdjXz_GxBSzRVwe645_Z.dw\",\n \"isPasswordRequired\": false,\n \"password\": null,\n \"sharingType\": \"V\"\n}"
}
]
}