Skip to content

Fixes #335: Doucmentation for post api of assets #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions devel/api/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,72 @@ Example Requests:

url = "https://master.demo.geonode.org/api/v2/resources/{pk}/linked_resources"
response = requests.request("GET", url)


Assets
------------

Assets Create
^^^^^^^^^^^^^

The Assets Create API allows you to create new assets with optional file uploads and resource linking.

**Endpoint**:

- **URL**: ``POST /api/v2/assets/``
- **Success Status Code**: ``201 Created``

**Parameters**:

.. list-table::
:widths: 15 10 75
:header-rows: 1

* - Parameter
- Type
- Description
* - ``file``
- File
- The file to upload. If provided, creates a local asset type
* - ``title``
- String
- Title for the asset
* - ``description``
- String
- Description of the asset
* - ``type``
- String
- Asset type specification
* - ``resource_id``
- Integer
- ID of the resource to link the asset to

**Behavior**:

- **With File**: When a file is provided, a local asset type will be created
- **With Resource ID**: When ``resource_id`` is provided, the asset will be linked to the specified resource
- **Without Resource ID**: Asset will be created as standalone without resource linking


**Example Request**:

.. code-block:: python

import requests

url = "https://master.demo.geonode.org/api/v2/assets/"

payload = {'resource_id': 1,
'title': 'My Asset Title',
'description': 'Description of my asset',
'type': 'document'}

files=[
('file',('assets.png',open('/location/of/file','rb'),'image/png'))
]

headers = {
'Authorization': 'Basic dXNlcjpwYXNzd29yZA=='
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)