Support » Plugin: CMB2 » REST API. POST request

  • Resolved primserion

    (@primserion)


    REST API text_datetime_timestamp field format in the post request. I try “expires”: {“date”: “04/06/2021”} and “expires”: “1619006768”

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m assuming you’re trying to update the meta value in a POST request but it’s failing in some way? Is that correct? or am I not quite accurate here?

    Plugin Author Justin Sternberg

    (@jtsternberg)

    I’ve pushed some updates to the develop branch and will be in the next release which make the values passed to these fields via the REST API a little more flexible (e.g. it will take timestamps and formatted date values), but for now, you’ll have to format the data the way the field expects it.

    In the case of the text_datetime_timestamp field type, you need to give it an array with date and time values:

    curl --request POST \
      --url '<REST_URL>/cmb2/v1/boxes/<BOX_ID>/fields/<FIELD_ID>?object_id=<POST_ID>&object_type=post&value%5Bdate%5D=2021-04-09&value%5Btime%5D=13%3A45'

    Or you can include the value in the BODY of the request as JSON:

    curl --request POST \
      --url '<REST_URL>/cmb2/v1/boxes/<BOX_ID>/fields/<FIELD_ID>?object_id=<POST_ID>&object_type=post' \
      --header 'Content-Type: application/json' \
      --data '{"value":{"date":"2021-04-09","time":"19:45"}}'

    I hope that makes sense.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.