# Utils methods

## Utils methods

Utils are available for you to avoid direct access to our rest API and an integrated usage directly from the SharinPix package in Apex from Salesforce.

Methods

* [renameAlbum](#renamealbum)
* [duplicateAlbum](#duplicatealbum)
* [getAlbumImages](#getalbumimages)
* [getImageDetails](#getimagedetails)
* [duplicateImageToAlbum](#duplicateimagetoalbum)
* [duplicateImages](#duplicateimages)
* [getImageUrl](#getimageurl)
* [getImageEndpoint](#getimageendpoint)
* [croppedImageUrl](#croppedimageurl)
* [getImageExternalUrls](#getimageexternalurls)
* [getOrgTags](#getorgtags)
* [getAlbumTagImages](#getalbumtagimages)
* [getTagsOnImage](#gettagsonimage)
* [getTagNamesOnImage](#gettagnamesonimage)
* [addTag](#addtag)
* [removeTags](#removetags)
* [clearTags](#cleartags)
* [uploadAttachment](#uploadattachment)
* [uploadContentDocument](#uploadcontentdocument)
* [uploadFromUrl](#uploadfromurl)
* [uploadWebshot](#uploadwebshot)
* [generateMobileAppUrl](#generatemobileappurl)
* [splitToken](#splittoken)
* [getAlbumImageIds](#getalbumimageids)
* [deleteImage](#deleteimage)
* [deleteImages](#deleteimages)
* [updateSessionIdValidity](#sessionidvalidity)
* [createContentDocumentFromUrl](#createcontentdocumentfromurl)

### Utils Method Example <a href="#example" id="example"></a>

### renameAlbum <a href="#renamealbum" id="renamealbum"></a>

*global Boolean **renameAlbum**(String **oldAlbumId**, String **newAlbumId**)*

* *Renames an album.*

#### renameAlbum <a href="#renamealbum_1" id="renamealbum_1"></a>

*global Boolean **renameAlbum**(String **oldAlbumId**, String **newAlbumId**, Boolean **mergeAlbum**)*<br>

* *Renames an album. The **mergeAlbum** parameter is used to specify whether to merge the old and new albums or not.*

```apex
sharinpix.Utils u = new sharinpix.Utils();
boolean renamed = u.renameAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS', true);
System.debug(renamed);
```

Image below shows the albums before using the renameAlbum method.

<figure><img src="https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2Fgit-blob-e46ac0f2655d2ba9fde128d1e9eca2cabc85f27d%2F1_1%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

After using the method renameAlbum with mergeAlbum parameter 'true', all the images from the old Album have been merged in the new Album as shown below.

<figure><img src="https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2Fgit-blob-aadcc736e6593c72f7c7098f7d708027df818553%2F2_2.png?alt=media" alt=""><figcaption></figcaption></figure>

### duplicateAlbum <a href="#duplicatealbum" id="duplicatealbum"></a>

#### duplicateAlbum with no Tags or Tags equals to false <a href="#duplicatealbum-with-no-tags" id="duplicatealbum-with-no-tags"></a>

*global String **duplicateAlbum**(String **sourceAlbumId**, String **destinationAlbumId**)*

* Copies all images from a source album to a destination album.

The code below shows the code without tags.

```apex
SharinPix.Utils utls = new SharinPix.Utils();
utls.duplicateAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS');
```

Image below shows the source record where the album an image with the tag "**object"**.

<figure><img src="https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2Fgit-blob-37777064b8c1d72ad2c3f6bcd8000f9d0119636c%2F3_3.png?alt=media" alt=""><figcaption></figcaption></figure>

The image below shows the destination record where the image from the source record has been populated without the tags because in the code snippet we have not mentioned if "Tags" is **true** or **false**.

<figure><img src="https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2Fgit-blob-646bb734032fac45ef41fc26e3a87600bdd81d3c%2F4_4.png?alt=media" alt=""><figcaption></figcaption></figure>

#### DuplicateAlbum with Tags True <a href="#duplicatealbum-with-tags-true-false" id="duplicatealbum-with-tags-true-false"></a>

*global String **duplicateAlbum**(String **sourceAlbumId**, String **destinationAlbumId**, Boolean **includeTags**)*

* Copies all images from a source album to a destination album. This method also allows the duplication of tags along with the images.

The image below shows the code where tags is true.

```apex
SharinPix.Utils utls = new SharinPix.Utils();
utls.duplicateAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS',true);
```

Image below shows the source record where the album an image with the tag "**object"**.

<figure><img src="https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2Fgit-blob-37777064b8c1d72ad2c3f6bcd8000f9d0119636c%2F5_5%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

The image below shows the destination record where the image from the source record has been populated and has been assign the tag "**object"** when the code snippet was executed.

<figure><img src="https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2Fgit-blob-25fbc83f6fdc48ba4fe3850e607fe919521cb54c%2F6_6.png?alt=media" alt=""><figcaption></figcaption></figure>

**duplicateAlbum with Einstein Boxes (DEPRECATED)**

{% hint style="danger" %}
This method has been deprecated and should not be included in new implementations as [Salesforce retired Einstein Vision on July 31, 2023](https://help.salesforce.com/s/articleView?id=000394460\&type=1).
{% endhint %}

*global String duplicateAlbum(String sourceAlbumId, String destinationAlbumId, Map\<String,Object> params)*

* Copies all images from a source album to a destination album if einstein\_boxes equals to true. This method also allows the duplication of labels along with the images.

```apex
SharinPix.Utils utls = new SharinPix.Utils();
utls.duplicateAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS',new Map<String,Object>{'einstein_boxes' => true, 'tags' => true});
```

{% hint style="success" %}
For **destination records,** the tags will only appear if we mentioned **true** in the code snippet.
{% endhint %}

### getAlbumImages <a href="#getalbumimages" id="getalbumimages"></a>

*global List\<Object> **getAlbumImages**(String **albumId**)*

* Gets all images from an album.

Below code shows how to get the details from an image (e.g: brightness, color, contrast, created\_at,...)

```apex
sharinpix.Utils u = new sharinpix.Utils();
list<object> lstobj = u.getAlbumImages('0018a00001rL2sXAAS');
```

### getImageDetails <a href="#getimagedetails" id="getimagedetails"></a>

*global Map\<String, Object> **getImageDetails**(String **imageId**)*

* *Gets image details.*

```apex
sharinpix.Utils u = new sharinpix.Utils();
Map<String, object> response = u.getImageDetails('66d6d11a-6399-4713-be28-ebcbdc148c3b');
System.debug(response);
```

### duplicateImageToAlbum <a href="#duplicateimagetoalbum" id="duplicateimagetoalbum"></a>

*global string **duplicateImageToAlbum**(string **imageId***, string **albumId**, map\<string, object> **options**)

* Duplicates an image to a specified album. The **options** parameter can be used to enable tag and image sync while duplicating the image. *An example on how to call this method has been given at the end of this article.*

```apex
sharinpix.Utils u = new sharinpix.Utils();
string response = u.duplicateImageToAlbum('64fae218-12b8-47ee-ad5a-e0d733e5eade','0018F00000SyyvJQAR',new map<string, object>{'tags' => true, 'sync' => true});
System.debug(response);
```

### duplicateImages <a href="#duplicateimages" id="duplicateimages"></a>

#### duplicateImages with no Tags or Tags equals to false <a href="#duplicateimages-with-no-tags-or-tags-equals-to-false" id="duplicateimages-with-no-tags-or-tags-equals-to-false"></a>

*global List\<Object> **duplicateImages**(List\<String> **imageIds**, String **destinationAlbumId**)*

* *Duplicates one or more images to another album.*

```apex
sharinpix.Utils u = new sharinpix.Utils();
List<object> response = u.duplicateImages(new list<String>{'66d6d11a-6399-4713-be28-ebcbdc148c3b'}, '0018F00000SyyvJQAR');
System.debug(response);
```

#### duplicateImages with Tags True <a href="#duplicateimages-with-tags-true" id="duplicateimages-with-tags-true"></a>

*global List\<Object> **duplicateImages**(List\<String> **imageIds**, String **destinationAlbumId,** Map\<String, Object> **options**)*

* *Duplicates one or more images to another album. This method also allows the duplication of tags along with the images.*

```apex
sharinpix.Utils u = new sharinpix.Utils();
List<object> response = u.duplicateImages(new list<String>{'66d6d11a-6399-4713-be28-ebcbdc148c3b'}, '0018F00000SyyvJQAR', new Map<String, Object> {'tags' => true});
System.debug(response);
```

{% hint style="success" %}
**Tip:**

The SharinPix package also include the **Image** class which includes useful methods for image management such as a method to move images. For more information about the Image class, please refer to the article below:

[Image methods](https://docs.sharinpix.com/documentation/cookbook/image-methods)
{% endhint %}

### getImageUrl <a href="#getimageurl" id="getimageurl"></a>

*global String **getImageUrl**(String **imageId**, Map\<String, Object> **sharinpix**, List\<Object> **transformations**)*

* *Gets the URL of a transformed image.*

```apex
sharinpix.Utils u = new sharinpix.Utils();
String imgURL = u.getImageUrl('66d6d11a-6399-4713-be28-ebcbdc148c3b', new Map<String, object>{'download' => false},new List<Object>{new map<String,object>{'crop' => 'fit', 'width' => 500}});
System.debug(imgURL);
```

* *Get the original url of an image (This url is a direct expiring url to the storage)*<br>

```apex
sharinpix.Utils u = new sharinpix.Utils();
String imgURL = u.getImageUrl('2ae9c19c-3ad3-4844-bacc-71c2cd3313a8', new Map<String, object>{'original' => true},new List<Object>{});
System.debug(imgURL);
```

### getImageEndpoint <a href="#getimageendpoint" id="getimageendpoint"></a>

global String **getImageEndpoint** (String **imageId**, Map\<String, Object> **sharinpix**, List\<Object> **transformations**)

* Get endpoint of transformed image

```apex
sharinpix.Utils u = new sharinpix.Utils();
String imgURL = u.getImageEndpoint('2ae9c19c-3ad3-4844-bacc-71c2cd3313a8', new Map<String, object>{'original' => true},new List<Object>{});
System.debug(imgURL);
```

### croppedImageUrl <a href="#croppedimageurl" id="croppedimageurl"></a>

*global String **croppedImageUrl**(String **imageId**, String **cropStyle**, Integer **width**, Integer **height**)*

* Crops or resizes images.

```apex
sharinpix.Utils u = new sharinpix.Utils();
string getUrl = u.croppedImageUrl('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5','fill',100,100);
System.debug(getUrl);
```

### getImageExternalUrl <a href="#getimageexternalurl" id="getimageexternalurl"></a>

*global Map\<String, Object> **getImageExternalUrl**(Map\<String, Object> **imageTransformation**)*

* Applies transformations on an image and get an external URL.

```apex
sharinpix.Utils u = new sharinpix.Utils();
Map<String,Object> image = new Map<String,Object>{'image_id' => '66d6d11a-6399-4713-be28-ebcbdc148c3b','crop' => 'fit','height' => 100,'width' => 100};
Map<String, Object> imageObj = u.getImageExternalUrl(image);
System.debug(imageObj);
```

### getImageExternalUrls <a href="#getimageexternalurls" id="getimageexternalurls"></a>

*global List\<Object> **getImageExternalUrls**(List\<Map\<String, Object>> **imageTransformations**)*

* *Applies transformations on images and get external images URLs.*

```apex
sharinpix.Utils u = new sharinpix.Utils();
list<Map<String,Object>> getImgExtUrl = new list<Map<String,Object>>{
    new Map<String,Object>{
        'image_id' => '66d6d11a-6399-4713-be28-ebcbdc148c3b',
        'transformations' => new Map<string, object> {
        'crop' => 'fit',
        'height' => 100,
        'width' => 100
            }
    }
};

List<object> lstObj = u.getImageExternalUrls(getImgExtUrl);
Map<String, Object> fieldsToValue = (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(lstObj[0]));
System.debug(fieldsToValue.get('url'));
```

### getOrgTags <a href="#getorgtags" id="getorgtags"></a>

*global List\<Object> **getOrgTags**()*

* Retrieves all tags present in your Organization.

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <object> lstobj = u.getOrgTags();
System.debug(lstobj);
```

### getAlbumTagImages <a href="#getalbumtagimages" id="getalbumtagimages"></a>

*global List\<Object> **getAlbumTagImages**(String **albumId**)*

* Retrieves the list of images having tags from an album.

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <Object> lstObj =u.getAlbumTagImages('0018a00001rL2scAAC');
System.debug(lstObj);
```

### getAlbumTagImages <a href="#getalbumtagimages_1" id="getalbumtagimages_1"></a>

*global List\<Object> **getAlbumTagImages**(String **albumId**, String **tagName**)*

* Retrieves all tagged images having a specific tag name from an album.

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <Object> lstObj = u.getAlbumTagImages('0018a00001rL2scAAC','Plan');
System.debug(lstObj);
```

### getTagsOnImage <a href="#gettagsonimage" id="gettagsonimage"></a>

*global List\<Object> **getTagsOnImage**(String **imageId**)*

* Retrieves all tags applied to an image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <object> lstobj = u.getTagsOnImage('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5');
System.debug(lstobj);
```

### getTagNamesOnImage <a href="#gettagnamesonimage" id="gettagnamesonimage"></a>

*global List\<String> **getTagNamesOnImage**(String **imageId**)*

* Retrieves all tag names available on an image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <String> lstobj = u.getTagNamesOnImage('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5');
System.debug(lstobj);
```

### addTag <a href="#addtag" id="addtag"></a>

*global Object **addTag**(String imageId, String **tagName**)*

* Adds a tag on an image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
u.addTag('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5','testInsertTags');
```

### removeTags <a href="#removetags" id="removetags"></a>

*global Boolean* (String **imageId**, String\[] **tags**)

* Removes tags from a tagged image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
Boolean tagRemoved = false;
tagRemoved = u.removeTags('66d6d11a-6399-4713-be28-ebcbdc148c3b',new list<String>{'Plan'});
```

### clearTags <a href="#cleartags" id="cleartags"></a>

*global Boolean **clearTags**(String **imageId**)*

* Clears all tags applied to an image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
u.clearTags('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5');
```

### uploadAttachment <a href="#uploadattachment" id="uploadattachment"></a>

*global Object **uploadAttachment**(Id **attachmentId**, String **albumId**)*

* Uploads Salesforce attachments to SharinPix albums.

```apex
sharinpix.Utils u = new sharinpix.Utils();
object result =u.uploadAttachment('00P8a00000HCfOWAA1','0018a00001rL2scAAC');
System.debug(result);
```

### uploadAttachment <a href="#uploadattachment_1" id="uploadattachment_1"></a>

*global Object **uploadAttachment**(Id **attachmentId**, String **albumId**, Map\<String, Object> **userMetadatas**)*

* Uploads Salesforce attachments to SharinPix albums.

```apex
sharinpix.Utils u = new sharinpix.Utils();
object result =u.uploadAttachment('00P8a00000HCfOWAA1','0018a00001rL2scAAC',null);
System.debug(result);
```

### uploadAttachment <a href="#uploadattachment_2" id="uploadattachment_2"></a>

global Object **uploadAttachment**(Id **attachmentId**, String **albumId**, Map\<String, Object> **userMetadatas**, List\<String> **tags**)

* Uploads Attachments to SharinPix albums with tags. Using this method, you can also provide a list of tags to be applied to every image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
object result =u.uploadAttachment('0698a00000HCfOWAA1','0018a00001rL2scAAC',null,new List<String>{ 'tagA', 'tagB' });
System.debug(result);
```

### uploadContentDocument <a href="#uploadcontentdocument" id="uploadcontentdocument"></a>

*global Object **uploadContentDocument**(Id **contentDocumentId**, String **albumId**)*

* Uploads Salesforce ContentDocuments to SharinPix albums.

```apex
sharinpix.Utils u = new sharinpix.Utils();
object result =u.uploadContentDocument('0698a00000HCfOWAA1','0018a00001rL2scAAC');
System.debug(result);
```

### uploadContentDocument <a href="#uploadcontentdocument_1" id="uploadcontentdocument_1"></a>

*global Object **uploadContentDocument**(Id **contentDocumentId**, String **albumId**, Map\<String, Object> **userMetadatas**)*

* Uploads Salesforce ContentDocuments to SharinPix albums.

```apex
sharinpix.Utils u = new sharinpix.Utils();
object result =u.uploadContentDocument('0698a00000HCfOWAA1','0018a00001rL2scAAC',null);
System.debug(result);
```

### uploadContentDocument <a href="#uploadcontentdocument_2" id="uploadcontentdocument_2"></a>

*global Object **uploadContentDocument**(Id **contentDocumentId**, String **albumId**, Map\<String, Object> **userMetadatas**, List\<String> **tags**)*

* Uploads Salesforce ContentDocuments to SharinPix albums. Using this method, you can also provide a title and description within the ***userMetadatas*** parameter and a list of tags within the ***tags*** parameter to be applied to every image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
object result =u.uploadContentDocument('0698a00000HCfOWAA1', '0018a00001rL2scAAC', new Map<String, Object> { 'sp_title' => 'sample title', 'sp_description' => 'sample description' }, new List<String> { 'tagA', 'tagB' });
System.debug(result);
```

### uploadFromUrl <a href="#uploadfromurl" id="uploadfromurl"></a>

*global Object **uploadFromUrl**(String **imageUrl**, String **albumId**, String **filename**)*

* Uploads an image to SharinPix using an URL.

```apex
sharinpix.Utils u = new sharinpix.Utils();
string url ='https://picsum.photos/1200/1000';
object result = u.uploadFromUrl(url,'0018a00001rL2scAAC','image.jpg');
System.debug(result);
```

### uploadFromUrl <a href="#uploadfromurl_1" id="uploadfromurl_1"></a>

*global Object **uploadFromUrl**(String **imageUrl**, String **albumId**, String **filename**, map\<string, object> **metadatas**)*

* Uploads an image to SharinPix using an URL. Using this method, you can also provide specific metadata as title, description and contentDocumentId within the ***userMetadatas*** parameter to be applied to the image.

```apex
sharinpix.Utils u = new sharinpix.Utils();
string url ='https://picsum.photos/1200/1000';
object result = u.uploadFromUrl(url,'0018a00001rL2scAAC','test1', new Map<string, string> { 'contentDocumentId' => '0698a00000HCfOWAA1', 'sp_title' => 'sample title', 'sp_description' => 'sample description' });
System.debug(result);
```

### uploadWebshot <a href="#uploadwebshot" id="uploadwebshot"></a>

*global Object **uploadWebshot**(String **url**, String **albumId**)*

* Captures screenshot from website URL and uploads to SharinPix.

```apex
sharinpix.Utils u = new sharinpix.Utils();
string url ='https://www.google.com';
object getUploadWebShot = u.uploadWebshot(url,'0018a00001rL2scAAC');
System.debug(getUploadWebShot);
```

### uploadWebshot <a href="#uploadwebshot_1" id="uploadwebshot_1"></a>

*global Object **uploadWebshot**(String **url**, String **albumId**, Map\<string, object> **options**)*

* Captures screenshot from website URL and uploads to SharinPix. Using this method you can also provide a list of tags to be applied on every image. For e.g :\
  sharinpix.Utils.uploadWebshot('https\:/test/maps/test', '00324000004GUxhAAG', new Map\<string, object>{ 'tags' => new List\<string> {'mapTag'}});

```apex
sharinpix.Utils u = new sharinpix.Utils();
object response = u.uploadWebshot('https://www.google.com/','5008a00001uwxsNAAQ',new Map<String,object> {'tags'=> 'test'});
System.debug(response);
```

### generateMobileAppUrl <a href="#generatemobileappurl" id="generatemobileappurl"></a>

*global String **generateMobileAppUrl**(String **albumId**, Map\<String, Object> **options**)*

* Generates the SharinPix URL used to launch the mobile application.

```apex
sharinpix.Utils u = new sharinpix.Utils();
Map <String, object> opt = new Map<String,Object>{
    'name'=> 'TestName',
        'linkExpiration' => 500
};

string appurl = u.generateMobileAppUrl('61a65f12-eccd-4b42-bd7d-2de4a8699b80',opt);
System.debug(appurl);
```

### generateMobileAppUrl <a href="#generatemobileappurl_1" id="generatemobileappurl_1"></a>

*global String **generateMobileAppUrl**(String **albumId**, String **name**, Map\<String, Object> **options**, Integer **linkExpiration**)*

* Generates the SharinPix URL used to launch the mobile application.

```apex
sharinpix.Utils u = new sharinpix.Utils();
Map<String, object> options = new map<String,object>{
    'name' => 'TestName',
    'linkExpiration' => 500
};
    String appurl = u.generateMobileAppUrl('61a65f12-eccd-4b42-bd7d-2de4a8699b80',options);
System.debug('appurl : '+ appurl);
```

### splitToken <a href="#splittoken" id="splittoken"></a>

*global static List\<String> **splitToken**(String **token**, Integer **sizeLimit**)*

* Method used to split a token.

```apex
sharinpix.Utils u = new sharinpix.Utils();
string tokens = sharinpix.Client.getInstance().token(
    new Map<String, Object> {
            'abilities' => new Map<String, Object> {
                '0018a00001rL2scAAC' => new Map<String, Object> {
                    'Access'  => new Map<String, Object> {
                        'see' => true,
                        'image_list' => true,
                        'image_upload' => true
                    }
                }
            }
        });
integer size = 255;
list<String> actualList = sharinpix.Utils.splitToken(tokens,size);
System.debug(actualList);
```

### getAlbumImageIds <a href="#getalbumimageids" id="getalbumimageids"></a>

*global List\<String> **getAlbumImageIds**(Id **albumId**)*

* Retrieves all image IDs found in an album.

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <String> lstAlbumId = u.getAlbumImageIds('a0A8a00002ho8elEAA');
System.debug(lstAlbumId);
```

### deleteImage <a href="#deleteimage" id="deleteimage"></a>

*global List\<String> **deleteImage**(String **imageId**)*

* Deletes image corresponding to the given ID

```apex
sharinpix.Utils u = new sharinpix.Utils();
List <String> lstImg = u.deleteImage('a7d50d26-4f01-4298-9d1b-f69db2214f07');
System.debug(lstImg);
```

### deleteImage <a href="#deleteimage_1" id="deleteimage_1"></a>

*global List\<String> **deleteImage**(String **imageId**, map\<string, object> **payload**)*

* Deletes image corresponding to the given ID taking into consideration parameters passed in payload. Available options:
  * purge
    * Set to true to completely delete image from SharinPix. This action cannot be undone and image cannot be restored. Example usage:\
      (new sharinpix.Utils()).deleteImage('imageIdHere', new map\<string,object>{'purge' => true});

```apex
sharinpix.Utils u = new sharinpix.Utils();
List <String> lstImg = u.deleteImage('a7d50d26-4f01-4298-9d1b-f69db2214f07', new Map<string,object> {'purge' => true});
System.debug(lstImg);
```

### deleteImages <a href="#deleteimages" id="deleteimages"></a>

*global List\<String> **deleteImages**(List\<String> **imageIds**)*

* Deletes images corresponding to the given IDs

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <String> delImgs = u.deleteImages(new list<String> {'0e7d41a8-b1b8-440a-9734-24e5a2923075', 'fa2b5a41-e43c-4ed0-ac85-58ff5b90a4ed'});
System.debug(delImgs)
```

### deleteImages <a href="#deleteimages_1" id="deleteimages_1"></a>

*global List\<String> **deleteImages**(List\<String> **imageIds**, map\<string, object> **payload**)*

* Deletes images corresponding to the given IDs taking into consideration parameters passed in payload. Available options:
  * purge
    * Set to true to completely delete images from SharinPix. This action cannot be undone and images cannot be restored.

```apex
sharinpix.Utils u = new sharinpix.Utils();
list <String> delImgs = u.deleteImages(new list<String> {'0e7d41a8-b1b8-440a-9734-24e5a2923075', 'fa2b5a41-e43c-4ed0-ac85-58ff5b90a4ed'}, new Map<string,object> {'purge' => true});
System.debug(delImgs)
```

### updateSessionIdValidity <a href="#sessionidvalidity" id="sessionidvalidity"></a>

*global Object **updateSessionIdValidity***(String **id**, Boolean ***valid**)*

* Validates or invalidates a session (corresponding to the given session Id in the parameters)
* Updates valid to true to validate a session or false to invalidate a session.

```apex
sharinpix.Utils u = new sharinpix.Utils(); 
u.updateSessionIdValidity('00524000000kfy0aan-open', false); 
```

### createContentDocumentFromUrl <a href="#createcontentdocumentfromurl" id="createcontentdocumentfromurl"></a>

You can utilize this method to transform a public URL into a content document. It's applicable for converting SharinPix Images into content documents using SharinPix public image URLs.

#### createContentDocumentFromUrl without the option to add custom filename <a href="#createcontentdocumentfromurl-without-the-option-to-add-custom-filename" id="createcontentdocumentfromurl-without-the-option-to-add-custom-filename"></a>

*global static Id **createContentDocumentFromUrl**(String url)*

* Download a file at a URL to Content Document

```apex
String url = 'https://app.sharinpix.com/3/9a3dc1c/YXltYW4ubmdyb2suaW8vaW1hZ2VzLzI1ZWNjOTdjLTg4NDMtNDEyNS1hNjI0LTIxNTg5YTBlNDBhOS90aHVtYm5haWxzL29yaWdpbmFsLTk5Y2VjNzgwMGM5LmpwZw/laptop7.jpg';
Sharinpix.Utils.createContentDocumentFromUrl(url);
```

#### createContentDocumentFromUrl with option to add custom filename <a href="#createcontentdocumentfromurl-with-option-to-add-custom-filename" id="createcontentdocumentfromurl-with-option-to-add-custom-filename"></a>

*global static Id **createContentDocumentFromUrl**(String url, Map\<String, Object> options)*

* Download a file at a URL to Content Document with custom filename

**Note:** The custom filename should be added with its extension (e.g. jpg, png, jpeg, and so on) and the key should be 'filename' as shown in the example below.

```apex
String url = 'https://app.sharinpix.com/3/9a3dc1c/YXltYW4ubmdyb2suaW8vaW1hZ2VzLzI1ZWNjOTdjLTg4NDMtNDEyNS1hNjI0LTIxNTg5YTBlNDBhOS90aHVtYm5haWxzL29yaWdpbmFsLTk5Y2VjNzgwMGM5LmpwZw/laptop7.jpg';
Map<String, Object> options = new Map<String, Object> {'filename' => 'filename.jpg'}
Sharinpix.Utils.createContentDocumentFromUrl(url, options);
```

{% hint style="warning" %}
**Note:**

Before calling an external site (url from an external site), that site must be registered in the Remote Site Settings page of Salesforce.[ How to register new site?](https://help.salesforce.com/s/articleView?id=sf.configuring_remoteproxy.htm\&type=5)
{% endhint %}
