FIWARE-NGSI v2 Specification (1.0)

Download OpenAPI specification:Download

TODO: Add a description

API Entry Point

Retrieve API Resources

This resource does not have any attributes. Instead it offers the initial API affordances in the form of the links in the JSON body. It is recommended to follow the “url” link values, Link or Location headers where applicable to retrieve resources. Instead of constructing your own URLs, to keep your client decoupled from implementation details.

Responses

Response samples

Content type
application/json
{
  • "entities_url": "/v2/entities",
  • "types_url": "/v2/types",
  • "subscriptions_url": "/v2/subscriptions",
  • "registrations_url": "/v2/registrations"
}

Entities

List Entities

Retrieves a list of entities that match different criteria by id, type, pattern matching (either id or type) and/or those which match a query or geographical query (see Simple Query Language and Geographical Queries). A given entity has to match all the criteria to be retrieved (i.e., the criteria is combined in a logical AND way). Note that pattern matching query parameters are incompatible (i.e. mutually exclusive) with their corresponding exact matching parameters, i.e. idPattern with id and typePattern with type. The response payload is an array containing one object per matching entity. Each entity follows the JSON entity representation format (described in "JSON Entity Representation" section). Response code:

  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
query Parameters
id
string

A comma-separated list of elements. Retrieve entities whose ID matches one of the elements in the list. Incompatible with idPattern.

type
string

comma-separated list of elements. Retrieve entities whose type matches one of the elements in the list. Incompatible with typePattern.

idPattern
string

A correctly formated regular expression. Retrieve entities whose ID matches the regular expression. Incompatible with id.

typePattern
string

A correctly formated regular expression. Retrieve entities whose type matches the regular expression. Incompatible with type.

q
string

A query expression, composed of a list of statements separated by ;, i.e., q=statement1;statement2;statement3. See Simple Query Language specification.

mq
string

A query expression for attribute metadata, composed of a list of statements separated by ;, i.e., mq=statement1;statement2;statement3. See Simple Query Language specification.

georel
string

Spatial relationship between matching entities and a reference shape. See Geographical Queries.

geometry
string

Geografical area to which the query is restricted. See Geographical Queries.

coords
string

List of latitude-longitude pairs of coordinates separated by ';'. See Geographical Queries.

limit
number <double>

Limits the number of entities to be retrieved

offset
number <double>

Establishes the offset from where entities are retrieved

attrs
string

Comma-separated list of attribute names whose data are to be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order. See "Filtering out attributes and metadata" section for more detail.

metadata
string

A list of metadata names to include in the response. See "Filtering out attributes and metadata" section for more detail.

orderBy
string

Criteria for ordering results. See "Ordering Results" section for details.

options
string
Enum: "count" "keyValues" "values" "unique"

Options dictionary

Responses

Response samples

Content type
application/json
[
  • {
    },
  • {
    },
  • {
    }
]

Create Entity

The payload is an object representing the entity to be created. The object follows the JSON entity representation format (described in a "JSON Entity Representation" section). Response:

  • Successful operation uses 201 Created (if upsert option is not used) or 204 No Content (if upsert option is used). Response includes a Location header with the URL of the created entity.
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
query Parameters
options
string
Enum: "keyValues" "upsert"

Options dictionary

header Parameters
Content-Type
required
string
Request Body schema: application/json
type
required
string
id
required
string
temperature
required
object
humidity
required
object
location
required
object

Responses

Request samples

Content type
application/json
{
  • "type": "Room",
  • "id": "Bcn-Welt",
  • "temperature": {
    },
  • "humidity": {
    },
  • "location": {
    }
}

Retrieve Entity

The response is an object representing the entity identified by the ID. The object follows the JSON entity representation format (described in "JSON Entity Representation" section). This operation must return one entity element only, but there may be more than one entity with the same ID (e.g. entities with same ID but different types). In such case, an error message is returned, with the HTTP status code set to 409 Conflict. Response:

  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity to be retrieved

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

attrs
string

Comma-separated list of attribute names whose data must be included in the response. The attributes are retrieved in the order specified by this parameter. See "Filtering out attributes and metadata" section for more detail. If this parameter is not included, the attributes are retrieved in arbitrary order, and all the attributes of the entity are included in the response.

metadata
string

A list of metadata names to include in the response. See "Filtering out attributes and metadata" section for more detail.

options
string
Enum: "keyValues" "values" "unique"

Options dictionary

Responses

Response samples

Content type
application/json
{
  • "type": "Room",
  • "id": "Bcn_Welt",
  • "temperature": {
    },
  • "humidity": {
    },
  • "location": {
    }
}

Remove Entity

Delete the entity. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity to be deleted

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

Responses

Retrieve Entity Attributes

This request is similar to retreiving the whole entity, however this one omits the id and type fields. Just like the general request of getting an entire entity, this operation must return only one entity element. If more than one entity with the same ID is found (e.g. entities with same ID but different type), an error message is returned, with the HTTP status code set to 409 Conflict. Response:

  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity to be retrieved

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

attrs
string

Comma-separated list of attribute names whose data are to be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order, and all the attributes of the entity are included in the response. See "Filtering out attributes and metadata" section for more detail.

metadata
string

A list of metadata names to include in the response. See "Filtering out attributes and metadata" section for more detail.

options
string
Enum: "keyValues" "values" "unique"

Options dictionary

Responses

Response samples

Content type
application/json
{
  • "temperature": {
    },
  • "humidity": {
    },
  • "location": {
    }
}

Replace all entity attributes

The request payload is an object representing the new entity attributes. The object follows the JSON entity representation format (described in a "JSON Entity Representation" above), except that id and type are not allowed. The attributes previously existing in the entity are removed and replaced by the ones in the request. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity in question.

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

options
string
Value: "keyValues"

Operations options

header Parameters
Content-Type
required
string
Request Body schema: application/json
temperature
required
object
seatNumber
required
object

Responses

Request samples

Content type
application/json
{
  • "temperature": {
    },
  • "seatNumber": {
    }
}

Update or Append Entity Attributes

The request payload is an object representing the attributes to append or update. The object follows the JSON entity representation format (described in "JSON Entity Representation" section), except that id and type are not allowed. The entity attributes are updated with the ones in the payload, depending on whether the append operation option is used or not.

  • If append is not used: the entity attributes are updated (if they previously exist) or appended (if they don't previously exist) with the ones in the payload.
  • If append is used (i.e. strict append semantics): all the attributes in the payload not previously existing in the entity are appended. In addition to that, in case some of the attributes in the payload already exist in the entity, an error is returned. Response:
  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Entity id to be updated

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

options
string
Enum: "append" "keyValues"

Operations options

header Parameters
Content-Type
required
string
Request Body schema: application/json
ambientNoise
required
object

Responses

Request samples

Content type
application/json
{
  • "ambientNoise": {
    }
}

Update Existing Entity Attributes

The request payload is an object representing the attributes to update. The object follows the JSON entity representation format (described in "JSON Entity Representation" section), except that id and type are not allowed. The entity attributes are updated with the ones in the payload. In addition to that, if one or more attributes in the payload doesn't exist in the entity, an error is returned. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity to be updated

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

options
string
Value: "keyValues"

Operations options

header Parameters
Content-Type
required
string
Request Body schema: application/json
temperature
required
object
seatNumber
required
object

Responses

Request samples

Content type
application/json
{
  • "temperature": {
    },
  • "seatNumber": {
    }
}

Attributes

Get attribute data

Returns a JSON object with the attribute data of the attribute. The object follows the JSON representation for attributes (described in "JSON Attribute Representation" section). Response:

  • Successful operation uses 200 OK.
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity

attrName
required
string

Name of the attribute to be retrieved.

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

metadata
string

A list of metadata names to include in the response. See "Filtering out attributes and metadata" section for more detail.

Responses

Response samples

Content type
application/json
{
  • "value": 21.7,
  • "type": "Number",
  • "metadata": { }
}

Update Attribute Data

The request payload is an object representing the new attribute data. Previous attribute data is replaced by the one in the request. The object follows the JSON representation for attributes (described in "JSON Attribute Representation" section). Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity to update

attrName
required
string

Attribute name

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

header Parameters
Content-Type
required
string
Request Body schema: application/json
value
required
number <double>
metadata
required
object

Responses

Request samples

Content type
application/json
{
  • "value": 25,
  • "metadata": {
    }
}

Remove a Single Attribute

Removes an entity attribute. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity.

attrName
required
string

Attribute name.

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

Responses

Attribute Value

Get Attribute Value

This operation returns the value property with the value of the attribute.

  • If attribute value is JSON Array or Object:
    • If Accept header can be expanded to application/json or text/plain return the value as a JSON with a response type of application/json or text/plain (whichever is the first in Accept header or application/json in case of Accept: */*).
    • Else return a HTTP error "406 Not Acceptable: accepted MIME types: application/json, text/plain"
  • If attribute value is a string, number, null or boolean:
    • If Accept header can be expanded to text/plain return the value as text. In case of a string, citation marks are used at the begining and end.
    • Else return a HTTP error "406 Not Acceptable: accepted MIME types: text/plain" Response:
  • Successful operation uses 200 OK.
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity in question

attrName
required
string

Name of the attribute to be retrieved.

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

Responses

Response samples

Content type
application/json
{
  • "address": "Ronda de la Comunicacion s/n",
  • "zipCode": 28050,
  • "city": "Madrid",
  • "country": "Spain"
}

Update Attribute Value

The request payload is the new attribute value.

  • If the request payload MIME type is application/json, then the value of the attribute is set to the JSON object or array coded in the payload (if the payload is not a valid JSON document, then an error is returned).
  • If the request payload MIME type is text/plain, then the following algorithm is applied to the payload:
    • If the payload starts and ends with citation-marks ("), the value is taken as a string (the citation marks themselves are not considered part of the string)
    • If true or false, the value is taken as a boolean.
    • If null, the value is taken as null.
    • If these first three tests 'fail', the text is interpreted as a number.
    • If not a valid number, then an error is returned and the attribute's value is unchanged. The payload MIME type in the request is specified in the Content-Type HTTP header. Response:
  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityId
required
string

Id of the entity to be updated.

attrName
required
string

Attribute name.

query Parameters
type
string

Entity type, to avoid ambiguity in case there are several entities with the same entity id.

header Parameters
Content-Type
required
string
Request Body schema: application/json
address
required
string
zipCode
required
integer <int32>
city
required
string
country
required
string

Responses

Request samples

Content type
application/json
{
  • "address": "Ronda de la Comunicacion s/n",
  • "zipCode": 28050,
  • "city": "Madrid",
  • "country": "Spain"
}

Types

List Entity Types

If the values option is not in use, this operation returns a JSON array with the entity types. Each element is a JSON object with information about the type:

  • type : the entity type name.
  • attrs : the set of attribute names along with all the entities of such type, represented in a JSON object whose keys are the attribute names and whose values contain information of such attributes (in particular a list of the types used by attributes with that name along with all the entities).
  • count : the number of entities belonging to that type. If the values option is used, the operation returns a JSON array with a list of entity type names as strings. Results are ordered by entity type in alphabetical order. Response code:
  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
query Parameters
limit
number <double>

Limit the number of types to be retrieved.

offset
number <double>

Skip a number of records.

options
string
Enum: "count" "values"

Options dictionary.

Responses

Response samples

Content type
application/json
[
  • {
    },
  • {
    }
]

Retrieve entity type

This operation returns a JSON object with information about the type:

  • attrs : the set of attribute names along with all the entities of such type, represented in a JSON object whose keys are the attribute names and whose values contain information of such attributes (in particular a list of the types used by attributes with that name along with all the entities).
  • count : the number of entities belonging to that type. Response code:
  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
entityType
required
string

Entity Type

Responses

Response samples

Content type
application/json
{
  • "attrs": {
    },
  • "count": 7
}

Subscriptions

List Subscriptions

Returns a list of all the subscriptions present in the system. Response:

  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
query Parameters
limit
number <double>

Limit the number of subscriptions to be retrieved

offset
number <double>

Skip a number of subscriptions

options
string
Value: "count"

Options dictionary

Responses

Response samples

Content type
application/json
[
  • {
    }
]

Create Subscription

Creates a new subscription. The subscription is represented by a JSON object as described at the beginning of this section. Response:

  • Successful operation uses 201 Created
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
header Parameters
Content-Type
required
string
Request Body schema: application/json
description
string
subject
required
object
notification
required
object
expires
string
throttling
integer <int32>

Responses

Request samples

Content type
application/json
{
  • "description": "One subscription to rule them all",
  • "subject": {
    },
  • "notification": {},
  • "expires": "2016-04-05T14:00:00Z",
  • "throttling": 5
}

Retrieve Subscription

The response is the subscription represented by a JSON object as described at the beginning of this section. Response:

  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
subscriptionId
required
string

subscription Id.

Responses

Response samples

Content type
application/json
{ }

Delete subscription

Cancels subscription. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
subscriptionId
required
string

subscription Id.

Responses

Update Subscription

Only the fields included in the request are updated in the subscription. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
subscriptionId
required
string

subscription Id.

header Parameters
Content-Type
required
string
Request Body schema: application/json
expires
required
string

Responses

Request samples

Content type
application/json
{
  • "expires": "2016-04-05T14:00:00Z"
}

Registrations

List Registrations

Lists all the context provider registrations present in the system.

query Parameters
limit
number <double>

Limit the number of registrations to be retrieved

offset
number <double>

Skip a number of registrations

options
string
Value: "count"

Options dictionary

Responses

Response samples

Content type
application/json
[
  • {
    }
]

Create Registration

Creates a new context provider registration. This is typically used for binding context sources as providers of certain data. The registration is represented by a JSON object as described at the beginning of this section. Response:

  • Successful operation uses 201 Created
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
header Parameters
Content-Type
required
string
Request Body schema: application/json
description
required
string
dataProvided
required
object
provider
required
object

Responses

Request samples

Content type
application/json
{
  • "description": "Relative Humidity Context Source",
  • "dataProvided": {
    },
  • "provider": {}
}

Retrieve Registration

The response is the registration represented by a JSON object as described at the beginning of this section. Response:

  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
registrationId
required
string

registration Id.

Responses

Response samples

Content type
application/json
{
  • "id": "abcdefg",
  • "description": "Example Context Source",
  • "dataProvided": {
    },
  • "provider": {},
  • "expires": "2017-10-31T12:00:00",
  • "status": "failed",
  • "forwardingInformation": {
    }
}

Delete Registration

Cancels a context provider registration. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
registrationId
required
string

registration Id.

Responses

Update Registration

Only the fields included in the request are updated in the registration. Response:

  • Successful operation uses 204 No Content
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
path Parameters
registrationId
required
string

registration Id.

header Parameters
Content-Type
required
string
Request Body schema: application/json
expires
required
string

Responses

Request samples

Content type
application/json
{
  • "expires": "2017-10-04T00:00:00"
}

Batch Operations

Update

This operation allows to create, update and/or delete several entities in a single batch operation. The payload is an object with two properties:

  • actionType, to specify the kind of update action to do: either append, appendStrict, update, delete, or replace.
  • entities, an array of entities, each entity specified using the JSON entity representation format (described in the section "JSON Entity Representation"). This operation is split in as many individual operations as entities in the entities vector, so the actionType is executed for each one of them. Depending on the actionType, a mapping with regular non-batch operations can be done:
  • append: maps to POST /v2/entities (if the entity does not already exist) or POST /v2/entities/<id>/attrs (if the entity already exists).
  • appendStrict: maps to POST /v2/entities (if the entity does not already exist) or POST /v2/entities/<id>/attrs?options=append (if the entity already exists).
  • update: maps to PATCH /v2/entities/<id>/attrs.
  • delete: maps to DELETE /v2/entities/<id>/attrs/<attrName> on every attribute included in the entity or to DELETE /v2/entities/<id> if no attribute were included in the entity.
  • replace: maps to PUT /v2/entities/<id>/attrs. Response:
  • Successful operation uses 204 No Content.
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
query Parameters
options
string
Value: "keyValues"

Options dictionary

header Parameters
Content-Type
required
string
Request Body schema: application/json
actionType
required
string
entities
required
Array of objects

Responses

Request samples

Content type
application/json
{
  • "actionType": "append",
  • "entities": [
    ]
}

Query

The response payload is an Array containing one object per matching entity, or an empty array [] if no entities are found. The entities follow the JSON entity representation format (described in the section "JSON Entity Representation"). The payload may contain the following elements (all of them optional):

  • entities: a list of entites to search for. Each element is represented by a JSON object with the following elements:
    • id or idPattern: Id or pattern of the affected entities. Both cannot be used at the same time, but one of them must be present.
    • type or typePattern: Type or type pattern of the entities to search for. Both cannot be used at the same time. If omitted, it means "any entity type".
  • attrs: List of attributes to be provided (if not specified, all attributes).
  • expression: an expression composed of q, mq, georel, geometry and coords (see "List entities" operation above about this field).
  • metadata: a list of metadata names to include in the response. See "Filtering out attributes and metadata" section for more detail. Response code:
  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
query Parameters
limit
number <double>

Limit the number of entities to be retrieved.

offset
number <double>

Skip a number of records.

orderBy
string

Criteria for ordering results. See "Ordering Results" section for details.

options
string
Enum: "count" "keyValues" "values" "unique"

Options dictionary

header Parameters
Content-Type
required
string
Request Body schema: application/json
entities
required
Array of objects
attrs
required
Array of strings
expression
required
object
metadata
required
Array of strings

Responses

Request samples

Content type
application/json
{
  • "entities": [
    ],
  • "attrs": [
    ],
  • "expression": {
    },
  • "metadata": [
    ]
}

Response samples

Content type
application/json
[
  • {
    },
  • {
    },
  • {
    }
]

Notify

This operation is intended to consume a notification payload so that all the entity data included by such notification is persisted, overwriting if necessary. This operation is useful when one NGSIv2 endpoint is subscribed to another NGSIv2 endpoint (federation scenarios). The request payload must be an NGSIv2 notification payload. The behaviour must be exactly the same as POST /v2/op/update with actionType equal to append. Response code:

  • Successful operation uses 200 OK
  • Errors use a non-2xx and (optionally) an error payload. See subsection on "Error Responses" for more details.
query Parameters
options
string
Value: "keyValues"

Options dictionary

header Parameters
Content-Type
required
string
Request Body schema: application/json
subscriptionId
required
string
data
required
Array of objects

Responses

Request samples

Content type
application/json
{
  • "subscriptionId": "5aeb0ee97d4ef10a12a0262f",
  • "data": [
    ]
}