acf-to-rest-api icon indicating copy to clipboard operation
acf-to-rest-api copied to clipboard

cant_update_item

Open modemmike opened this issue 6 years ago • 17 comments

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.

modemmike avatar Aug 01 '18 00:08 modemmike

Hi @modemmike,

My first question is: are you using the corrects credentials?

Thanks

airesvsg avatar Aug 01 '18 01:08 airesvsg

Thank for a quick response!

I'm using an administrator account with oauth.

modemmike avatar Aug 01 '18 01:08 modemmike

With PostMan I sometimes get:

Unexpected 'W'

modemmike avatar Aug 01 '18 01:08 modemmike

I think I just got it working... I may have been using the wrong Content-Type... damn, the simplest things.

modemmike avatar Aug 01 '18 01:08 modemmike

I think your have some typo in your code, because the unexpected 'W'.

airesvsg avatar Aug 01 '18 01:08 airesvsg

@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.

Awert88 avatar Aug 01 '18 09:08 Awert88

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 avatar Aug 24 '18 15:08 Mulli

@Mulli check your content type... should be application/json

modemmike avatar Aug 24 '18 15:08 modemmike

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 avatar Aug 26 '18 08:08 Mulli

@Mulli didn't find soulution. Ended up using update_field and processing data from file.

Any luck on your side?

Awert88 avatar Aug 27 '18 06:08 Awert88

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 ) );
		}

Mulli avatar Aug 30 '18 05:08 Mulli

Running into this same issue.... Yes I am authenticated via basic auth and GET works fine.

I cant update a user

vstlouis avatar Nov 19 '18 22:11 vstlouis

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...

Mulli avatar Nov 20 '18 18:11 Mulli

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.

Zyles avatar Jun 30 '20 21:06 Zyles

This issue triggers also when updating ACF fields of taxonomies. I can confirm that it isn't patched yet.

henrique-voni avatar Aug 17 '20 21:08 henrique-voni

You have to send:

{
  "fields": {
      "field_name": ""
  }
}

fkropfhamer avatar Sep 15 '20 15:09 fkropfhamer

I think this same issue exists for the media endpoints too.

chrissy-dev avatar Jul 06 '21 14:07 chrissy-dev