Guzzle post request | WordPress.org

[ad_1]

Hello,

I’m using Guzzle for my WP Rest application.

 "guzzlehttp/guzzle": "^7.5"

I can do the GET requests without any problems but when it comes to POST request I’m getting a

401 Unauthorized response: {“code”:”rest_cannot_create”,”message”:”Sorry, you are not allowed to create posts as this user.”,”data”:{“status”:401}}

However, when I’m doing the POST request using Postman I can make POST request without any problems

$response = $client->request('POST', '/wp-json/wp/v2/our-cruises/', [
          'json' => [
               'title' => 'This is a new test post from REST API',
               'content' => 'This is a content from REST API'
                    ]
]);
 
 
 
$body = $response->getBody();
$arr_body = json_decode($body);
print_r($arr_body);

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer