Create a json metafield

JSON object must be stringifyed before being sent.

<!-- JavaScript + Liquid -->
<script type="text/javascript">
  ravenSubmit = (value) => {
    const ravenObj = {%- render 'raven-mac-gen', resource_id: page.id, raven_id: 'TBD' -%}
    const valueObj = { value: value };
    const requestParams = { raven: Object.assign({}, ravenObjOne, valueObjOne) };
    const response = fetch('/apps/raven/create_metafield', {
      method: 'PUT',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(requestParams)
    })

    response
      .then(res => res.json())
      .then(resJson => console.log('resJson: ', resJson))
  }
</script>

<!-- HTML -->
<button id="fieldsraven-demo" onclick="ravenSubmit(JSON.stringify({fav_color: 'Yellow', hobby: 'Soccer'}))">Send the Raven!</button>

Last updated