2

How to create and update Custom Label using tooling API? Is it possible to do it without deployment? Dont want to create and update via Metadata API.

2 Answers 2

2

The Tooling API does not have a documented CustomLabel object you can interact with. The list of supported objects are listed in Tooling API Objects.

On version 42.0, there's two objects that represent labels, CustomLabel and ExternalString. However, attempting to insert, update, or delete labels results in the following error:

[ {
  "message" : "entity type cannot be inserted: Custom Label",
  "errorCode" : "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY",
  "fields" : [ ]
} ]
8
  • You can query custom labels using tooling API. Are u sure?
    – Arteezy
    Apr 26, 2018 at 19:40
  • @SouravNandy It's not in the documentation or the describe call. Are you sure you're not mistaking the Tooling API with the Metadata API?
    – sfdcfox
    Apr 26, 2018 at 19:44
  • Select id,Name from CustomLabel If i run this in query editor with Using tooling API checkbox it is giving me the values.
    – Arteezy
    Apr 26, 2018 at 21:27
  • @SouravNandy Okay, so it's new in v42, but it's not documented, and DML operations are restricted.
    – sfdcfox
    Apr 26, 2018 at 21:39
  • yea same result i also got.. just wanted to confirm... If i now go via Metadata API how should i go about..
    – Arteezy
    Apr 26, 2018 at 21:41
5

We can use tooling API to create the custom label and its translation as below.

The Master label is stored in External String and translation is stored in ExternalStringLocalization

Request to create master label:

Endpoint

/services/data/v51.0/tooling/sobjects/ExternalString

Payload

{
  "Name" : "API_Name_Of_Label",
  "MasterLabel" : "Label of Custom Label",
  "Value" : "Hi, how are you?",
  "IsProtected" : true,
  "Category" : null,
  "Language" : "en_US"
}

Response

{
  "id" : "1012v00000NNo06AAD",
  "success" : true,
  "errors" : [ ],
  "warnings" : [ ],
  "infos" : [ ]
}

We can grab the Id of Master Label and create translation by creating a record in ExternalStringLocalization. Payload would be like this:

{
  "ExternalStringId" : "1012v00000NNo06AAD",
  "Value" : "Salut comment ça va?",
  "Language" : "fr"
}

P.S: I came across the requirement to create label using API and did this POC using Workbench and thought to share this.

1
  • did you try to update a few ExternalStringLocalization by /vXX.X/tooling/composite/sobjects? I have issues getting positive results.
    – hsd
    Sep 29, 2022 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .