How to add new or existing multi-select tags when creating a page in Notion API? - api

I can't figure out how to add multi-select tags when creating a page in Notion API. Single select tags are extremely easy to add:
"City": {
"select": {
"name": "New York",
}
}
But my attempts to add multi-select tags end up failing.
"City": {
"multi_select": {
"options": [
{
"name": "New York",
"color": "red"
},
{
"name": "Tbilisi",
"color": "gray"
}
]},
}
Here's the error I get
{"object":"error","status":400,"code":"validation_error","message":"body failed validation. Fix one:\nbody.properties.City.title should be defined, instead was `undefined`.\nbody.properties.City.rich_text should be defined, instead was `undefined`.\nbody.properties.City.number should be defined, instead was `undefined`.\nbody.properties.City.url should be defined, instead was `undefined`.\nbody.properties.City.select should be defined, instead was `undefined`.\nbody.properties.City.multi_select should be an array, instead was `{\"options\":[{\"name\":\"apple\",\"color\":\"red\"},{\"name\":\"Ora...`.\nbody.properties.City.people should be defined, instead was `undefined`.\nbody.properties.City.email should be defined, instead was `undefined`.\nbody.properties.City.phone_number should be defined, instead was `undefined`.\nbody.properties.City.date should be defined, instead was `undefined`.\nbody.properties.City.checkbox should be defined, instead was `undefined`.\nbody.properties.City.relation should be defined, instead was `undefined`.\nbody.properties.City.files should be defined, instead was `undefined`.\nbody.properties.City.status should be defined, instead was `undefined`.\nbody.properties.Name.id should be defined, instead was `undefined`.\nbody.properties.Name.name should be defined, instead was `undefined`.\nbody.properties.Name.start should be defined, instead was `undefined`."}
Do you have a working example of how it should be done?
Here's the full payload
newPageData = {
"parent": { "database_id": 'some id' },
"properties": {
"Name": {
"title": [
{
"text": {
"content": "New page"
}
}
]
},
"City": {
"multi_select": {
"options": [
{
"name": "New York",
"color": "red"
},
{
"name": "Tbilisi",
"color": "gray"
}
]},
},
"Date": {
"date": {
"start": "2023-02-06",
"end": None,
}
},
"Link": {
"url": "example.info"
}
}
}

When populating / updating a Multi-Select property, you don't need to include "options" or specify the option's colour so this should work -
"City": {
"multi_select": [
{
"name": "New York"
},
{
"name": "Tbilisi"
}
]
}
you should remove the first comma at the end of your list of options for the City property too -
]},
},

Related

How to create a new database on Notion API with the new "Status" property?

Notion API HTTP requests are not working when I add a new "Status" propoerty for a new database creation.
I've been trying for a while to figure out why, sending Notion a simple HTTP POST request with a "Status" breaks it.
If I just replace "Status" with a simple "Select" it works fine...
This is the code that I tried on my latest attempt:
{
"is_inline": true,
"parent": {
"type": "page_id",
"page_id": page_id
},
"icon": {
"type": "emoji",
"emoji": "🐟"
},
"title": [
{
"type": "text",
"text": {
"content": "Catches",
"link": null
}
}
],
"properties": {
"Name": {
"title": {}
},
"Status": {
"status": {
"options": [
{
"name": "Not started",
"color": "default"
},
{
"name": "25% Complete",
"color": "blue"
},
{
"name": "50% Complete",
"color": "blue"
},
{
"name": "75% Complete",
"color": "blue"
},
{
"name": "Done",
"color": "green"
},
{
"name": "Blocked",
"color": "red"
}
]
}
}
}
}
Status ref page on Notions docs: https://developers.notion.com/reference/property-object#status-configuration

Certain relations are added to the product entity for no reason

I have been using OroCommerce's API for creating products through POST requests. The request works fine but I have one problem once the entity has been created. For some reason, OroCommerce will add extra relations to the product entity.
For example, if I create a product with the name "testt", the request will have the following data :
{
"data": {
"type": "products",
"attributes": {
...
},
"relationships": {
"data": [
{
"type": "productnames",
"id": "name"
}
]
}
},
"included": [
{
"type": "productnames",
"id": "name",
"attributes": {
"fallback": null,
"string": "testt"
},
"relationships": {
"localization": {
"data": null
}
}
},
...
]
}
But when I send the POST request, the resulting entity I get has 2 name relationships instead of one, here's what the data of the resulting entity looks like with a GET request and including names :
"included": [
{
"type": "productnames",
"id": "450",
"attributes": {
"string": null,
"fallback": "system"
},
"relationships": {
"product": {
"data": {
"type": "products",
"id": "445"
}
},
"localization": {
"data": {
"type": "localizations",
"id": "1"
}
}
}
},
{
"type": "productnames",
"id": "451",
"attributes": {
"string": "testt",
"fallback": null
},
"relationships": {
"product": {
"data": {
"type": "products",
"id": "445"
}
},
"localization": {
"data": null
}
}
},
...
]
As you can see, the resulting object has an extra name relationship, even though it was never in the initial POST request to start with. I have the same issue with descriptions, shortDescriptions, where a relation with empty data gets created even if I explicitly set the data to null in the POST request.
Is there a way to prevent this?
The case is that every localizable field MUST have a value for every localization and one by default.
Such entities as
productnames
productdescriptions
productshortdescriptions
localizedfallbackvalues
can contain either a string value or fallback link to the default value or some other localization.
As is seen from your examples you have only one localization so when you create a product with
{
"type": "productnames",
"id": "name",
"attributes": {
"fallback": null,
"string": "testt"
},
"relationships": {
"localization": {
"data": null
}
}
}
the system creates a "productnames" instance with a string value inside as a default value
{
"type": "productnames",
"id": "451",
"attributes": {
"string": "testt",
"fallback": null
},
"relationships": {
"product": {
"data": {
"type": "products",
"id": "445"
}
},
"localization": {
"data": null
}
}
}
and then automatically adds "productnames" instances for each localization with fallback links (in your case one instance)
{
"type": "productnames",
"id": "450",
"attributes": {
"string": null,
"fallback": "system"
},
"relationships": {
"product": {
"data": {
"type": "products",
"id": "445"
}
},
"localization": {
"data": {
"type": "localizations",
"id": "1"
}
}
}
}
An absence of localizable field default value in a POST body will trigger "Not Null constraint".
So as detailed above every localizable field MUST has a value (or fallback) for each localization. So every time a product or localization entity is created system adds a linking entity for every intersection of every localizable field and every localization.

How can I achive that enable all checkboxes in jsonschema after I check radio button?

Okey. I have a jsonschema as below. I am trying to get all the items (colors - checkboxes) clicked by default when the radio button "YES" is marked. On the contrary, if the "NO" button is clicked, all the colors will be unchecked.
JsonSchema
{
"title": "Item Type Filtering Form",
"description": "Form for filtering Item Types according to selected Attribute Values.",
"type": "object",
"properties": {
"colorAll": {
"type": "boolean",
"title": "Seat Color All",
"enum": [
false,
true
],
"enumNames": [
"NO",
"YES"
],
"default": true
},
"colorList": {
"type": "array",
"title": "Seat Color",
"items": {
"type": "object",
"enum": [
{
"id": 1,
"label": "RED"
},
{
"id": 2,
"label": "BLUE"
},
{
"id": 3,
"label": "GREEN"
}
],
"enumNames": [
"RED",
"BLUE",
"GREEN"
]
},
"uniqueItems": true
}
}
}
UISchema
{
"colorAll": {
"ui:widget": "radio",
"ui:options": {
"inline": true
}
},
"colorList": {
"ui:widget": "checkboxes",
"ui:options": {
"inline": true
}
}
}
I am practising it on the page https://mozilla-services.github.io/react-jsonschema-form/# but none of my tries is working how I described above...
I thought, that I can make it with "default:" keyword and put all the values into it -> JsonSchema is valided, but it didn't work.
Can somebody help me with it?
Currently It does not seems to be possible
{
"title": "Schema dependencies",
"description": "These samples are best viewed without live validation.",
"type": "object",
"properties": {
"conditional": {
"title": "Conditional",
"$ref": "#/definitions/person"
}
},
"definitions": {
"person": {
"title": "Person",
"type": "object",
"properties": {
"colorAll": {
"type": "string",
"enum": [
"No",
"Yes"
],
"default": "No"
}
},
"required": [
"colorAll"
],
"dependencies": {
"colorAll": {
"oneOf": [
{
"properties": {
"colorAll": {
"enum": [
"Yes"
]
},
"colorList": {
"type": "array",
"title": "Seat Color",
"items": {
"type": "string",
"enum": [
"RED",
"BLUE",
"GREEN",
"Yes Only",
"ABC"
]
},
"default": [
"RED",
"BLUE",
"Yes Only"
],
"uniqueItems": true
}
}
},
{
"properties": {
"colorAll": {
"enum": [
"No"
]
},
"colorList": {
"type": "array",
"title": "Seat Color",
"items": {
"type": "string",
"enum": [
"RED",
"BLUE",
"GREEN"
]
},
"uniqueItems": true
}
}
}
]
}
}
}
}
}
if you run the above in playground, the list of colors changes, but it does not select the default ones. but if you have colorList has standalone component, it selects the default ones.
To change the default selected values, you need to use the "onChange" property of the form (https://react-jsonschema-form.readthedocs.io/en/latest/#form-data-changes) and handle that logic on your own. Thus, you can check if the radio button was toggled to true or false, and if so, set colorList to
[
{
"id": 1,
"label": "RED"
},
{
"id": 2,
"label": "BLUE"
},
{
"id": 3,
"label": "GREEN"
}
]
or [] respectively.
Note the following warning in the doc:
WARNING: If you have situations where your parent component can re-render, make sure you listen to the onChange event and update the data you pass to the formData attribute.
Here's an example codepen I set up that manages the two properties:
https://codepen.io/anon/pen/VOjJmY
Also note that because the actual value is an object, I think you have to reuse the same object (hence the direct use of schema.properties.colorList.items.enum).
I think there is a bug with React JSON Schema Form because the checkboxes' UI state doesn't get updated in the right lifecycle or something. The state is correctly updated, but I can't the un-toggle all/toggle all effect to happen on correct state, but rather the follow toggle... Like on going from "YES" -> "NO" -> "YES" they all switch off, and then going from "YES" -> "NO" they would switch back on...

Ember Data JSON-API hasMany: How?

I'm familiar with the old ember-data "sideloading" model, which would look like this:
```
{
authors:[
{id:1, name:"Ernest", type: 'author', books: [1,2]
],
books: [
{id:1, name: "For whom the bell tolls", type: 'book', author:1},
{id:2, name: "Farewell To Arms", type: 'book', author:1}
]
}
But the new JSON-API method is different.
For one thing, (and I like this), attributes are separated from the id and type information, preventing namespace collisions.
I don't yet understand how to do a hasMany relationship with the JSON-API format. Can anyone point me to a doc or article on how this is expected? The examples on the JSON-API page show individual relationships, but not hasMany.
If you could write the above example in the new format, you'd have answered my question.
I found the answer in The JSON-API spec.
Each model should have a relationships key, whose value is an object with a key for each named relationship, which also has a data key that can be either a single object or an array for a hasMany relationship.
By providing an included key as top-level member, I can lazy load the entities.
In this case, the above example would be:
{
"data": [
{
"id": 1,
"type": "author",
"attributes": {
"name": "Ernest"
},
"relationships": {
"books": {
"data": [
{
"id": "1",
"type": "book"
},
{
"id": "2",
"type": "book"
}
]
}
}
}
],
"included": [
{
"id": 1,
"type": "book",
"attributes": {
"name": "For Whom the Bell Tolls"
},
"relationships": {
"author": {
"data": {
"id": 1,
"type": "author"
}
}
}
},
{
"id": 2,
"type": "book",
"attributes": {
"name": "Farewell to Arms"
},
"relationships": {
"author": {
"data": {
"id": 1,
"type": "author"
}
}
}
}
]
}
FYI: If you want to fetch a hashMany relationship at a later time, you have two other options.
1. Use a Related Resource Link:
As soon as the hashMany relationship is needed, Ember Data will call the backend with related link to fetch all the relations.
{
"data": [{
...,
"relationships": {
"books": {
"links" {
"related": "http://example.com/books"
}
}
}
}]
}
2. Use find-ids
As soon as the hashMany relationship is needed, Ember Data will call the backend with an url to fetch given ids. In this example it would be http://example.com/books?ids=1&ids=2
{
"data": [{
...,
"relationships": {
"books": {
"books": {
"data" [{
"id": "1",
"type": "book"
}, {
"id": "2",
"type": "book"
}]
}
}
}
}]
}

Jira REST API: create issue linked to another one

I'd like to link an issue to an existing one at creation using the REST API. The idea is not to CREATE then UPDATE, but just CREATE.
Here is my JSON:
{
"issueUpdates": [
{
"fields": {
"project": {
"key": "CMDB"
},
"issuetype": {
"id": "10500"
},
"summary": "VMP-MYSQL-01",
"issuelinks": [
{
"type": {
"name": "Relates",
"inward": "relates to",
"outward": "relates to"
},
"inwardIssue": {
"key": "CMDB-825"
},
"outwardIssue": "CMDB-825"
}
],
"customfield_10600": "VMP-MYSQL-01"
}
}
]
}
The error I get is:
{
"issues": [],
"errors": [
{
"status": 400,
"elementErrors": {
"errorMessages": [],
"errors": {
"issuelinks": "Field does not support update 'issuelinks'"
}
},
"failedElementNumber": 0
}
]
}
Does the API support the creation of Linked Issue at creation? Using the GUI works.
Jira is running v6.2.
Since this question is a bit older, I've been experiencing same issue as you. After some searching I found that instead of fields you can use update in the json you send to server.
Alternatively, you can use issueLink method to add links after creating the issue.
Complete code to create an issue with a link to a different issue:
{
"fields": {
"summary": "Sample Issue",
"project": {
"id": 14505
},
"issuetype": {
"id": 11002
}
},
"update": {
"issuelinks": [
{
"add": {
"type": {
"name": "Relates"
},
"inwardIssue": {
"key": "PRJ-1"
}
}
}
]
}
}
This will solve your problem. This will create an issue with one jira issue linked to it.
key is a project key,
Blocks or related to whichever you want.
put below json into http://jsonlint.com/. It will do proper formatting.
{
"fields": {
"summary": "Test Adapter",
"project": {
"key": "WFM"
},
"description": "Testing of Jira from Adapter",
"issuetype": {
"name": "Bug"
},
"update": {
"issuelinks": [{
"add": {
"type": {
"name": "Blocks",
"inward": "is blocked by",
"outward": "blocks"
},
"outwardIssue": {
"key": "WFM-28",
"fields": {
"summary": "Test Adapter"
}
}
}
}]
}
}
}