Skip to content
New issue

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

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

Already on GitHub? # to your account

[Docs] add response example for bulk entities upload #1166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spwoodcock
Copy link
Member

Issue

  • Currently the docs for POST /projects/{projectId}/datasets/{name}/entities show the response type for uploading a single Entity.
  • They have not been updated to show the response type when bulk uploading multiple Entities.
  • Ideally the response would return the Entity data, but this is not trivial, due to having to re-fetch data from the db for each Entity (line 98 & 113):
    if (!entities) {
    // not a bulk operation
    const partial = await Entity.fromJson(body, properties, dataset);
    const sourceId = await Entities.createSource();
    const entity = await Entities.createNew(dataset, partial, null, sourceId, userAgent);
    // Entities.createNew doesn't return enough information for a full response so re-fetch.
    return Entities.getById(dataset.id, entity.uuid).then(getOrNotFound);
    } else {
    // bulk operation
    if (!Array.isArray(body.entities))
    return reject(Problem.user.unexpectedAttributes({ expected: ['entities: [...]'], actual: ['not an array'] }));
    if (!body.entities.length)
    return reject(Problem.user.unexpectedAttributes({ expected: ['entities: [...]'], actual: ['empty array'] }));
    const partials = body.entities.map(e => Entity.fromJson(e, properties, dataset));
    const sourceId = await Entities.createSource(extractBulkSource(source, partials.length, userAgent));
    await Entities.createMany(dataset, partials, sourceId, userAgent);
    return success();
    }

Solution

  • The endpoint currently returns 'success': true.
  • I updated the docs to reflect this, until the endpoint returns the Entity data (if possible).
  • I reused the pattern in the docs for return type application/json; extended to use application/json; bulk, allowing us to display two examples side-by-side - not sure if this is the preferred approach!

@matthew-white matthew-white self-requested a review October 1, 2024 21:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant