acf-to-rest-api
acf-to-rest-api copied to clipboard
cant_update_item
Authentication: oAuth
End Point: /wp-json/acf/v3/product/999
JSON Posted:
fields: {
"type": "",
"online": "",
"subtitle": "",
"lead_line": "testing 123454566",
"content_marketing": "",
"authors": "",
"new_edition": "",
"copyright": "",
"size": "",
"publisher": "",
"pages": "",
"edition": "",
"skills": "",
"grades": "",
"colorbw": "",
"run_time": "",
"subtitles": "",
"features": "",
"samples": "",
"featured_series": "",
"new_notable": "",
"parent_record_id": false,
"series_record_id": false,
"media_text": "",
"isbn": "",
"proprietary": "",
"file_name": "",
"extension": "",
"file_size": "",
"subject": "",
"subject2": "",
"subject3": "",
"grade_code": "",
"grade_level_start": "",
"grade_level_end": "",
"media_type": "",
"media_type_2": ""
}
Error:
{
"code": "cant_update_item",
"message": "Cannot update item",
"data": {
"status": 500
}
}
Any clue as to why?
Thank you for your time.
Hi @modemmike,
My first question is: are you using the corrects credentials?
Thanks
Thank for a quick response!
I'm using an administrator account with oauth.
With PostMan I sometimes get:
Unexpected 'W'
I think I just got it working... I may have been using the wrong Content-Type... damn, the simplest things.
I think your have some typo in your code, because the unexpected 'W'.
@airesvsg Would appreciate any help, as it seems to me I've tried everything I found and still no luck.
So I'm using: ACF to REST API - 3.1.0 Application Passwords - 0.1-dev Advanced Custom Fields PRO - 5.7.1
Trying to work with: /wp-json/acf/v3/product_cat/127/ Testing with Postman Authorization - Basic Auth
GET request returns info
{
"acf": {
"seo_title": "Купить билеты на СКА - Барыс в Ледовом дворце | Билеты онлайн в Санкт-Петербурге (СПб)",
"seo_description": "",
"listing_text": "СКА - БАРЫС",
"logo_1": false,
"logo_2": "http://bilety-na-ska.ru/wp-content/uploads/2017/09/Barys-.png",
"date": "27.11.2017",
"sorting_date": "27.11.2017",
"time": "19:30",
"place": "ЛЕДОВЫЙ ДВОРЕЦ",
"content": ""
}
}
PUT requests looks like
Headers
Content-Type: application/json; charset=UTF-8
Raw data:
{
"fields": {
"place": "The value goes here"
}
}
Response is always:
{
"code": "cant_update_item",
"message": "Cannot update item",
"data": {
"status": 500
}
}
Thanks in advance for any hints.
I am having the same problem for days now. Tried v2, v3 - no luck.
I also have acf pro, with custom post type "referral" havind long "acf" object as in your case. GET works fine but POST for update fails. Do you have some working example??? Any idea how to proceed? or should I GIVE UP??? Thanks
@Mulli check your content type... should be application/json
It is... "Content-Type →application/json; charset=UTF-8
"
But I find the Allow -> GET
(no post!) see below
The post is generated but returns acf: false
Access-Control-Allow-Headers →Authorization, Content-Type
Access-Control-Expose-Headers →X-WP-Total, X-WP-TotalPages
Allow →GET
Cache-Control →no-cache, must-revalidate, max-age=0
Connection →Keep-Alive
Content-Length →1032
Content-Type →application/json; charset=UTF-8
Date →Sun, 26 Aug 2018 07:52:29 GMT
Expires →Wed, 11 Jan 1984 05:00:00 GMT
Keep-Alive →timeout=5, max=100
Link →<http://yahav/wp-json/>; rel="https://api.w.org/"
Location →http://yahav/wp-json/wp/v2/digma_referrals/5886
Server →Apache/2.4.27 (Win64) PHP/7.0.23
X-Content-Type-Options →nosniff
X-Powered-By →PHP/7.0.23
X-Robots-Tag →noindex
Is this a problem? and If so what am I missing? Thanks!!!
@Mulli didn't find soulution. Ended up using update_field and processing data from file.
Any luck on your side?
Seems that I shall have to code it myself.
I was hoping to find a simple way to post/put data from clients.
I suspect that in ...legacy/v2/lib/endpoints/class-acf-to-rest-controller.php
The update_item
function fails to update.
The big question is how to fix it?
Any tip is much appreciated
public function update_item( $request ) {
$item = $this->prepare_item_for_database( $request );
if ( is_array( $item ) && count( $item ) > 0 ) {
foreach ( $item['data'] as $key => $value ) {
if ( isset( $item['fields'][ $key ]['key'] ) ) {
$field = $item['fields'][ $key ];
if ( function_exists( 'acf_update_value' ) ) {
acf_update_value( $value, $item['id'], $field );
} elseif ( function_exists( 'update_field' ) ) {
update_field( $field['key'], $value, $item['id'] );
} else {
do_action( 'acf/update_value', $value, $item['id'], $field );
}
}
}
return new WP_REST_Response( $this->get_fields( $request ), 200 );
}
return new WP_Error( 'cant_update_item', __( 'Cannot update item', 'acf-to-rest-api' ), array( 'status' => 500 ) );
}
Running into this same issue.... Yes I am authenticated via basic auth and GET works fine.
I cant update a user
My solution is to generate a plugin with new endpoints in v3 and use acf with my code to make sure that my updates/creation works It works...
So not solved since 2018?
Same problem.
Can't update items using the API using https://sv.wordpress.org/plugins/jwt-auth/ as authentication method.
This issue triggers also when updating ACF fields of taxonomies. I can confirm that it isn't patched yet.
You have to send:
{
"fields": {
"field_name": ""
}
}
I think this same issue exists for the media
endpoints too.