Tuesday, July 12, 2022

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:




 

No comments:

Post a Comment

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...