• Resolved fudgeboy

    (@fudgeboy)


    I’ve got a custom post type called “artist”, with a text ACF called “artist_first_name”.

    When I update it by sending form data, it works fine:

        [james@marlon ~] $ curl -i -k --user <redacted> "https://dev.<redacted>.com/wp-json/acf/v2/artist/39608" --data "fields[artist_first_name]=bob"
        HTTP/1.1 200 OK
        Date: Thu, 22 Dec 2016 21:18:56 GMT
        Server: Apache/2.4.18 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4
        X-Powered-By: PHP/5.4.45
        X-Robots-Tag: noindex
        Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
        Access-Control-Allow-Headers: Authorization, Content-Type
        Transfer-Encoding: chunked
        Content-Type: application/json; charset=UTF-8
        
        {"acf":{"artist_first_name":"bob"}}

    but if I try sending JSON, I get a 500 back:

        [james@marlon ~] $ curl -i -k -H "Content-Type: application/json" --user <redacted> "https://dev.<redacted>.com/wp-json/acf/v2/artist/39608" --data-binary '{"fields[artist_first_name]":"bob"}'
        HTTP/1.1 500 Internal Server Error
        Date: Thu, 22 Dec 2016 21:21:49 GMT
        Server: Apache/2.4.18 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4
        X-Powered-By: PHP/5.4.45
        X-Robots-Tag: noindex
        Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
        Access-Control-Allow-Headers: Authorization, Content-Type
        Transfer-Encoding: chunked
        Content-Type: application/json; charset=UTF-8
        
        {"code":"cant_update_item","message":"Cannot update item","data":{"status":500}}

    What am I doing wrong? How can I send a JSON body?

    • This topic was modified 8 years, 11 months ago by fudgeboy. Reason: formatting
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author airesvsg

    (@airesvsg)

    Hi @fudgeboy,
    Your JSON structure is not right.

    Try it:

    {
      "fields": {
        "artist_first_name": "Bob"  
      }
    }

    Thanks

    • This reply was modified 8 years, 11 months ago by airesvsg.
    Thread Starter fudgeboy

    (@fudgeboy)

    That’s great. Thank you.

    Is there a reason for the asymmetry between the body sent for a POST and the returned body? I have to send the ACFs in a field called fields, but in the returned JSON, they’re in a field called acf.

    This is a shame because it means extra logic in the client to do the (un)marshalling.

    This is brilliant! thanks

    How would I update a relationship type field, or post_object type field? I’ve tried passing in json that represents the object – but it doesn’t work…

    Figured it out – simply post the ID’s of the posts in an array

    `fields : {
    “artists”: [11,22,34,56]
    }

    each id represents an artist.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Can’t update ACFs using JSON’ is closed to new replies.