Problem during update api call in typeform | Community
Skip to main content
Answered

Problem during update api call in typeform


const { createClient } = require('@typeform/api-client')

const typeformAPI = createClient({ token: 'token' })

var data = {

    "value": {"fields":{"title": "First Name", "type": "short_text", "validations": { "required": true }}}

}

 

//form updation

const res1 = typeformAPI.forms.update({ id: 'hfiBOz3P', data:[data] }).then((response1) => {

 

  console.log("response1 : ", response1)

  return response1

}).catch((err) => {

  console.log("error: ", err)

})

 

I am using the upper mention code using in node Js to add an extra field to an existing form, but getting error(”Error: The payload is invalid.”). Help me with correct payload.

Best answer by mathio-tf

Hello,

the docs for the @typeform/api-client library say your request body must include all the existing form fields, in addition to the extra field you want to add.

The way I usually do this is I retrieve a form first, then modify the response and send the modified object to the update endpoint.

View original

5 replies

Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14840 replies
  • June 28, 2023

@picsoung or @mathio  @Harsh @jeremielp do any of you happen to have any advice on this? 


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • Answer
  • June 28, 2023

Hello,

the docs for the @typeform/api-client library say your request body must include all the existing form fields, in addition to the extra field you want to add.

The way I usually do this is I retrieve a form first, then modify the response and send the modified object to the update endpoint.


  • Author
  • Explorer
  • 2 replies
  • June 28, 2023

@mathio @Liz @Harsh  could you send me one dummy payload? how that json would looks like with my payload please? for now put the existing filed id as “field_id”.


  • Author
  • Explorer
  • 2 replies
  • June 28, 2023

After creating that form i received response as 

response1 :  {
  id: 'hfiBOz3P',
  type: 'form',
  title: 'demo typeform4',
  workspace: { href: 'https://api.typeform.com/workspaces/v3x4jA' },
  theme: { href: 'https://api.typeform.com/themes/qHWOQ7' },
  settings: {
    language: 'en',
    progress_bar: 'proportion',
    meta: { allow_indexing: false },
    hide_navigation: false,
    is_public: true,
    is_trial: false,
    show_progress_bar: true,
    show_typeform_branding: true,
    are_uploads_public: false,
    show_time_to_complete: true,
    show_number_of_submissions: false,
    show_cookie_consent: false,
    show_question_number: true,
    show_key_hint_on_choices: true,
    autosave_progress: true,
    free_form_navigation: false,
    use_lead_qualification: false,
    pro_subdomain_enabled: false,
    capabilities: { e2e_encryption: [Object] }
  },
  thankyou_screens: [
    {
      id: 'DefaultTyScreen',
      ref: 'default_tys',
      title: 'Thanks for completing this typeform\n' +
        "Now *create your own* — it's free, easy, & beautiful",
      type: 'thankyou_screen',
      properties: [Object],
      attachment: [Object]
    }
  ],
  fields: [
    {
      id: 'ENmFFAEmcLvI',
      title: 'Picture Choice Title',
      ref: '01H416151CQ6N5MH4F4VYQJP5F',
      properties: [Object],
      validations: [Object],
      type: 'picture_choice'
    },
    {
      id: 'vdtU2nsbiLMI',
      title: 'Picture Choice Title',
      ref: '01H416151CXMV1J4AFCYT809ZV',
      properties: [Object],
      validations: [Object],
      type: 'picture_choice'
    },
    {
      id: 'TjQUUbpsD779',
      title: 'Picture Choice Title',
      ref: '01H416151C2DG6VS5MZFWCYYYY',
      properties: [Object],
      validations: [Object],
      type: 'picture_choice'
    },
    {
      id: 'BLfXUF2vWeKW',
      title: 'Picture Choice Title',
      ref: '01H416151DYR1H2RKZN4RC98DY',
      properties: [Object],
      validations: [Object],
      type: 'picture_choice'
    }
  ],
  _links: { display: 'https://condenast-interactive.typeform.com/to/hfiBOz3P' }
}
and this is form link (https://condenast-interactive.typeform.com/to/hfiBOz3P)

now if I want to update this form basically add one more short_text field using api call then what this json will looks llike?

"fields":{"title": "First Name", "type": "short_text", "validations": { "required": true }}

Please provide me the correct format.

Already tried with this format 

var data = {

    "fields":[{"id": 'ENmFFAEmcLvI'},{"id": 'vdtU2nsbiLMI'}, {"id": 'TjQUUbpsD779'},{"id": 'BLfXUF2vWeKW'},{"title": "First Name", "type": "short_text", "validations": { "required": true }}]

}

but getting same error.

Pease help me in it.


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • July 3, 2023

The payload will be different for each typeform. First you need to retrieve the form, then modify that payload (eg. add new field) and send that full JSON to the update endpoint. Make sure you are using the PUT endpoint for updating the form.


Reply