• I use a few custom scripts to upload and edit WP posts through the API, accessing post data, as well as custom post data and the media through the relevant APIs.

    Since updating to 3.5 i’m getting 401 codes back. The only difference is the plugin version. I’ve testing downgrading and upgrading on two environments and it’s the plugin, not recent ACF changes.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author abhiladdha07

    (@abhiladdha07)

    Hi @outdoorsdev1,

    Thanks for reaching out.

    Can you please share the sample request you are trying and what is the exact 401 error response you are receiving so we can debug this better?

    Awaiting your response.

    Thanks,
    Team miniOrange

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

     # Upload the image

        try:

            image_response = requests.post(media_endpoint, headers=image_headers, data=image_data, verify=verify_ssl)

            image_response.raise_for_status()

            image_id = image_response.json()['id']

            if verbose:

                print(f"Image uploaded successfully for {card_info['card_title']}. Image ID: {image_id}")

            # Set the uploaded image as the featured image of the post

            post_update_data = {

                'featured_media': image_id

            }

            try:

                update_response = requests.post(f"{card_endpoint}/{card_info['post_id']}", headers=headers, json=post_update_data, verify=verify_ssl)

                update_response.raise_for_status()

                if verbose:

                    print(f"Image set as featured for {card_info['card_title']} with ID {image_id} for post ID {card_info['post_id']}.")

            except requests.exceptions.HTTPError as http_err:

                if update_response.status_code == 403:

                    print("Permission denied. You are not allowed to use this endpoint or the provided data is not allowed.")

                elif update_response.status_code == 404:

                    print("Endpoint not found. Please check the URL.")

                else:

                    print(f"HTTP error occurred while setting featured image: {http_err}")

            except requests.exceptions.ConnectionError:

                print("Connection error while setting featured image. Check your internet connection and WordPress URL.")

            except requests.exceptions.Timeout:

                print("Request timed out while setting featured image. The server might be slow or unresponsive.")

            except requests.exceptions.RequestException as err:

                print(f"An error occurred while setting featured image: {err}")

    Some example code. This is after checking and verifying I can get tokens, and they are up to date.

    In this case i’m seeing the errors below: –

    HTTP error occurred while setting featured image: 401 Client Error: Unauthorized for url: https://mysite.com/wp-json/wp/v2/card/12767
    HTTP error occurred: 401 Client Error: Unauthorized for url: https://mysite.com/wp-json/wp/v2/media/12768

    which indicate we can access the site and upload images, but a 401 error is coming back while trying to set the featured image. i’ve checked with various other test scripts and i’m able to authenticate fine.

    • This reply was modified 1 week, 4 days ago by outdoorsdev1.
    Plugin Author abhiladdha07

    (@abhiladdha07)

    Hi @outdoorsdev1,

    Thanks for the details.

    As I can see the 401 is coming from the /card endpoint itself and you are able to authenticate with our plugin successfuly so it should not be an issue from the plugin’s end.

    One thing I would like to confirm again that, if you revert back to the versiob 3.4.0 and you are able to access the API without any error? If yes, can you confirm that this /card API is the custom endpoint you developed or using the some third-party plugin so we can ourselves test on our environment and debig this better?

    Thanks,
    Team miniOrange

    I can confirm this. Reverting back to 3.4.0 solves the same issue here.

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    @abhiladdha07

    Card is an ACF endpoint for a custom post type card, which has custom fields attached. Both are exposed to the API.

    Reverting does fix the issue. Tested with the latest and previous versions of ACF.

    ACF fields are stored as a subfield in post meta fields I believe. https://www.advancedcustomfields.com/resources/wp-rest-api-integration/

    Plugin Author abhiladdha07

    (@abhiladdha07)

    Hi @outdoorsdev1 and @milank1,

    Thanks for the details and confirmation.

    We’re inspecting this issue and should be resolved shortly. Thanks for the patience.

    Meanwhile, we would recommend you use the the version 3.4.0 to have the seamless working of the plugin as had before.

    I’ll keep you posted. Stay Tuned!!

    Thanks,
    Team miniOrange

    Plugin Author abhiladdha07

    (@abhiladdha07)

    Hi @outdoorsdev1 and @milank1,

    Thanks for the patience.

    We just rolled out a new version 3.5.3 that consist of the fix for the issue you had.

    Just follow the below simple steps to fix the issue on your WP environment –

    • Go to Protected REST APIs section. 
    • Click on Save Settings and test the API again using the authentication method you have configured.

    Please test and let us know the updates.

    Thanks,
    Team miniOrange

    • This reply was modified 4 days, 8 hours ago by abhiladdha07.

    Hi @abhiladdha07,
    This seems to fix it, the same code runs fine now, yielding response code 200 as expected.
    Thank you.
    M.

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    Seems to have worked now, thanks for fixing the issues ??

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