Update Data

This endpoint allows you to update data within a database. Unlike the Add Data endpoint with refresh set to 1, using this endpoint allows selective updating leading to greater efficiencies of updating data – you can update individual rows rather than re-uploading your entire dataset each time there is a modification.

POST Parameters

ParameterRequiredValueDescription
api_key{key}An API key that has access to the resource you want to query for
database_id{integer}The ID of the database which you wish to update the data of
data{XML/unicode}Specify the rows you wish to update and the value for the column(s) you wish to update in that row. Structure your XML with each row you wish to update as a parent tag. You then have subtags matching the column_ids for your database (which you wish to update) with the actual value for that column inside the tag

You can provide two conditions for selecting the row:

  • row_id – the id of the row as in the Xtracta App.
  • WHERE style condition – use any field’s value as a key, e.g. "<row condition="{column_id}='{value}'">"

Example XML for data:

<row id="4">
    <column id="1">value1</column>
    <column id="2">value2</column>
    <column id="3">value3</column>
</row>
<row id="5">
    <column id="1">value4</column>
    <column id="2">value5</column>
    <column id="3">value6</column>
</row>
<row condition="3='sample_value'">
    <column id="2">value7</column>
</row>

Code Examples

The cURL, PHP, Python, Node.js, and C# examples call Xtracta from a trusted server. The React example calls an application-defined backend proxy so the API key is never exposed in browser code.

Warning

Store XTRACTA_API_KEY as a server-side environment variable. Never embed it in browser-delivered code.

curl --request POST 'https://api-app.xtracta.com/v1/databases/data_update' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'api_key=<API_KEY>' \
  --data-urlencode 'database_id=<DATABASE_ID>' \
  --data-urlencode 'data={xml here}'

Sample Request

POST https://api-app.xtracta.com/v1/databases/data_update HTTP/1.1
api_key=123&database_id=456789&data={xml here}

Sample Response

<?xml version="1.0" encoding="UTF-8"?>
<databases_response>
    <status>200</status>
    <message>The request has been successfully processed</message>
    <affected_records>1</affected_records>
    <data>
        <row id="1" response="Record Updated"/>
    </data>
</databases_response>

Schema Definition

Response Elements

ElementDescription
<status>A status code in response to the operation.
<message>Additional information about the operation – human readable.
<affected_records>The number of records which were affected by the operation
<data>A container for information about the specific rows that were added.
<data>→<row>The rows (and their Ids) which were added.

Example

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:complexType name="RowType"><xs:sequence/><xs:attribute name="id" type="xs:positiveInteger" use="optional"/><xs:attribute name="condition" type="xs:string" use="optional"/><xs:attribute name="response" type="xs:string" use="required"/></xs:complexType>
  <xs:complexType name="DataType"><xs:sequence><xs:element name="row" type="RowType" maxOccurs="unbounded"/></xs:sequence></xs:complexType>
  <xs:element name="databases_response"><xs:complexType><xs:sequence>
    <xs:element name="status" type="xs:positiveInteger"/><xs:element name="message" type="xs:string"/>
    <xs:element name="affected_records" type="xs:nonNegativeInteger" minOccurs="0"/><xs:element name="data" type="DataType" minOccurs="0"/>
  </xs:sequence></xs:complexType></xs:element>
</xs:schema>

Error Responses

For JSON and XML responses generated by this endpoint, the response is wrapped in databases_response and includes the HTTP status code and a message.

StatusMessageDescription
400database_id is required / database_id must be natural numberSupply the positive integer database ID.
400data is required / Invalid XML format provided in data parameterSupply well-formed XML in data.
400Invalid XML structure is detectedInclude at least one <row><column>...</column></row> structure.
400row id=...Use a numeric row ID.
400Neither row id nor condition is specified ...Identify each row by id or a supported condition.
400Either column id or column name should be specified in condition ...Use a condition in the supported column='value' form.
400column id/name ... does not belong to specified databaseReference columns from the selected database.
202No data has been updatedThe request was valid, but no matching record changed.
500Internal server error occurred. Please try again later or contact support@xtracta.comRetry and contact support with the request parameters and timestamp if it persists.
Information Circle

Authentication, permission, IP-access-control, and rate-limit failures can be returned before this endpoint processes the request. Confirm the API key and caller access first.