Import label

All operations in Labelbox go through our GraphQL API. The below to query information about the first label from each of your Labelbox projects.

Run this query

query {
projects {
name,
labels(first:1) {
id,
label
}
}
}

To update an existing label, we’ll need the ID of the label. To perform the label update, use the updateLabel

Run this query

mutation {
updateLabel(
where:{
id:"<INSERT_LABEL_ID_HERE>"
}
data: {
label:"<INSERT_LABEL_DATA_STRING_HERE>"
}
) {
id
label
}
}

To create a new label for a data row, we’ll need: * the organization ID * your user ID (createdBy) * the data row ID * the project ID * the label type, which is Any unless it’s Skip

Run this query

mutation {
createLabel(
data: {
label:"<INSERT_LABEL_DATA_STRING_HERE>",
secondsToLabel: 42,
dataRow: {
connect: {
id: "<INSERT_DATA_ROW_ID_HERE>"
}
},
project: {
connect: {
id: "<INSERT_PROJECT_ID_HERE>"
}
},
type: {
connect: {
name: "Any"
}
}
}) {
id
label
}
}

The data.label argument contains a stringified JSON representation of the label prediction. It must adhere to the schema expected by the labeling interface configured for the project. The label schema for the Labelbox image labeling interface is described in more detail here.

Example in Python

# Two things to run this script
# 1. run "pip install graphqlclient"
# 2. Fill in <API-KEY-HERE>

import json
from graphqlclient import GraphQLClient
client = GraphQLClient('https://api.labelbox.com/graphql')
client.inject_token('Bearer <API-KEY-HERE>')

# Make sure you pass in label as string
# json.dumps(label_json)
def create_label(label, project_id, data_row_id):
res_str = client.execute("""
mutation CreateLabelFromApi($label: String!, $projectId: ID!, $dataRowId: ID!){
createLabel(data:{
label:$label,
secondsToLabel:0,
project:{
connect:{
id:$projectId
}
}
dataRow:{
connect:{
id:$dataRowId
}
}
type:{
connect:{
name:"Any"
}
}
}){
id
}
}
""", {
'label': label,
'projectId': project_id,
'dataRowId': data_row_id
})

res = json.loads(res_str)
return res['data']['createLabel']['id']


How did we do?