Answered

Update Form Api not allowing to reorder the fields


Userlevel 1

As the title says, I am trying to update an existing form through the API and I am getting the following error 

{"code":"VALIDATION_ERROR","description":"The payload is invalid.","details":[{"code":"WRONG_TYPE","description":"should be object","in":"body"}]}


Here is an example of the post data I use to create the form

data = [
'title' => 'title',
'type' => 'form',
'fields' => [
[
'properties' => [
'description' => 'brief',
],
'ref' => 'campaign',
'title' => 'campaign',
'type' => 'statement'
],
[
'properties' => [
'description' => 'details',
],
'ref' => 'event',
'title' => 'event,
'type' => 'statement'
]
],
'workspace' => [
'href' => 'https://api.typeform.com/workspaces/{href}
]
];


And this is the data I use to update it

 

data = [
'title' => 'title',
'type' => 'form',
'fields' => [
[
'properties' => [
'description' => 'brief',
],
'ref' => 'campaign',
'title' => 'campaign',
'type' => 'statement'
],
[
'properties' => [
'description' => 'new field',
],
'ref' => 'newfield',
'title' => 'new field',
'type' => 'statement'
],
[
'properties' => [
'description' => 'details',
],
'ref' => 'event',
'title' => 'event,
'type' => 'statement'
]
],
'workspace' => [
'href' => 'https://api.typeform.com/workspaces/{href}
]
];

 

As a side note, something I discovered is that if I add the new field below the last one, it works, is there any way I can sort the fields so I have the newly added fields where I need them?

​​​​​​​Thanks in advance!

icon

Best answer by mathio 3 May 2023, 16:34

View original

6 replies

Userlevel 7
Badge +5

@mathio do you happen to know what the issue is for this one? 😓

Userlevel 7
Badge +5

Maybe you are using PATCH instead of PUT endpoint?

 


 

I tried to create a new form with the following payload. It should be the same as the one you provided, just converted to JSON for the purpose of making the request in Postman (please double check if I didnt overlook anything from your payload).

POST /forms

{

"title": "title",
"type": "form",
"fields": [
{
"properties": {
"description": "brief"
},
"ref": "campaign",
"title": "campaign",
"type": "statement"
},
{
"properties": {
"description": "details"
},
"ref": "event",
"title": "event",
"type": "statement"
}
],
"workspace": {
"href": "https://api.typeform.com/workspaces/7rcxDr"
}
}

 

Then I tried updating the form with the following payload. It is the same as above when creating the form, only the newfield field is added to the array (in 2nd place).

PUT /form/:id

{

"title": "title",
"type": "form",
"fields": [
{
"properties": {
"description": "brief"
},
"ref": "campaign",
"title": "campaign",
"type": "statement"
},
{
"properties": {
"description": "new field"
},
"ref": "newfield",
"title": "new field",
"type": "statement"
},
{
"properties": {
"description": "details"
},
"ref": "event",
"title": "event",
"type": "statement"
}
],
"workspace": {
"href": "https://api.typeform.com/workspaces/7rcxDr"
}
}

It worked as expected. You can find my form definition here: https://form.typeform.com/forms/i2pIXcsx

Userlevel 1

@Liz @mathio thanks for the quick response, unfortunately, no, I am using PUT, I tried changing to Patch but when I did that I got a similar error

{"code":"VALIDATION_ERROR","description":"The payload is invalid.","details":[{"code":"WRONG_TYPE","description":"should be array","in":"body"}]}

Edit:
Sorry, missed the definition, will give it a try and come back, thanks again!

Userlevel 7
Badge +5

Let us know how it goes, @neovldz !

Userlevel 1

Sorry for taking so long, been a little busy, it went very well, all good now, thanks for the help guys!

Userlevel 7
Badge +5

Glad to hear it, @neovldz !

Reply