Re: Create a hidden form field via the REST API

Anonymous
Not applicable

Create a hidden form field via the REST API

Following this tread I'm also trying to update forms with hidden field but I can't figure how to do it.

Can you guys please show POST example on how to do it.

We have a field which is called "formCategory"

POST Example

payload = {'id': 1638, 'addFormFieldSetRequest': {

  "fieldId": "formCategory",

  "fieldType": "hidden"

}}

r = requests.post('https://...mktorest.com/rest/asset/v1/form/1638/fields.json?access_token=...', params=payload)

Response:

{'success': False, 'errors': [{'message': 'fieldId cannot be null.', 'code': '701'}], 'requestId': None, 'warnings': []}

Tags (2)
4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Create a hidden form field via the REST API

Doesn't look like you're understanding the REST docs correctly (and they are a little bit SOAP-like in this regard).

addFormFieldSetRequest is the internal name of the property bag. That string never appears in the payload. The payload has a top-level JSON object like

{

  "blankFields": 0,

  "defaultValue": "string",

  "fieldId": "string",

  "fieldType": "string",

  "fieldWidth": 0,

  "formPrefill": true,

  "hintText": "string",

  "initiallyChecked": true,

  "instructions": "string",

  "label": "string",

  "labelToRight": true,

  "labelWidth": 0,

  "maskInput": "string",

  "maxLength": 0,

  "maxValue": 0,

  "minValue": 0,

  "multiSelect": true,

  "required": true,

  "validationMessage": "string",

  "values": "string",

  "visibleLines": 0

}

Anonymous
Not applicable

Re: Create a hidden form field via the REST API

When we send "fieldType": "email" the call is success and we can see in marketo that thr form updated correctly

When send "fieldType": "hidden" the response is {'code': '611', 'message': 'System error'}

Payload with the success call

url_form_id = ".../rest/asset/v1/form/1638/fields.json"

payload = {'access_token': token,   "blankFields": 0,

  "defaultValue": "Demo",

  "fieldId": "formCategory",

  "fieldType": "email",

  "fieldWidth": 150,

  "formPrefill": "true",

  "hintText": "",

  "initiallyChecked": "true",

  "instructions": "",

  "label": "form_category",

  "labelToRight": "true",

  "labelWidth": 100,

  "maskInput": "",

  "maxLength": 255,

  "maxValue": 0,

  "minValue": 0,

  "multiSelect": "true",

  "required": "false",

  "validationMessage": "",

  "values": "",

  "visibleLines": 0}

r = requests.post(url_form_id, params=payload)

pp.pprint(r.json())

Exact Payload but now fieldType = hidden

url_form_id = ".../rest/asset/v1/form/1638/fields.json"

payload = {'access_token': token,   "blankFields": 0,

  "defaultValue": "Demo",

  "fieldId": "formCategory",

  "fieldType": "hidden",

  "fieldWidth": 150,

  "formPrefill": "true",

  "hintText": "",

  "initiallyChecked": "true",

  "instructions": "",

  "label": "form_category",

  "labelToRight": "true",

  "labelWidth": 100,

  "maskInput": "",

  "maxLength": 255,

  "maxValue": 0,

  "minValue": 0,

  "multiSelect": "true",

  "required": "false",

  "validationMessage": "",

  "values": "",

  "visibleLines": 0}

r = requests.post(url_form_id, params=payload)

pp.pprint(r.json())

Anonymous
Not applicable

Re: Create a hidden form field via the REST API

Update:

I now noticed in:

https://nation.marketo.com/thread/35651-create-a-hidden-form-field-via-the-rest-api

that this is treated as a bug - is this being taken care of? Is there an ETA? Do we have a temporary solution we can use in the meantime?

SanfordWhiteman
Level 10 - Community Moderator

Re: Create a hidden form field via the REST API

Still buggy AFAIK. The only sort-of-workaround I can think of would be adding a Rich Text area that calls addHiddenFields(). Needless to say, suboptimal, and only works (absent additional code) for constant values.