Title: Could not create snippet. Request failed with status code 500
Last modified: May 30, 2023

---

# Could not create snippet. Request failed with status code 500

 *  Resolved [dimitribrouers](https://wordpress.org/support/users/dimitribrouers/)
 * (@dimitribrouers)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/)
 * Hello to all, I tried to add the code below to the functions.php file via Code
   Snippets, add_cap( ‘read_private_pages’ ); ?>
 * but I get the following error message when I save it on the plugin:
 * Could not create snippet. Request failed with status code 500
 * The strange thing is that I tried it on another site and it worked perfectly 
   well.
 * Could you please help me find out what happened?
 * Thank you very much!

Viewing 15 replies - 1 through 15 (of 41 total)

1 [2](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/2/?output_format=md)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16779915)
 * There’s definitely something about server configuration that’s causing this to
   happen – it’s not something we encountered during testing.
 * If you open your browser console (right-click -> Inspect -> Console), can you
   see any error messages?
 *  Thread Starter [dimitribrouers](https://wordpress.org/support/users/dimitribrouers/)
 * (@dimitribrouers)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16789070)
 * Thanks a lot [@bungeshea](https://wordpress.org/support/users/bungeshea/) 
   Indeed,
   I discovered these errors!!!
 *     ```wp-block-code
       JQMIGRATE: Migrate is installed, version 3.4.0
       post-1000.css:1     Failed to load resource: the server responded with a status of 404 ()
       post-1050.css:1     Failed to load resource: the server responded with a status of 404 ()
       post-1050.css:1     Failed to load resource: the server responded with a status of 404 ()
       post-1000.css:1     Failed to load resource: the server responded with a status of 404 ()
       DevTools failed to load source map: Could not load content for https://mywebsitedomain/wp-content/plugins/elementor/assets/lib/swiper/v8/swiper-bundle.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
       DevTools failed to load source map: Could not load content for https://mywebsitedomain/wp-content/plugins/advanced-custom-fields-pro/assets/build/css/acf-input.css.map: Connection error: net::ERR_CONNECTION_RESET
       ```
   
 * I think I have to sent a message to my host’s support team… Is there anything
   in particular to highlight in my request?
 *  [fredywebs](https://wordpress.org/support/users/fredywebs/)
 * (@fredywebs)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16819128)
 * I’m having the same problem. I can’t create or update any snippets. It started
   happening after updating WordPress to 6.2.2 and Code Snippets to 3.4.0.
 * There are two errors in the console that only appear after saving an individual
   snippet: “POST [https://www.uhliska.sk/wp-json/code-snippets/v1/snippets/22](https://www.uhliska.sk/wp-json/code-snippets/v1/snippets/22)
   500” and “Request failed”.
 * However, could there be a problem with WooCommerce compatibility? I can see this
   error: “CRITICAL Uncaught Error: Call to a member function get_cart() on null”.
   Strangely, I can’t even update any other snippet where `get_cart()` is not used.
   I’m really not sure what to do.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16824765)
 * I think the error message you’re receiving is unrelated to the saving error.
 * I can’t be sure what is causing the error (500 is a very generic error code),
   but we’re working on a few potential fixes that we’re hoping to push out asap.
 *  [fritos](https://wordpress.org/support/users/fritos/)
 * (@fritos)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16841151)
 * Hi,
 * I also get “Could not update snippet. Request failed with status code 500”. Can’t
   add or edit existing snippets.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16871311)
 * Hi [@fritos](https://wordpress.org/support/users/fritos/),
 * Would it be possible to confirm whether you’re still experiencing this issue 
   in the v3.4.1 patch?
 *  [fritos](https://wordpress.org/support/users/fritos/)
 * (@fritos)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16875962)
 * Yes, I still get the “Could not update snippet. Request failed with status code
   500″ error on v3.4.1 and v3.4.2
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16876584)
 * Are you able to share the code you’re trying to update and you receive this error?
   Do you have any security or packet filtering software installed, like Cloudflare?
 *  [vigwe](https://wordpress.org/support/users/vigwe/)
 * (@vigwe)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16909418)
 * [@bungeshea](https://wordpress.org/support/users/bungeshea/)
 * I’m getting the error as well. pls help.
 * Could not update snippet. Request failed with status code 500
 * i’m on the latest version.
 * The error occurs even when I click “save changes” on an already running snippet
   without actually editing it.
 * UPDATE:
 * I realized the error start after i added below code snippet. The error stops 
   when I remove it. Is there anything wrong with the snippet? 
   This snippet is 
   needed to add a product to Cart whenever a user visits the website.
 * /*
    - Automatically adding the product to the cart.
      */function aaptc_add_product_to_cart(){
      if ( ! is_admin() ) {$product_id = 209; // Product Id of the free product 
      which will get added to cart$found = false;//check if product already in cartif(
      sizeof( WC()->cart->get_cart() ) > 0 ) {foreach ( WC()->cart->get_cart() as
      $cart_item_key => $values ) {$_product = $values[‘data’];if ( $_product->get_id()
      == $product_id )$found = true;}// if product not found, add itif ( ! $found)
      WC()->cart->add_to_cart( $product_id );} else {// if no products in cart, 
      add itWC()->cart->add_to_cart( $product_id );}}}add_action( ‘init’, ‘aaptc_add_product_to_cart’);
 *  -  This reply was modified 2 years, 9 months ago by [vigwe](https://wordpress.org/support/users/vigwe/).
    -  This reply was modified 2 years, 9 months ago by [vigwe](https://wordpress.org/support/users/vigwe/).
    -  This reply was modified 2 years, 9 months ago by [vigwe](https://wordpress.org/support/users/vigwe/).
 *  [ifcstudios](https://wordpress.org/support/users/ifcstudios/)
 * (@ifcstudios)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16910681)
 * I’m getting the same error but only when attempting to create a global snippet.
   Creating the same exact snippet on a child site does not cause an error, but 
   attempting to create the snippet from the Network Admin dashboard and checking
   the box “Allow this snippet to be activated on individual sites on the network”
   always results in the following error message: Could not create snippet. Request
   failed with status code 500
 *  [ifcstudios](https://wordpress.org/support/users/ifcstudios/)
 * (@ifcstudios)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16910684)
 * [@bungeshea](https://wordpress.org/support/users/bungeshea/)
 * I also see the following error under Inspect >> Console
   /wp-json/code-snippets/
   v1/snippets:1Failed to load resource: the server responded with a status of 500()
 *  [umutacar](https://wordpress.org/support/users/umutacar/)
 * (@umutacar)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16921798)
 * Experiencing the same error now after updates to the core.
 *  [vigwe](https://wordpress.org/support/users/vigwe/)
 * (@vigwe)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/#post-16921804)
 * A quick workaround i found is to temporarily disable and snippet where get_cart()
   is used. This would allow me to save my new snippet and then afterward, re-enable
   the get_cart() snippet.
 * The get_cart() snippet is causing the issue. I hope it’s resolved soon.
 *  [lifeinnerlasting](https://wordpress.org/support/users/lifeinnerlasting/)
 * (@lifeinnerlasting)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/2/#post-16933559)
 * I’m getting the same 500 error when trying to save snippets on multisite… Problem
   occurs on all versions released beyond 3.3.0. Only solution so far has been to
   rollback to 3.3.0
   It only happens when I select “Allow this snippet to be activated
   on individual sites on the network”. I am able to save if I leave this box unchecked,
   but that’s not a solution for me.
    -  This reply was modified 2 years, 8 months ago by [lifeinnerlasting](https://wordpress.org/support/users/lifeinnerlasting/).
 *  [ROSA ESTER MARCHANT](https://wordpress.org/support/users/rositamg/)
 * (@rositamg)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/2/#post-16936486)
 * I have the same error
 *  Could not update snippet. Request failed with status code 500

Viewing 15 replies - 1 through 15 (of 41 total)

1 [2](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/2/?output_format=md)

The topic ‘Could not create snippet. Request failed with status code 500’ is closed
to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 45 replies
 * 27 participants
 * Last reply from: [ROSA ESTER MARCHANT](https://wordpress.org/support/users/rositamg/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/could-not-create-snippet-request-failed-with-status-code-500/page/3/#post-17773282)
 * Status: resolved