Create Custon Organization fields

Hi everyone,

I tryng create a new custom fields in organization by api, follow bellow my code:
var sheet = SpreadsheetApp.getActiveSheet();
var fieldName = ‘’;
var url = “https://api.pipedrive.com/v1/organizationFields?api_token=”;
var startLine = 2
var dataFields = sheet.getRange(‘K2:’+‘K’+sheet.getLastRow().toString()).getValues();
for(var i=0;i<dataFields.length;i++){
var fieldName = dataFields[i][0];
data = {
“name”: fieldName,
“field_type”: “text”,
“active_flag”: true,
“edit_flag”: true,
“index_visible_flag”: true,
“details_visible_flag”: true,
“add_visible_flag”: true,
“important_flag”: true,
“bulk_edit_allowed”: true,
“searchable_flag”: true,
“filtering_allowed”: true,
“options”:[
{“label”:“Sim”},
{“label”:“Não”},
{“label”:“Não Sei Informar”}

]

}
var response = UrlFetchApp.fetch(url+api_token, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded;charset=UTF-8’
},
payload: data
})

And when I run the code I get this error:

Exception: Request failed for https://api.pipedrive.com returned code 400. Truncated server response: {“success”:false,“error”:“Options must be provided as an array. 4”,“error_info”:"Please check developers.pipedrive.com for more information about P… (use muteHttpExceptions option to examine full response)

Somebody cam help me with this error?

Thanks for attention.

Hi,

You can find information on creating custom fields here
https://developers.pipedrive.com/docs/api/v1/OrganizationFields#addOrganizationField

It could also be because of the content-type header in the request. Can you try with application/json ?