{"id":1149,"date":"2018-01-10T23:00:00","date_gmt":"2018-01-10T23:00:00","guid":{"rendered":"https:\/\/old-2023.weichie.com\/curl-api-calls-with-php\/"},"modified":"2024-02-08T15:29:21","modified_gmt":"2024-02-08T15:29:21","slug":"curl-api-calls-with-php","status":"publish","type":"post","link":"https:\/\/old-2023.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":"<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<!--more-->\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">The API calls and functions I&#8217;m using in this post are all working examples on PHP -v 5.6.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<div class=\"center\"><figure><img decoding=\"async\" src=\"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/02\/curl_api_calls.jpg\" alt=\"REST API calls with cURL, PHP and json\"><\/figure><\/div>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-basics\">PHP cURL Basics<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">Now that we understand the basics, let&#8217;s try to put this into a function we can reuse within our application.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-setup\">PHP cURL setup<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-get-request\">PHP cURL GET request<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">$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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-post-request\">PHP cURL POST request<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">In my example I&#8217;m using the CakePHP syntax for setting up my json array, so don&#8217;t mind that.<\/p>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-put-request\">PHP cURL PUT request<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-php-curl-delete-request\">PHP cURL DELETE request<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<pre><code class=\"language-php\">callAPI('DELETE', 'https:\/\/api.example.com\/delete_url\/' . $id, false);<\/code><\/pre>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-what-with-flexible-headers\">What with flexible headers?<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<h2 class=\"wp-block-heading\" id=\"h-creating-custom-headers-before-our-call\">Creating custom headers before our call<\/h2>\n<\/div>\n\n<div class=\"default__block container-fluid lg\">\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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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<\/div>\n\n<div class=\"default__block container-fluid lg\">\n<p class=\"wp-block-paragraph\">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-2023.weichie.com\/nl\/blog\/php-curl-api-calls-authentication\/\">Make sure to check it out here as well!<\/a><\/p>\n<\/div>","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":694,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[211],"tags":[137,276,277,278,274,275,186,198,279,280,261,199],"class_list":["post-1149","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development-nl","tag-api-nl","tag-calls-nl","tag-curl-nl","tag-delete-nl","tag-get-nl","tag-json-nl","tag-php-nl","tag-post-nl","tag-put-nl","tag-rest_api-nl","tag-tutorial-nl","tag-web-dev-for-a-five-year-old-nl"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.9 (Yoast SEO v27.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\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-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Weichie.com\" \/>\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=\"2024-02-08T15:29:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/01\/accounting-website.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1851\" \/>\n\t<meta property=\"og:image:height\" content=\"920\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"weichie\" \/>\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:label1\" content=\"Geschreven door\" \/>\n\t<meta name=\"twitter:data1\" content=\"weichie\" \/>\n\t<meta name=\"twitter:label2\" content=\"Geschatte leestijd\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/\"},\"author\":{\"name\":\"weichie\",\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/#\\\/schema\\\/person\\\/36b4fff07382bc08a5c566728d9c579f\"},\"headline\":\"cURL API calls with PHP, REST and JSON data (GET POST PUT DELETE)\",\"datePublished\":\"2018-01-10T23:00:00+00:00\",\"dateModified\":\"2024-02-08T15:29:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/\"},\"wordCount\":1206,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/old-2023.weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/curl_api_calls.jpg\",\"keywords\":[\"api\",\"calls\",\"curl\",\"delete\",\"get\",\"json\",\"php\",\"post\",\"put\",\"rest_api\",\"tutorial\",\"web dev for a five year old\"],\"articleSection\":[\"Development\"],\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/\",\"url\":\"https:\\\/\\\/old-2023.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-2023.weichie.com\\\/nl\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/old-2023.weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/curl_api_calls.jpg\",\"datePublished\":\"2018-01-10T23:00:00+00:00\",\"dateModified\":\"2024-02-08T15:29:21+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-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/old-2023.weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/curl_api_calls.jpg\",\"contentUrl\":\"https:\\\/\\\/old-2023.weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/curl_api_calls.jpg\",\"width\":1194,\"height\":954},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/blog\\\/curl-api-calls-with-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/old-2023.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-2023.weichie.com\\\/nl\\\/#website\",\"url\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/\",\"name\":\"Weichie.com\",\"description\":\"Digital Agency in Brussels &amp; New York\",\"publisher\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/#organization\"},\"alternateName\":\"Weichie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl-NL\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/#organization\",\"name\":\"Weichie.com\",\"alternateName\":\"Weichie\",\"url\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/old-2023.weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Weichie_full.png\",\"contentUrl\":\"https:\\\/\\\/old-2023.weichie.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Weichie_full.png\",\"width\":1181,\"height\":177,\"caption\":\"Weichie.com\"},\"image\":{\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/weichiecom\\\/\",\"https:\\\/\\\/www.instagram.com\\\/weichiecom\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/weichie\\\/\"],\"description\":\"A digital agency based in Brussels and New York. We create high-quality digital experiences for brands and help them promote their business through the online world! Specialised in websites, e-commerce, SEO and applications.\",\"email\":\"hello@weichie.com\",\"telephone\":\"+32 469 129 449\",\"legalName\":\"Weichie.com\",\"vatID\":\"0782.257.983\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1\",\"maxValue\":\"10\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/old-2023.weichie.com\\\/nl\\\/#\\\/schema\\\/person\\\/36b4fff07382bc08a5c566728d9c579f\",\"name\":\"weichie\",\"sameAs\":[\"https:\\\/\\\/old-2023.weichie.com\"]}]}<\/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-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/","og_site_name":"Weichie.com","article_publisher":"https:\/\/www.facebook.com\/weichiecom\/","article_published_time":"2018-01-10T23:00:00+00:00","article_modified_time":"2024-02-08T15:29:21+00:00","og_image":[{"width":1851,"height":920,"url":"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/01\/accounting-website.jpg","type":"image\/jpeg"}],"author":"weichie","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_misc":{"Geschreven door":"weichie","Geschatte leestijd":"6 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#article","isPartOf":{"@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/"},"author":{"name":"weichie","@id":"https:\/\/old-2023.weichie.com\/nl\/#\/schema\/person\/36b4fff07382bc08a5c566728d9c579f"},"headline":"cURL API calls with PHP, REST and JSON data (GET POST PUT DELETE)","datePublished":"2018-01-10T23:00:00+00:00","dateModified":"2024-02-08T15:29:21+00:00","mainEntityOfPage":{"@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/"},"wordCount":1206,"commentCount":0,"publisher":{"@id":"https:\/\/old-2023.weichie.com\/nl\/#organization"},"image":{"@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#primaryimage"},"thumbnailUrl":"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/02\/curl_api_calls.jpg","keywords":["api","calls","curl","delete","get","json","php","post","put","rest_api","tutorial","web dev for a five year old"],"articleSection":["Development"],"inLanguage":"nl-NL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/","url":"https:\/\/old-2023.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-2023.weichie.com\/nl\/#website"},"primaryImageOfPage":{"@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#primaryimage"},"image":{"@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#primaryimage"},"thumbnailUrl":"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/02\/curl_api_calls.jpg","datePublished":"2018-01-10T23:00:00+00:00","dateModified":"2024-02-08T15:29:21+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-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/"]}]},{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#primaryimage","url":"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/02\/curl_api_calls.jpg","contentUrl":"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/02\/curl_api_calls.jpg","width":1194,"height":954},{"@type":"BreadcrumbList","@id":"https:\/\/old-2023.weichie.com\/nl\/blog\/curl-api-calls-with-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/old-2023.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-2023.weichie.com\/nl\/#website","url":"https:\/\/old-2023.weichie.com\/nl\/","name":"Weichie.com","description":"Digital Agency in Brussels &amp; New York","publisher":{"@id":"https:\/\/old-2023.weichie.com\/nl\/#organization"},"alternateName":"Weichie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/old-2023.weichie.com\/nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl-NL"},{"@type":"Organization","@id":"https:\/\/old-2023.weichie.com\/nl\/#organization","name":"Weichie.com","alternateName":"Weichie","url":"https:\/\/old-2023.weichie.com\/nl\/","logo":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/old-2023.weichie.com\/nl\/#\/schema\/logo\/image\/","url":"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/11\/Weichie_full.png","contentUrl":"https:\/\/old-2023.weichie.com\/wp-content\/uploads\/2023\/11\/Weichie_full.png","width":1181,"height":177,"caption":"Weichie.com"},"image":{"@id":"https:\/\/old-2023.weichie.com\/nl\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/weichiecom\/","https:\/\/www.instagram.com\/weichiecom\/","https:\/\/www.linkedin.com\/company\/weichie\/"],"description":"A digital agency based in Brussels and New York. We create high-quality digital experiences for brands and help them promote their business through the online world! Specialised in websites, e-commerce, SEO and applications.","email":"hello@weichie.com","telephone":"+32 469 129 449","legalName":"Weichie.com","vatID":"0782.257.983","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1","maxValue":"10"}},{"@type":"Person","@id":"https:\/\/old-2023.weichie.com\/nl\/#\/schema\/person\/36b4fff07382bc08a5c566728d9c579f","name":"weichie","sameAs":["https:\/\/old-2023.weichie.com"]}]}},"_links":{"self":[{"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/posts\/1149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/comments?post=1149"}],"version-history":[{"count":0,"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/posts\/1149\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/media\/694"}],"wp:attachment":[{"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/media?parent=1149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/categories?post=1149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/old-2023.weichie.com\/nl\/wp-json\/wp\/v2\/tags?post=1149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}