Content API upsert query difficulties

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ ] Bug report
  • [ ] Performance issue
  • [x] Documentation issue or request

Current behavior

Hello!
So I try to do upsert content of my app using content API. But I only get ‘Request failed with status code 400’ error.


Can you point me at what am I doing wrong or prompt where can I find examples of valid queries for upserting content using Content API?

Expected behavior

The upsert request upserts content.

Minimal reproduction of the problem

I try to make a post request using this piece of code:

const config = {
      headers: {
        Authorization: getters.AUTHORIZATION_TOKEN,
        'Content-Type': 'application/json',
        Accept: 'application/json'
      }
    }

// mediaPage variable consists of all the needed content data. 
const mediaPage = {                                                                                               
  title: {
    iv: 'Abc'
  },
  lead: {
    iv: '-'
  },
  views: {
    iv: 2
  },
  article: {
    iv: '-'
  },
  previewCover: {
    iv: [
      [Object]
    ]
  },
  author: {
    iv: {
      name: '-',
      role: '-',
      photo: [Array]
    }
  },
  description: {
    iv: '- '
  },
  pinned: {
    iv: true
  },
  publishedAt: {
    iv: '2021-08-20T10:38:36Z'
  },
  tags: {
    iv: [
      '-',
      '+'
    ]
  },
  readingTime: {
    iv: '5 mins'
  },
  cover: {
    iv: [
      [Object]
    ]
  }
}

const content = await this.$axios.$post(`/api/content/man-platform/media-page/${id}?publish=true`,
      mediaPage,
      config)

Environment

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [x] Cloud version

Browser:

  • [x] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Have you checked the response? It should contain all necessary information.

In catch statement I get following message:

“Request failed with status code 400”

I have never used axios myself, but it is a problem of the client library. Somehow you need to get the response string when non 2XX status code is returned.

E.g. I found this: https://stackoverflow.com/questions/45017822/catching-error-body-using-axios-post

I am not sure if it helps.

Thank you, Sebastian!
You could be surprised, but that’s helped a lot! :relaxed:

1 Like