Tuesday, July 12, 2022

Sitecore Content Hub: Delete asset using REST API

 API URL : api/entities/{id}


Description: The delete Rest api can be used with the unique asset ID to delete the file that already exists in the repository.

Parameters

Name

Located in

Description

Required

Schema

Authorization

Headers

Access token which is generated in Oauth api call insert in the header.

Yes

String

id

url

To fetch the asset details using the asset ID.

Yes

sting

  

Responses: 

If the delete is successful, the return status code of 200 with value OK will be returned; if the delete is failed, error messages will be returned.

 

HTTP Status Code

Application Return Code

Description

Value

Schema

200

 

OK

-

String

304

 

Not Modified

-

String

400

 

Bad Request

-

String

403

 

Forbidden

-

String

404

 

Not Found

-

String

500

 

Internal Server Error

 

String

 

Reference Screenshot – API call from postman tool:



Sitecore Content Hub: Update asset using REST API

 API URL : api/entities/{id}


Description: We can update the metadata of an asset once the asset is available in content hub platform. Asset details can be updated using the specific asset id.

Parameters

Name

Located in

Description

Required

Schema

Authorization

Headers

Access token which is generated in Oauth api call insert in the header.

Yes

String

id

url

To fetch the asset details using the asset ID.

Yes

sting

Raw

Body

The Metadata of the asset which the details has to be updated in JSON format.

Yes

JSON

 

Responses:

If the request is successful, then asset details will be updated in content hub and the api response will be with status code 200.

HTTP Status Code

Application Return Code

Description

Value

Schema

200

 

OK

-

String

304

 

Not Modified

-

String

400

 

Bad Request

-

String

403

 

Forbidden

-

String

404

 

Not Found

-

String

500

 

Server Error

 

String

  

Reference Screenshot – API call from postman tool:

 


Sitecore Content Hub: Get asset using REST API

 API URL : api/entities/{id}


Description: We can get the asset and metadata from the Content hub. The get service will fetch the details with the input asset id. We can also use query parameter to control the response. If more than one assets are present with the same name in SCH then latest asset will be returned.

 

Parameters

Name

Located in

Description

Required

Schema

Authorization

Headers

Access token which is generated in Oauth api call insert in the header.

Yes

String

id

url

To fetch the asset details using the asset ID.

Yes

sting

members

Params

To get the specified properties from the response. Ex: members=Title,FileSize

No

sting

query

params

Query entities by generic properties of known datatypes

No

sting

take

params

skip and take parameters to page the results set.            To get the latest asset this parameter can be set to 1

No

sting

skip

params

skip and take parameters to page the results set

 

 

 

 

Responses:

 

If the request is successful asset details will be received in response with status code 200.

HTTP Status Code

Application Return Code

Description

Value

Schema

200

 

OK

-

String

304

 

Not Modified

-

String

400

 

Bad Request

-

String

403

 

Forbidden

-

String

404

 

Not Found

-

String

500

 

Server Error

 

String

 

Reference Screenshot – API call from postman tool:

 


Sitecore Content Hub: Upload asset using REST API

 1/oauth/token

Description: OAuth is an open standard for authorization. OAuth allows one program to authorize another program to make changes on behalf of an account holder or end-user. Useful for browser-based operations without server-side back-end support

Parameters

Name

Located in

Description

Required

Schema

user_name

Body

Login username for the source system.

Yes

String

password

Body

Login password for the source system.

Yes

String

grant_type

Body

Specifies the Grant type. The value should be password

Yes

String

Username

Authorization

The value of client_id configured in OAuth client from Content hub

Yes

String

password

Authorization

The value of Client Secret configured in OAuth client from Content hub

Yes

String


Responses

HTTP Status Code

Application Return Code

Description

Value

Schema

200

0

The request has succeeded

access_token, token_type, refresh_token , expires_in

 

String

201

 

The request resulted in a new resource being created

-

String

202

 

The request was accepted but has not been completed yet

-

String

204

 

The request has succeeded but returns no message

-

String

304

 

The response has not changed

-

String

400

 

Bad request due to bad syntax

-

String

401

 

The request requires user authentication or authentication has been refused

-

String

403

 

The server understood the request but is refusing to execute it

 

String

404

 

The requested resource could not be found

 

String

429

 

Too many requests

 

String

500

 

Internal server error

 

String

502

 

Bad gateway

 

String

503

 

Service unavailable

 

String

 

 

Reference Screenshot – API call from postman tool:

 



2. api/entities

Description: Content Hub support Asset upload using UI, Web Client SDK and Rest API. Below are the steps to use the Rest Api to upload asset to Content Hub.

Upload Asset is three step process

1.       Request an upload

2.       Upload File

3.       Finalize Upload

Request an upload    /api/v2.0/upload

To retrieve an upload URL, send a POST request to the endpoint api/v2.0/upload.

 The request body should have the following structure:

{

  "file_name": "package.zip",

  "file_size": 1000000,

  "upload_configuration": {

    "name": "AssetUploadConfiguration"

  },

  "action": {

    "name": "NewAsset"

  }

}

Parameters

Name

Located in

Description

Required

Schema

Authorization

Headers

Access token which is generated in Oauth api call insert in the header.

Yes

String

Raw

Body

Raw data in json format along with configuration and asset properties.

Yes

JSON

 

Response:

If request is successful, A successful response returns the upload URL for the next step in the location header, and a JSON body containing information upload_identifier, file_identifier

 

HTTP Status Code

Application Return Code

Description

Value

Schema

200

0

The request has succeeded

 

String

201

 

The request resulted in a new resource being created

upload_identifier, file_identifier, Location

Location

String

202

 

The request was accepted but has not been completed yet

-

String

204

 

The request has succeeded but returns no message

-

String

304

 

The response has not changed

-

String

400

 

Bad request due to bad syntax

-

String

401

 

The request requires user authentication or authentication has been refused

-

String

403

 

The server understood the request but is refusing to execute it

 

String

404

 

The requested resource could not be found

 

String

429

 

Too many requests

 

String

500

 

Internal server error

 

String

502

 

Bad gateway

 

String

503

 

Service unavailable

 

String

 

Reference Screenshot – API call from postman tool:

 


 3. /api/v2.0/upload/process

Description: To perform an upload, send a POST request to the upload URL, containing your file in the body of the request, and your authentication token in the header.

 Parameters

Name

Located in

Description

Required

Schema

Authorization

Headers

Access token which is generated in Oauth api call insert in the header.

Yes

String

Binary

Body

The file which need to be upload as a zip file

Yes

file

 Responses:

If the file upload is successful, you will get 200 OK.

HTTP Status Code

Application Return Code

Description

Value

Schema

200

0

The request has succeeded

success, message

String

201

 

The request resulted in a new resource being created

 

String

202

 

The request was accepted but has not been completed yet

-

String

204

 

The request has succeeded but returns no message

-

String

304

 

The response has not changed

-

String

400

 

Bad request due to bad syntax

-

String

401

 

The request requires user authentication or authentication has been refused

-

String

403

 

The server understood the request but is refusing to execute it

 

String

404

 

The requested resource could not be found

 

String

429

 

Too many requests

 

String

500

 

Internal server error

 

String

502

 

Bad gateway

 

String

 

 

503

 

Service unavailable

 

String

 

Reference Screenshot – API call from postman tool:

 



 4. /api/v2.0/upload/finalize

Description: To mark an upload as complete, send a POST request to the endpoint api/v2.0/upload/finalize with the JSON response body received in the first step

 

Parameters

Name

Located in

Description

Required

Schema

Authorization

Headers

Access token which is generated in Oauth api call insert in the header.

Yes

String

Raw

Body

upload_identifier: identifier of the upload job.

fileIdentifier: identifier of the file in the system.

Yes

JSON

 

Responses:

Once the request is successful, the asset will be uploaded to content hub and in response we will get the asset id and identifier.

HTTP Status Code

Application Return Code

Description

Value

Schema

200

0

The request has succeeded

success, message, Asset ID, Identifier

String

201

 

The request resulted in a new resource being created

 

String

202

 

The request was accepted but has not been completed yet

-

String

204

 

The request has succeeded but returns no message

-

String

304

 

The response has not changed

-

String

400

 

Bad request due to bad syntax

-

String

401

 

The request requires user authentication or authentication has been refused

-

String

403

 

The server understood the request but is refusing to execute it

 

String

404

 

The requested resource could not be found

 

String

429

 

Too many requests

 

String

500

 

Internal server error

 

String

502

 

Bad gateway

 

String

503

 

Service unavailable

 

String

 

 Reference Screenshot – API call from postman tool:




 

How to Create a Public Link Using the Sitecore Content Hub REST API

Creating a public link using the Sitecore Content Hub REST API is a straightforward process that enables you to share content externally whi...