Making a Guzzle 6 API call using a POST method

Can anyone help me figure out how to send multiple data with a POST request? Here's what works:

$data = array(
'post_params'=>[
  'Name'=>'Foo',
  'LastName'=>'Bar'
]
);

But when I try this, it doesn't work. Any suggestions?

$data = array(
'post_params'=>[
  'Name'=>'Foo',
  'LastName'=>'Bar'
],
'post_params'=>[
  'Name'=>'Foo',
  'LastName'=>'Bar'
]
);

How can I successfully send multiple post data at once?

Answer №1

The approach you were taking won't work because requests don't support nested arrays of data. Instead, you can add multiple attributes but not in the form of nested arrays.

To achieve your goal, follow this method:

$data = array(
  'post_params'=>[
    'Name1'=>'Foo',
    'LastName1'=>'Bar',
    'Name2'=>'Foo',
    'LastName2'=>'Bar'
  ]
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve data from the MySQL database that has not been previously accessed

Is there a way to retrieve rows that have not been previously loaded using ajax without relying on an id? This is because the sorting of rows is not done based on id. ...

PHP Function - rounding numbers to two decimal places

Do you have a moment for a question? Here is the function in question: function clean_num($num){ return trim(trim($num, '0'), '.'); } The current functionality removes .00 from numbers like 85.00 and 55.00, and returns 85 and 55. ...

Switching ASP.net code to PHP and integrating it with mysql database

I've been on the hunt for a solution to convert my asp.net code to php and mysql. I gave a website a try that promised to handle the conversion, but it's falling short in terms of performance. While I'm no expert in either ASP or PHP, I ma ...

What is the best way to dynamically retrieve a URL and utilize it as a hyperlink using jQuery?

Is there a way to retrieve the current URL and use it as a link in jQuery? For example, if my browser is currently on page mysite.com/index.php?page=post&see=11, I would like to use this URL in my link and append /new/ after the domain name, like so: ...

"Failure encountered while trying to fetch JSON with an AJAX request

I am facing an issue with an ajax request. When I make the request with the property dataType: 'json', I get a parsererror in response. My PHP function returns the data using json_encode(), can someone assist me? On the other hand, when I make th ...

Send a JavaScript variable to Twig

I am trying to pass a JavaScript variable to a twig path but the current method I am using is not working as expected. <p id="result"></p> <script> var text = ""; var i; for (varJS = 0; varJS < 5; varJS++) { text += "<a href= ...

Automatically scraping Facebook API data with PHP

I'm completely new to php and I am looking for a way to automatically scrape metadata. I came across a solution, but I am unsure how to implement it in php. POST /?id={object-instance-id or object-url}&scrape=true Can anyone provide a sample php ...

Accessing files in Dropbox using the Dropbox API with PHP - Is it possible to find a way to access a specific file in

I am exploring the potential for integrating Dropbox with another API. Is it possible to retrieve a link to a file in Dropbox, allowing for opening and saving the file with updated content? Can files be created using the Dropbox API after receiving per ...

Exploring the Depths of Multidimensional JSON Arrays in PHP

I am currently working on developing a web-based file manager that allows me to organize, view, create, edit, and delete folders and files. In order to store information about these folders, files, and subfolders, I am in need of an appropriate data struct ...

Transferring data to a PHP script using the power of jQuery

Imagine a scenario where there are two links available. <li><a href="#" id="VALUE1" class="charName">Name 1</a></li> <li><a href="#" id="VALUE2" class="charName">Name 2</a></li> Now, when one of these link ...

Battle of Cookies and User Preferences: Who Will Prevail?

Recently, I encountered a challenge while developing an ecommerce site. After facing numerous issues, I believe I may have finally found a solution. (For more details on the problem and my question, click here) The expected scenario: Users checkout and p ...

Guidelines for utilizing the DISTINCT keyword in MySQL server to retrieve specific data

Consider this given value: $weight = 50 In my database, I possess the names of four individuals. Their respective weights are 40, 50, 35, and 54. What I desire is to obtain the names of those individuals whose weight falls within the range of $weight+10 a ...

Encountering Internal Server Error during Magento's mass reindexing process

Is there a way to reindex a Magento 1.7.02 version site with over 24,000 products and numerous categories? Whenever I attempt to reindex the product price index in Magento Admin Index Management, it triggers an internal Server Error 500. Upon inspecting t ...

Trouble with Facebox Dialog boxes: jQuery selectors altering input fields without any successfully triggering events

I am struggling to make a trigger like .change(), .click(), or .keydown() work on my facebox form in any browser. -- EDIT --- I discovered that the issue lies in the fact that facebox duplicates html to show it in the dialog box. Because of this, jquery ...

The Scottish flag isn't displaying on my website, but all other Emoji 5 symbols are working perfectly

When I build my website with PHP, I include header('Content-Type:text/html; charset=utf-8'); at the start. Interestingly, the Scottish flag emoji ...

Incorporating a WHERE clause into the COUNT query

Having some difficulty incorporating a where clause into a COUNT query. The following code successfully retrieves the total count of the table: $search = $_POST['search_text']; SELECT COUNT(*) FROM stories') ->fetchColumn(); However ...

AngularJS $scope variable can be initialized only once using an HTTP GET request

I'm facing an issue with fetching data from an API in a separate AngularJS application. There's a button that triggers the retrieval of data from the API. Upon clicking, it executes the $scope.getApiData function, which is connected to $scope.pr ...

Is it possible to nest clicks for ajax calls within the results of a previously appended call?

As I dive into learning about AJAX to enhance page loading speed by avoiding reliance on PHP for displaying results, I've encountered a challenge. I have three tiers of data distributed across three database tables: The first tier of data is fetche ...

MySQL Query Running Exceptionally Slow

Dealing with a database structure that is less than ideal. Table1 has 2 Ids (id1, id2) which link to rows in Table2. Want to retrieve specific columns from Table1 using id1 and id2 to get data from Table2. Is it necessary to join the same table twice to ...

Creating a fresh .pot template from a converted .po document: A step-by-step guide

After beginning with an incomplete gettext .pot file, the final .po translation file now contains numerous translation strings that were not present in the original .pot file. Is there a way to retroactively create a .pot file for other languages (strings ...