{"id":1570,"date":"2018-01-11T00:00:00","date_gmt":"2018-01-10T23:00:00","guid":{"rendered":"https:\/\/old.weichie.com\/blog\/curl-api-calls-with-php\/"},"modified":"2023-03-27T09:53:20","modified_gmt":"2023-03-27T08:53:20","slug":"curl-api-calls-with-php","status":"publish","type":"post","link":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/","title":{"rendered":"cURL API calls with PHP, REST and JSON data (GET POST PUT DELETE)"},"content":{"rendered":"\n<p>I was recently working on a project where I needed to integrate an external API using HTTP cURL requests. It was my first time doing this and I had a lot of problems figuring this out. I wrote this post so I can remember my cURL API calls for next time, and maybe it can help you as well.&nbsp;<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The API calls and functions I&#8217;m using in this post are all working examples tested up to PHP v8+, v7+ and v5.6.<\/p>\n\n\n\n<div class=\"center\"><figure><img decoding=\"async\" src=\"https:\/\/old.weichie.com\/wp-content\/uploads\/2019\/07\/curl_api_calls.jpg\" alt=\"REST API calls with cURL, PHP and json\"><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-basics\">PHP cURL Basics<\/h2>\n\n\n\n<p>cURL stands for &#8216;Client URL Library&#8217; and it allows you to connect and communicate with different types of servers with many different types of protocols (HTTP, https, FTP, proxy, cookies, &#8230;). More info about how cURL actually works can be found in <a rel=\"noreferrer noopener\" href=\"https:\/\/www.php.net\/manual\/en\/intro.curl.php\" target=\"_blank\">the official PHP documentation<\/a>. This article will provide more in-depth examples for integrating your applications.<\/p>\n\n\n\n<p>I&#8217;ve received a lot of responses on &#8216;how does cURL actually work&#8217; and I get the feeling that people don&#8217;t know what&#8217;s going on in a cURL call. Before we start with the article and our cURL setup, I&#8217;ve added a simple example of a plain cURL request. The request will return the API response as a string.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code class=\"language-php\">\/\/ create &amp; initialize a curl session\n$curl&nbsp;=&nbsp;curl_init();\n\n\/\/ set our url with curl_setopt()\ncurl_setopt($curl,&nbsp;CURLOPT_URL,&nbsp;\"api.example.com\");\n\n\/\/ return the transfer as a string, also with setopt()\ncurl_setopt($curl,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1);\n\n\/\/ curl_exec() executes the started curl session\n\/\/ $output contains the output string\n$output&nbsp;=&nbsp;curl_exec($curl);\n\n\/\/ close curl resource to free up system resources\n\/\/ (deletes the variable made by curl_init)\ncurl_close($curl);<\/code><\/pre>\n\n\n\n<p>Note that we stored our curl_exec() in a variable $output. This $output variable is still available in our program even after we closed it with curl_close(). So after we did our call and closed the connection, we can still access the result using our $output variable.<\/p>\n\n\n\n<p>Now that we understand the basics, let&#8217;s try to put this into a function we can reuse within our application.<\/p>\n\n\n\n<p>If you&#8217;re looking for a simple cURL GET function to retrieve your API data with PHP, please check if my <a href=\"https:\/\/old.weichie.com\/blog\/simple-curl-api-connection-to-get-data-from-php-rest-api\/\">basic cURL API connection with PHP<\/a> is a better fit for your needs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-setup\">PHP cURL setup<\/h2>\n\n\n\n<p>Implementing an external API into your project is probably going to take more than just one API call and from different pages in your project. This is why I&#8217;ve created a &#8216;simple&#8217; PHP script that allows us to call this function, with a set of parameters, and a cURL request will be done.<\/p>\n\n\n\n<p>Make sure to put this code into a file or place that can be accessed by your entire app or website. <em>(I&#8217;ve updated this function so we&#8217;ll be able to define the headers when we&#8217;re making the call. I&#8217;ve added a section for custom headers at the bottom!)<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code class=\"language-php\">function callAPI($method, $url, $data){\n   $curl = curl_init();\n   switch ($method){\n      case \"POST\":\n         curl_setopt($curl, CURLOPT_POST, 1);\n         if ($data)\n            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);\n         break;\n      case \"PUT\":\n         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, \"PUT\");\n         if ($data)\n            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);\t\t\t \t\t\t\t\t\n         break;\n      default:\n         if ($data)\n            $url = sprintf(\"%s?%s\", $url, http_build_query($data));\n   }\n   \/\/ OPTIONS:\n   curl_setopt($curl, CURLOPT_URL, $url);\n   curl_setopt($curl, CURLOPT_HTTPHEADER, array(\n      'APIKEY: 111111111111111111111',\n      'Content-Type: application\/json',\n   ));\n   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);\n   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);\n   \/\/ EXECUTE:\n   $result = curl_exec($curl);\n   if(!$result){die(\"Connection Failure\");}\n   curl_close($curl);\n   return $result;\n}<\/code><\/pre>\n\n\n\n<p>This is a basic setup for doing a cURL call and I&#8217;m using a <code>switch<\/code> statement to check if the API call will be a POST, PUT, or something else (get or delete). I&#8217;ll go deeper into the switch case while we&#8217;re doing the specific requests.<\/p>\n\n\n\n<p>I&#8217;m using <code>if-statements<\/code> inside the <code>switch-case<\/code> to see if we want to provide JSON data into our call or not. For the POST and PUT request the if-statement is not really necessary because we&#8217;re only using POST or PUT with data, but it&#8217;s an extra security to make sure our call function won&#8217;t break.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-get-request\">PHP cURL GET request<\/h2>\n\n\n\n<p>The most simple API call is the GET call, so let&#8217;s start with that! Our callAPI function expects 3 parameters: $method, $url and $data. We need to give those parameters to all our API calls, so for a cURL GET, we can just set $data on false because we are not passing any data with a GET call.<\/p>\n\n\n\n<pre><code class=\"language-php\">$get_data = callAPI('GET', 'https:\/\/api.example.com\/get_url\/'.$user['User']['customer_id'], false);\n$response = json_decode($get_data, true);\n$errors = $response['response']['errors'];\n$data = $response['response']['data'][0];<\/code><\/pre>\n\n\n\n<p>$get_data already returns all the data we want from the API in a json string. I&#8217;m using $response to convert the json string back to a usable PHP array. You can skip those steps if you want, this is my personal preference. I&#8217;m also using the extra $errors and $data arrays to store the actual data and errors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-post-request\">PHP cURL POST request<\/h2>\n\n\n\n<p>Obviously, a POST request does require data. Make sure your json-data is correct, otherwise the request will keep returning errors. Although&#8230; If we receive errors from the API, that means our calls are working \ud83d\ude09<\/p>\n\n\n\n<p>In my example I&#8217;m using the CakePHP syntax for setting up my json array, so don&#8217;t mind that.<\/p>\n\n\n\n<pre><code class=\"language-php\">$data_array =  array(\n      \"customer\"        =&gt; $user['User']['customer_id'],\n      \"payment\"         =&gt; array(\n            \"number\"         =&gt; $this-&gt;request-&gt;data['account'],\n            \"routing\"        =&gt; $this-&gt;request-&gt;data['routing'],\n            \"method\"         =&gt; $this-&gt;request-&gt;data['method']\n      ),\n);\n$make_call = callAPI('POST', 'https:\/\/api.example.com\/post_url\/', json_encode($data_array));\n$response = json_decode($make_call, true);\n$errors   = $response['response']['errors'];\n$data     = $response['response']['data'][0];<\/code><\/pre>\n\n\n\n<p>Because we&#8217;re doing an API call with json data, I&#8217;m converting my PHP array to a json string with <code>json_encode($data_array);<\/code>. The response will come in as a json string again, so I&#8217;m using <code>json_decode($make_call, true);<\/code> to convert the json string back to a usable PHP array. Same as we did in our GET call, so you can skip these steps again if you don&#8217;t need them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-put-request\">PHP cURL PUT request<\/h2>\n\n\n\n<p>The PUT request is almost the same as the POST request. I had a hard time figuring out how to pass data into a PUT call. If we take a look at our callAPI() function, you see that I changed some things up between the PUT and the POST request. We can still use the same parameters in our callAPI() function as always.<\/p>\n\n\n\n<pre><code class=\"language-php\">$data_array =  array(\n   \"amount\" =&gt; (string)($lease['amount'] \/ $tenant_count)\n);\n$update_plan = callAPI('PUT', 'https:\/\/api.example.com\/put_url\/'.$lease['plan_id'], json_encode($data_array));\n$response = json_decode($update_plan, true);\n$errors = $response['response']['errors'];\n$data = $response['response']['data'][0];<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-delete-request\">PHP cURL DELETE request<\/h2>\n\n\n\n<p>The delete request is very simple again. We can just hit the API url with the $id we want to remove and poof&#8230; it&#8217;s gone forever.<\/p>\n\n\n\n<pre><code class=\"language-php\">callAPI('DELETE', 'https:\/\/api.example.com\/delete_url\/' . $id, false);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-with-flexible-headers\">What with flexible headers?<\/h2>\n\n\n\n<p>In the beginning we defined our callAPI function with preset headers. But what if we, for some reason, need to change the headers a bit for another call? We don&#8217;t want to write a whole new callAPI function just to edit some headers. Therefore, here&#8217;s an option on how to make the preset headers flexible:<\/p>\n\n\n\n<pre><code class=\"language-php\">function callAPI($method, $url, $data, $headers = false){\n   $curl = curl_init();\n   switch ($method){\n      ...\n   }\n   \/\/ OPTIONS:\n   curl_setopt($curl, CURLOPT_URL, $url);\n   if(!$headers){\n       curl_setopt($curl, CURLOPT_HTTPHEADER, array(\n          'APIKEY: 111111111111111111111',\n          'Content-Type: application\/json',\n       ));\n   }else{\n       curl_setopt($curl, CURLOPT_HTTPHEADER, array(\n          'APIKEY: 111111111111111111111',\n          'Content-Type: application\/json',\n          $headers\n       ));\n   }\n   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);\n   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);\n   \/\/ EXECUTE:\n   ...\n}<\/code><\/pre>\n\n\n\n<p>There are 2 differences here from our first function. 1: We&#8217;ve added an extra parameter in our function to define if we want to use a custom header or not. I put it to <code>$headers = false<\/code> to give it a default value. Now we&#8217;re not required to enter our headers with every call.<\/p>\n\n\n\n<p>The second change is the if-statement when we&#8217;re setting the API headers. If we didn&#8217;t give in any headers when we make the call, it&#8217;s going to use our default headers instead of crashing. Now we&#8217;re ready to add custom headers with our call!<\/p>\n\n\n\n<p>In this example, I&#8217;m using search parameters to search for specific data before I&#8217;ll pull in all the data with the API. To make the search, I obviously need to be able to add my search query into my callAPI headers. Here&#8217;s my example:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-custom-headers-before-our-call\">Creating custom headers before our call<\/h2>\n\n\n\n<pre><code class=\"language-php\">$one_month_ago = date(\"Y-m-d\", strtotime(date(\"Y-m-d\", strtotime(date(\"Y-m-d\"))) . \"-1 month\"));\n$rent_header = 'Search: and[][created][greater]=' . $one_month_ago . '%and[][created][less]=' . date('Y-m-d') . '%';\n\/\/the actual call with custom search header\n$make_call = callAPI('GET', 'https:\/\/api.example.com\/get_url\/', false, $rent_header);<\/code><\/pre>\n\n\n\n<p>This is just an example on how to add headers. My example is to get all rows where a rent was paid in the last 30 days. $one_month_ago is just a helper variable. The $rent_header is the actual header I want to add to my default headers. This needs to be a string!!<\/p>\n\n\n\n<p>When you&#8217;ve set the header, you can just do a regular api call and add your new header at the end.<\/p>\n\n\n\n<p>I didn&#8217;t need to use any other API call methods like patch or purge or anything like that. These you need to figure out yourself. If there&#8217;s some magic going on in this post I hope my examples can give you a better understanding.<\/p>\n\n\n\n<p>I recently wrote a part 2 for this post, that will talk about generating an AUTH-key (utoken) before we make our calls. <a href=\"https:\/\/old.weichie.com\/blog\/curl-api-calls-authentication\/\">Make sure to check it out here as well!<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>No clue on how to make PHP API calls with cURL? I recently made some integrations and had a lot of problems figuring this out. This article might help you!<\/p>\n","protected":false},"author":1,"featured_media":967,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[110,111],"tags":[113,187,122,188,180,123,98,181,189,124,169,186],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.4 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>cURL API calls with PHP and JSON data (GET - POST - PUT - DELETE)<\/title>\n<meta name=\"description\" content=\"Need to make PHP API calls with cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"cURL API calls with PHP and json data (GET, POST, PUT, DELETE)\" \/>\n<meta property=\"og:description\" content=\"Need to make PHP API calls with HTTP cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Weichie\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/weichiecom\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-10T23:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-27T08:53:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/old.weichie.com\/wp-content\/uploads\/2019\/07\/curl_api_calls.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1194\" \/>\n\t<meta property=\"og:image:height\" content=\"954\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Bob Weichler\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"cURL API calls with PHP and json data (GET, POST, PUT, DELETE)\" \/>\n<meta name=\"twitter:description\" content=\"Need to make PHP API calls with HTTP cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.weichieprojects.com\/wp-content\/uploads\/2018\/01\/curl_api_calls.jpg\" \/>\n<meta name=\"twitter:creator\" content=\"@Weichiie\" \/>\n<meta name=\"twitter:site\" content=\"@Weichiie\" \/>\n<meta name=\"twitter:label1\" content=\"Geschreven door\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Weichler\" \/>\n\t<meta name=\"twitter:label2\" content=\"Geschatte leestijd\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/\"},\"author\":{\"name\":\"Bob Weichler\",\"@id\":\"https:\/\/old.weichie.com\/nl\/#\/schema\/person\/6ad8396db109092b3b23f7ea9e6b8f2a\"},\"headline\":\"cURL API calls with PHP, REST and JSON data (GET POST PUT DELETE)\",\"datePublished\":\"2018-01-10T23:00:00+00:00\",\"dateModified\":\"2023-03-27T08:53:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/\"},\"wordCount\":1245,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/old.weichie.com\/nl\/#organization\"},\"keywords\":[\"api\",\"calls\",\"curl\",\"delete\",\"get\",\"json\",\"php\",\"post\",\"put\",\"rest_api\",\"tutorial\",\"web dev for a five year old\"],\"articleSection\":[\"php\",\"Zelfstudie\"],\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/\",\"url\":\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/\",\"name\":\"cURL API calls with PHP and JSON data (GET - POST - PUT - DELETE)\",\"isPartOf\":{\"@id\":\"https:\/\/old.weichie.com\/nl\/#website\"},\"datePublished\":\"2018-01-10T23:00:00+00:00\",\"dateModified\":\"2023-03-27T08:53:20+00:00\",\"description\":\"Need to make PHP API calls with cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.\",\"breadcrumb\":{\"@id\":\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/old.weichie.com\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"cURL API calls with PHP, REST and JSON data (GET POST PUT DELETE)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/old.weichie.com\/nl\/#website\",\"url\":\"https:\/\/old.weichie.com\/nl\/\",\"name\":\"Weichie\",\"description\":\"Web development for forward thinking brands\",\"publisher\":{\"@id\":\"https:\/\/old.weichie.com\/nl\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/old.weichie.com\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"nl-NL\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/old.weichie.com\/nl\/#organization\",\"name\":\"Weichie\",\"url\":\"https:\/\/old.weichie.com\/nl\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\/\/old.weichie.com\/nl\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/old.weichie.com\/wp-content\/uploads\/2019\/04\/wp_logo_black.png\",\"contentUrl\":\"https:\/\/old.weichie.com\/wp-content\/uploads\/2019\/04\/wp_logo_black.png\",\"width\":500,\"height\":228,\"caption\":\"Weichie\"},\"image\":{\"@id\":\"https:\/\/old.weichie.com\/nl\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/weichiecom\",\"https:\/\/twitter.com\/Weichiie\",\"https:\/\/www.instagram.com\/weichiie\/\",\"https:\/\/www.linkedin.com\/company\/weichieprojects\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/old.weichie.com\/nl\/#\/schema\/person\/6ad8396db109092b3b23f7ea9e6b8f2a\",\"name\":\"Bob Weichler\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"cURL API calls with PHP and JSON data (GET - POST - PUT - DELETE)","description":"Need to make PHP API calls with cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"nl_NL","og_type":"article","og_title":"cURL API calls with PHP and json data (GET, POST, PUT, DELETE)","og_description":"Need to make PHP API calls with HTTP cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.","og_url":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/","og_site_name":"Weichie","article_publisher":"https:\/\/www.facebook.com\/weichiecom","article_published_time":"2018-01-10T23:00:00+00:00","article_modified_time":"2023-03-27T08:53:20+00:00","og_image":[{"width":1194,"height":954,"url":"https:\/\/old.weichie.com\/wp-content\/uploads\/2019\/07\/curl_api_calls.jpg","type":"image\/jpeg"}],"author":"Bob Weichler","twitter_card":"summary_large_image","twitter_title":"cURL API calls with PHP and json data (GET, POST, PUT, DELETE)","twitter_description":"Need to make PHP API calls with HTTP cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.","twitter_image":"https:\/\/www.weichieprojects.com\/wp-content\/uploads\/2018\/01\/curl_api_calls.jpg","twitter_creator":"@Weichiie","twitter_site":"@Weichiie","twitter_misc":{"Geschreven door":"Bob Weichler","Geschatte leestijd":"8 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#article","isPartOf":{"@id":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/"},"author":{"name":"Bob Weichler","@id":"https:\/\/old.weichie.com\/nl\/#\/schema\/person\/6ad8396db109092b3b23f7ea9e6b8f2a"},"headline":"cURL API calls with PHP, REST and JSON data (GET POST PUT DELETE)","datePublished":"2018-01-10T23:00:00+00:00","dateModified":"2023-03-27T08:53:20+00:00","mainEntityOfPage":{"@id":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/"},"wordCount":1245,"commentCount":0,"publisher":{"@id":"https:\/\/old.weichie.com\/nl\/#organization"},"keywords":["api","calls","curl","delete","get","json","php","post","put","rest_api","tutorial","web dev for a five year old"],"articleSection":["php","Zelfstudie"],"inLanguage":"nl-NL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/","url":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/","name":"cURL API calls with PHP and JSON data (GET - POST - PUT - DELETE)","isPartOf":{"@id":"https:\/\/old.weichie.com\/nl\/#website"},"datePublished":"2018-01-10T23:00:00+00:00","dateModified":"2023-03-27T08:53:20+00:00","description":"Need to make PHP API calls with cURL? This article might help you with making correct curl GET calls, as well as curl POST, PUT, and DELETE.","breadcrumb":{"@id":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/old.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/old.weichie.com\/nl\/"},{"@type":"ListItem","position":2,"name":"cURL API calls with PHP, REST and JSON data (GET POST PUT DELETE)"}]},{"@type":"WebSite","@id":"https:\/\/old.weichie.com\/nl\/#website","url":"https:\/\/old.weichie.com\/nl\/","name":"Weichie","description":"Web development for forward thinking brands","publisher":{"@id":"https:\/\/old.weichie.com\/nl\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/old.weichie.com\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"nl-NL"},{"@type":"Organization","@id":"https:\/\/old.weichie.com\/nl\/#organization","name":"Weichie","url":"https:\/\/old.weichie.com\/nl\/","logo":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/old.weichie.com\/nl\/#\/schema\/logo\/image\/","url":"https:\/\/old.weichie.com\/wp-content\/uploads\/2019\/04\/wp_logo_black.png","contentUrl":"https:\/\/old.weichie.com\/wp-content\/uploads\/2019\/04\/wp_logo_black.png","width":500,"height":228,"caption":"Weichie"},"image":{"@id":"https:\/\/old.weichie.com\/nl\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/weichiecom","https:\/\/twitter.com\/Weichiie","https:\/\/www.instagram.com\/weichiie\/","https:\/\/www.linkedin.com\/company\/weichieprojects\/"]},{"@type":"Person","@id":"https:\/\/old.weichie.com\/nl\/#\/schema\/person\/6ad8396db109092b3b23f7ea9e6b8f2a","name":"Bob Weichler"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/posts\/1570"}],"collection":[{"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/comments?post=1570"}],"version-history":[{"count":5,"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/posts\/1570\/revisions"}],"predecessor-version":[{"id":4902,"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/posts\/1570\/revisions\/4902"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/media\/967"}],"wp:attachment":[{"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/media?parent=1570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/categories?post=1570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/old.weichie.com\/nl\/wp-json\/wp\/v2\/tags?post=1570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}