Creating a task by API

I am able to create a task via the API, which works as expected.

[{ 
"command": "fibery.entity/create", 
  "args": {
    "type": "Tasks/Task",
    "entity": {
        "Tasks/name": "Test Task Create via API 2",
        "Tasks/Type": { "fibery/id": "30335333-f30a-31e3-a3a3-dbdc3c340ab3" }
    }
  }
}]

The docs say:

Setting entity collection Fields on Entity creation is not supported.

Just want to confirm the meaning of this. If I have a different app acting as a picklist for say, Contracts, that I want to separate and group my tasks and projects etc by, then does the above mean I cannot auto-set this at the time of Task creation?

When I push the above json to https://myco.fibery.io/api/commands, I see in the response that there’s a fibery/id returned, so is the idea to pick that up and use it to do an update?

I can see it for a many:many relation. But in the case that a task can have only one related contract, it seems it should be possible to drop a uuid somewhere at the same time as making the task via API?

If I want it in one step, I can do it by putting Contract in as a standard multiselect field, but that means I need to have duplicate contract lists in each place I need to be able to select Contract, and would need to maintain it. Not so attractive.

In the end, my goal is to create tasks for clients, so they appear under the correct Contract backlog, and not under the general backlog, because it saves steps for users.

What’s possible?

Hey Rick!

You’re on the right track!
Everything depends on how many Contracts could a Task belong to.

Task belongs to one Contract only
Create a Task and connect it to the right Contract in a single command:

[{ 
"command": "fibery.entity/create", 
  "args": {
    "type": "Tasks/Task",
    "entity": {
        "Tasks/name": "Test Task Create via API 2",
        "Tasks/Type": { "fibery/id": "30335333-f30a-31e3-a3a3-dbdc3c340ab3" },
        "APP_NAME/Contract": { "fibery/id": "CONTRACT_FIBERY_ID" }
    }
  }
}]

Task can belong to multiple Contracts
Two commands executed one after another is the way to go:

  1. Create a Task the way you currently do and get its fibery/id in response

  2. Update Contracts collection via fibery.entity/add-collection-items command:

    [
      {
        "command": "fibery.entity/add-collection-items",
        "args": {
        "type": "Tasks/Task",
        "field": "APP_NAME/Contracts",
        "entity": { "fibery/id": "TASK_FIBERY_ID" },
        "items": [
           { "fibery/id": "CONTRACT_1_FIBERY_ID" },
           { "fibery/id": "CONTRACT_2_FIBERY_ID" }
          ]
        }
      }
    ]
    

Note that in both cases Contracts should already exitst. If they don’t you’ll need an extra command to create them.

Please let us know if it works for you.

Thanks! Ok, I tried the “task belongs to one contract”, but got an error:

Field SOW/SOW was not found in type Tasks/Task.

In this case I generified SOW to “Contract” to more easily explain it above. Our SOW is a separate app that I am selecting from.

Hey Rick!

Sorry for the late reply.
Could you please share you schema (https://api.fibery.io/#get-schema) with us via Intercom?
Probably, there is something wrong with the namespace (the thing that goes before ‘/’ symbol).

thanks @antoniokov, duly pasted into intercom.

This got solved by following Anton’s instruction in intercom, just to close the loop here:

The solution is to replace SOW/SOW with user/SOW. You’ve built your Fields on top of an App from App Gallery, which is perfectly legal. In this case we distinguish native Fields from custom ones using the namespace: Tasks/ or SOW/ vs. user/. This helps us to update Apps without affecting customizations, but brings a bit of complexity when working with API.

1 Like