-1

So i have a post CURL object and I keep getting an error when I pass a variable to it. When i hard code it in, the CURL post works just fine. What am I doing wrong? I know the variable is set, because when i echo it to the screen it displays the value.

$tVA = "false";    

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://xyzservice.com",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{
"folderName":"folder name 1028-1",
"templateIds":[54909],
"fields":
    {

        "VA":$tVA

    },

The above code throws the error:

Trying to get property 'embeddedSigningSessions' of non-object
Trying to get property 'embeddedSessionURL' of non-object in

but when i hard code the value in, it works just fine. No errors.

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://xyzservice.com",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{
"folderName":"folder name 1028-1",
"templateIds":[54909],
"fields":
    {

        "VA":"false"

    },

The above works fine. Why isn't my variable working? Should I be wrapping it in something? I cant figure out why it will not allow me to pass a variable into the object. Thank you for any help.

user982853
  • 2,470
  • 14
  • 55
  • 82
  • 1
    Does this answer your question? [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – DarkBee Oct 29 '19 at 14:20

1 Answers1

2

This is happening because the $tVa is not being parsed as you have passed the values to CURLOPT_POSTFIELDS in single quotes.

You could change like below

CURLOPT_POSTFIELDS => '{
"folderName":"folder name 1028-1",
"templateIds":[54909],
"fields":
    {

        "VA":'.$tVA.'

    },
ascsoftw
  • 3,466
  • 2
  • 15
  • 23