-
It appears I cannot use a JSON string as a binding for a REST API call. Is there some way around this? It seems to work if the backslashes are tripled (i.e. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
While I still haven't found a way to successfully send a JSON string as a binding in a request, I did figure out how to send the full object in a post body. You simply omit the quotes in the post body. I hate how long that took me to figure out. I just upgraded to v2.0- maybe this is a new-ish feature? JS function to send form data to binding for REST API: const addStudent = $("Role Form.Fields.addStudentRole")
const addOwner = $("Role Form.Fields.addOwnerRole")
const addCustom = $("Role Form.Fields.addCustomRole")
const studentRole = addStudent ? {
name: 'student',
description: 'for students in the group',
includeInReports: true
} : null
const ownerRole = addOwner ? {
name: 'owner',
description: 'group owner',
includeInReports: false
} : null
const customRole = addCustom ? {
name: $("Role Form.Fields.roleName"),
description: $("Role Form.Fields.roleDescription"),
includeInReports: $("Role Form.Fields.roleIncludeInReports")
} : null
const roles = [studentRole, ownerRole, customRole].filter(r => r !== null).map(r => ({
...r,
includedInGroups: [{ id: $("URL.id") }],
createdAt: new Date().toISOString(),
default: false
}))
return { input: roles } REST API post body: {
"variables": {{ yourJsonObjBinding }}
} |
Beta Was this translation helpful? Give feedback.
-
so i've found a way to successfully send JSON string json parse: let a = JSON.stringify($("State.AnswerSet"))
let result = a.replace(/"/g, '\\\"')
return result it is because for some reason budibase require 3 "\" to accept it dont ask me y cause idk either i just stumble upon it API body: {
"variables": "{{ yourJsonObjBinding }}"
} |
Beta Was this translation helpful? Give feedback.
While I still haven't found a way to successfully send a JSON string as a binding in a request, I did figure out how to send the full object in a post body. You simply omit the quotes in the post body. I hate how long that took me to figure out. I just upgraded to v2.0- maybe this is a new-ish feature?
JS function to send form data to binding for REST API: