1

I am trying to send a post request in laravel. Below is my code:

$response = Http::withToken($local_signature)
    ->post('myUrl', [
        "amount" => $amount,
        "narration" => $narration,
        "currency" => $currency,
        "beneficiary_name" => $beneficiary_name,
        "reference" => $reference,
        "debit_currency" => $debit_currency,
        "callback_url" => $callback_url,

        "meta" => array(

            "account_number" => $account_number,
            "routing_number" => $routing_number,
            "swift_code" => $swift_code,
            "bank_name" => $bank_name,
            "beneficiary_name" => $beneficiary_name,
            "beneficiary_address" => $beneficiary_address,
            "beneficiary_country" => $beneficiary_country,

        )
    ]);

For some reason meta is not seen by the server as I keep getting error "meta is required and it must be a non-empty array". How do I send this post request with meta as an array?

I need the request to look like this:

{
  "amount": 500,
  "narration": "Sample USD Transfer",
  "currency": "USD",
  "beneficiary_name": "Mark Cuban",
  "meta": [
    {
     "account_number": "09182972BH",
     "routing_number": "0000000002993",
     "swift_code": "ABJG190",
     "bank_name": "BANK OF AMERICA, N.A., SAN FRANCISCO, CA",
     "beneficiary_name": "Mark Cuban",
     "beneficiary_address": "San Francisco, 4 Newton",
     "beneficiary_country": "US"
    }
  ]
}

Any help?

1 Answer 1

3

To have the same structure as that json, meta should be an array of arrays.

$response = Http::withToken($local_signature)
    ->post('myUrl', [
        'amount' => $amount,
        'narration' => $narration,
        'currency' => $currency,
        'beneficiary_name' => $beneficiary_name,
        'reference' => $reference,
        'debit_currency' => $debit_currency,
        'callback_url' => $callback_url,
        'meta' => [
            [
                'account_number' => $account_number,
                'routing_number' => $routing_number,
                'swift_code' => $swift_code,
                'bank_name' => $bank_name,
                'beneficiary_name' => $beneficiary_name,
                'beneficiary_address' => $beneficiary_address,
                'beneficiary_country' => $beneficiary_country,
            ],
        ],
    ]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.