0

I'm trying to write to a slide element.

I keep getting the error responses of "Invalid JSON payload received. Unknown name" and " Cannot bind query parameter. Field"

My request is

 {
  "requests": [
    {
      "deleteText": {
        "objectId": "g33c4ea3b90_0_9",
        "textRange": {
          "type": "FROM_START_INDEX",
          "startIndex": 0
        }
      }
    },
    {
      "insertText": {
        "objectId":  "g33c4ea3b90_0_9",
        "text": "$8.23",
        "insertionIndex": 0
      }
    }
  ]
}

I am posting to: https://slides.googleapis.com/v1/presentations/PRESENTATION_ID:batchUpdate?access_token=ACCESS_TOKEN

I am manually cURLing the request in PHP:

 $params =  '
 {
  "requests": [
    {
      "deleteText": {
        "objectId": "'.$page_object_id.'",
        "textRange": {
          "type": "FROM_START_INDEX",
          "startIndex": 0
        }
      }
    },
    {
      "insertText": {
        "objectId":  "'.$page_object_id.'",
        "text": "$8.23",
        "insertionIndex": 0
      }
    }
  ]
}
';

$options = array(
    CURLOPT_RETURNTRANSFER => true, // return web page
    CURLOPT_HEADER => false, // don't return headers
    CURLOPT_FOLLOWLOCATION => true, // follow redirects
    CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
    CURLOPT_ENCODING => "", // handle compressed
    CURLOPT_AUTOREFERER => true, // set referrer on redirect
    CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
    CURLOPT_TIMEOUT => 120, // time-out on response
    CURLOPT_CUSTOMREQUEST => 'POST' ,   

    CURLOPT_SSL_VERIFYPEER =>  false,
    CURLOPT_SSL_VERIFYHOST =>  false ,
    CURLINFO_HEADER_OUT =>  true ,
    CURLOPT_VERBOSE => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS =>  $params 

);

 $ch = curl_init($url);
curl_setopt_array($ch, $options);

$content = curl_exec($ch);

curl_close($ch);

  $obj = json_decode($content, true);
  print_r( $obj );

When I call it from the API Explorer it works perfectly, but not from my server.

Chris
  • 136
  • 2
  • 12

1 Answers1

1

So the problem was the use of double quotes instead of single quotes in the request parameter json string.

So the following works:

 {
  'requests': [
    {
      'deleteText': {
        'objectId': 'g33c4ea3b90_0_9',
        'textRange': {
          'type': 'FROM_START_INDEX',
          'startIndex': 0
        }
      }
    },
    {
      'insertText': {
        'objectId': 'g33c4ea3b90_0_9',
        'text': '$44.23',
        'insertionIndex': 0
      }
    }
  ]
}

I had been working on this for two days.

Chris
  • 136
  • 2
  • 12