diff --git a/htdocs/api/admin/index.php b/htdocs/api/admin/index.php
index b867b6668c8b3661b1a219a93ffed329a35c3162..8142b564c1e7f6357cd5bdd522e727c0de9cc53b 100644
--- a/htdocs/api/admin/index.php
+++ b/htdocs/api/admin/index.php
@@ -43,8 +43,16 @@ if ($action == 'setproductionmode')
 
 	if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', $conf->entity) > 0)
 	{
-		header("Location: ".$_SERVER["PHP_SELF"]);
-		exit;
+	    $result = dol_mkdir($conf->api->dir_temp);
+	    if ($result < 0)
+	    {
+	        setEventMessages($langs->trans("ErrorFaildToCreateDir", $conf->api->dir_temp), null, 'errors');
+	    }
+	    else
+	    {
+    		header("Location: ".$_SERVER["PHP_SELF"]);
+	   	    exit;
+	    }
 	}
 	else
 	{