0

Here is what my API gives as an example:

curl 'https://api.webflow.com/collections/580e63fc8c9a982ac9b8b745/items' \
-H "Authorization: Bearer d59f681797fbb3758b2a0ce8e5f31a199e2733110cb468bb2bb0d77f23417b32" \
-H 'accept-version: 1.0.0' \
-H "Content-Type: application/json" \
--data-binary $'{
  "fields": {
    "name": "Exciting blog post title",
    "slug": "exciting-post",
    "_archived": false,
    "_draft": false,
    "color": "#a98080",
    "author": "580e640c8c9a982ac9b8b778",
    "post-body": "<p>Blog post contents...</p>",
    "post-summary": "Summary of exciting blog post",
    "main-image": "580e63fe8c9a982ac9b8b749"
  }
}'

I have my web form post the form data through GET/POST. But how do I convert that form data to what is show in --data-binary?

Here is how I'm doing it in PHP:

$ch = curl_init();
$request_url = 'https://api.webflow.com/collections/' . $collection_id . '/items';

$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer ' . $access_token;
$header[] = 'accept-version: 1.0.0';

curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,     json_encode($_REQUEST) );  

$rest = curl_exec($ch);

curl_close($ch);

My json encode looks like:

{"fields":{"region":"Saskatchewan","first-name":"Steven","last-name":"Gauerke","phone-number":"7705333580","email-address":"steven@chalamministries.com","first-name-spouse":"Daniel","last-name-spouse":"Canup","phone-number-spouse":"","email-address-spouse":"daniel@finidev.com","home-address":"Lamar Giles Rd","city":"Winder","province":"Georgia","active":"false"}}

I see everyone else talk about the @ but in this example there is a $.

swg1cor14
  • 1,682
  • 6
  • 25
  • 46
  • 1
    Possible duplicate of [PHP cURL: how to set body to binary data?](http://stackoverflow.com/questions/31970541/php-curl-how-to-set-body-to-binary-data) – Vasil Rashkov Jan 07 '17 at 22:41
  • No because that is a string. What am I supposed to do to make it look like what's above? – swg1cor14 Jan 08 '17 at 00:00

0 Answers0