Data Update

Last edit:  Mar 05, 2019

Contributors:  piotrze diana-lakatos

This topic describes updating existing data in an Instance.

The data to be updated needs to be in JSON format, similarly to what you use when importing data.
Update is very similar to import, the main difference from the import tool is that update can only change existing data on an Instance. In order to use this tool, you have to first export data from the Instance (see data export). Once you have the data, modify it with your own tools (while keeping the right format), and update them to the Instance.

General information

  • Before update, your model schemas need to be deployed.

  • When updating data, the id fields must match objects that exisit on the Instance. The update tool will not create new objects, in order to do this use the data import tool.

  • No data will be deleted, update will only change existing values.

  • In order to clean value on property set the null value explicitly.

  • Update will only do basic validations — it validates types and the existence of properties. It doesn't check any of the validations defined on forms.

Data Update with CLI

The platformOS CLI provides the marketplace-kit data update command for updating data from a JSON file. It accepts one option:

  • --path (short: -p): path to a JSON data file to be updated

Under the hood, the CLI uses the GraphQL update API that's described in the next section. However, using the CLI provides some major benefits:

  • Uploading file from disk
  • Leveraging the CLI's authentication mechanism (i.e. you don't need to manually send your authentication token)

Input format

Input format is the same as for data import.

Example

To update the data from a file, run the following command in the terminal:


marketplace-kit data update --path=data.json staging-instance

Data Update with GraphQL mutations

It is possible to update data using GraphQL mutations. This gives you more flexibility, and even allows you to create your own update tool as a website feature. Please remember to handle authentication properly.

There are two main mutations for updating update_users() and update_models(). You can create a page that will update sent data.

mutation update_data(
    $users: [UserImport!]!,
    $models: [CustomizationImport!]!
  ) {
  update_users(users: $users) { ids }
  update_models(models: $models) { ids }
}

---
slug: update_data
format: json
method: post
---
{% execute_query "update_data",
  users: context.params.users,
  models: context.params.models
%}

{{ g | json }}


curl -d @transformed.json \
  -H "Content-Type: application/json" \
  -X POST https://example.com/update_data.json

Data Update with raw update API

Our CLI uses the HTTP API to update a data file. You can use it in your own tool.
Please note, that you need to provide your authentication token in the HTTP Authorization header of the request.


curl -d @data.json \
  -H "Content-Type: application/json" \
  -H "Authorization: Token token=[YOUR API TOKEN]" \
  -X POST https://example.com/api/marketplace_builder/data_updates

Questions?

We are always happy to help with any questions you may have. Check out our Help page, or contact us.