# How to add custom field option using google scripts?

**URL:** <https://community.developer.atlassian.com/t/how-to-add-custom-field-option-using-google-scripts/33121>\
**Category:** Trello\
**Tags:** javascript\
**Created:** [November 4, 2019, 2:31am UTC](https://community.developer.atlassian.com/t/how-to-add-custom-field-option-using-google-scripts/33121 "2019-11-04T02:31:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DylanJames](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@DylanJames](https://community.developer.atlassian.com/u/DylanJames)\
**Post date:** [November 4, 2019, 2:31am UTC](https://community.developer.atlassian.com/t/how-to-add-custom-field-option-using-google-scripts/33121/1 "2019-11-04T02:31:32Z")

</div>

How would I do this:

```javascript
var url = "https://api.trello.com/1/cards/{idCard}/customField/{idCustomField}/item?token={yourToken}&key={yourKey}";
var data = {value: { number: "42" }};
fetch(url, { body: JSON.stringify(data), method: 'PUT', headers: {'content-type': 'application/json'}})
.then((resp) => resp.json())
.then((data) => console.log(JSON.stringify(data, null, 2)))
.catch((err) => console.log(JSON.stringify(err, null, 2)))

```

In order to change the options in a pre-defined custom field on a card,  
However I can’t use fetch on google scripts, I’m constrained to using google’s “UrlFetchApp.fetch”  
class [Class UrlFetchApp &nbsp;|&nbsp; Apps Script &nbsp;|&nbsp; Google Developers](https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app)

I’ve attempted this:

```javascript
var url = "https://api.trello.com/1/cards/" + cardId + "/customField/[CustomID]/item?token=[Token]&key=[Key]";
var data = {value: { "text": "42" }};
var payload = {"customField" : data};
var options = {"method" : "put",
               "payload" : payload};
UrlFetchApp.fetch(url,options);  

```

But I get this error But I get this error:   
`Request failed for https://api.trello.com returned code 400. Truncated server response: Invalid value for custom field type`

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![bentley](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/bentley/32/36116_2.png) [@bentley](https://community.developer.atlassian.com/u/bentley)\
**Post date:** [November 5, 2019, 5:01pm UTC](https://community.developer.atlassian.com/t/how-to-add-custom-field-option-using-google-scripts/33121/2 "2019-11-05T17:01:20Z")

</div>

I think this may have to do with the way that you’re `payload` is being passed in.

I don’t think that you need `var payload = {"customField" : data};` Trello never looks for a `customField` key in the body of the request.

Can you try deleting the `var payload =` line and replacing your `var options = ...` with:

```auto
var options = {
  "method" : "put",
  "payload" : JSON.stringify(data),
  "contentType": "application/json"
};

```

You’ll notice in the [`fetch()` examples here](https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetch(String,Object)) they specifically call out `Convert the JavaScript object to a JSON string`

---

<div class="post-metadata">

**Author:** ![DylanJames](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@DylanJames](https://community.developer.atlassian.com/u/DylanJames)\
**Post date:** [November 5, 2019, 7:07pm UTC](https://community.developer.atlassian.com/t/how-to-add-custom-field-option-using-google-scripts/33121/3 "2019-11-05T19:07:50Z")

</div>

Thank you so much, it works!
