PIPELINES AND STAGES OF SALES

Adding and updating pipelines and stages of sales

The stages of sales are the sequence of steps that a potential customer (lead) passes through the sales pipeline before buying. In amoCRM, you can create multiple sales cranes in one account and set your own milestones to track the progress of the lead in each pipeline. In amoCRM, you can configure up to 10 pipelines in your account. Each pipeline can contain up to 100 stages (including successful and unsuccessful statuses). Configure pipelines and stages of sales can administrator account on the Settings -> Sales stages page.

Methods for working with the settings of the stages of sales of the account. These methods are only available to the account administrator. The method allows you to add pipelines and stages of sales one at a time or in batches, and also update data on existing pipelines and stages. When you change the pipeline, you must submit a complete list of steps, including those already existing.

Method URL

POST / private / api / v2 / json / pipelines / set

Parameters
Parameter Type Description
add array The list of added pipelines, if an error occurs, this key will be specified in the error description
update array Updating an existing hopper
All the parameters that are described in add also work in the update
add/name
require
string Pipeline name
add/sort int Pipeline ordinal number when displayed
add/is_main string Is the pipeline "main" (it is necessary to pass the value "on" if it is)
add/statuses array Stages of the pipeline, you must pass at least one step, except successfully / unsuccessfully completed.
As the key, you must pass the ID of the step, if it exists. For stages successfully / unsuccessfully completed (id 142/143 respectively) it is possible to transfer only the field name
add/statuses// array Inside it will be a description of each step
add/statuses//name string The name of the stage
add/statuses//sort int Sequence number of the stage when displayed (automatically recomputed after adding)
add/statuses//color string The color of the stage (you can learn more here)
update/id
require
int The unique identifier of the pipeline, which is indicated for the purpose of updating it
update/statuses//id
require
int The unique identifier of the step, which is specified for the purpose of updating it
Example response
  1. {
  2.   "request": {
  3.     "pipelines": {
  4.       "add": [
  5.         {
  6.           "name": "Test Pipeline",
  7.           "statuses": {
  8.             "0": {
  9.               "color": "#fffeb2",
  10.               "name": "Status #0",
  11.               "sort": 0
  12.             },
  13.             "1": {
  14.               "color": "#fffeb2",
  15.               "name": "Status #1",
  16.               "sort": 10
  17.             },
  18.             "2": {
  19.               "color": "#d6eaff",
  20.               "name": "Status #2",
  21.               "sort": 20
  22.             },
  23.             "3": {
  24.               "color": "#f3beff",
  25.               "name": "Status #3",
  26.               "sort": 30
  27.             },
  28.             "142": {
  29.               "name": "Success"
  30.             },
  31.             "143": {
  32.               "name": "Failed"
  33.             }
  34.           },
  35.           "is_main": "false"
  36.         }
  37.       ]
  38.     },
  39.     "update": {
  40.       "2521": {
  41.         "id": 2521,
  42.         "name": "Retest Pipeline",
  43.         "sort": 12,
  44.         "is_main": "on",
  45.         "statuses": {
  46.           "10223179": {
  47.             "id": 10223179,
  48.             "name": "Status #0",
  49.             "sort": 10,
  50.             "color": "#fffeb2"
  51.           },
  52.           "10223183": {
  53.             "id": 10223183,
  54.             "name": "Status #4",
  55.             "sort": 50,
  56.             "color": "#deff81"
  57.           },
  58.           "10223184": {
  59.             "id": 10223184,
  60.             "name": "Status #5",
  61.             "sort": 60,
  62.             "color": "#d6eaff"
  63.           },
  64.           "10223185": {
  65.             "id": 10223185,
  66.             "name": "Status #6",
  67.             "sort": 70,
  68.             "color": "#fffd7f"
  69.           }
  70.         }
  71.       }
  72.     }
  73.   }
  74. }
Response parameters
Parameter Description
add/pipelines//id The unique identifier of the pipeline
add/pipelines//value The unique identifier of the pipeline
add/pipelines//label Pipeline name
add/pipelines//name Pipeline name
add/pipelines//sort Ordinal number of the pipeline when displayed
add/pipelines//is_main Is the pipeline the "main"
add/pipelines//statuses//id The unique identifier of the step
add/pipelines//statuses//name The name of the stage
add/pipelines//statuses//pipeline_id The unique identifier of the pipeline
add/pipelines//statuses//sort Sequence number of the stage when displaying
add/pipelines//statuses//color The color of the stage (you can learn more here)
add/pipelines//statuses//editable Is it possible to change or delete this stage, the possible values ​​are "Y" or "N"
add/pipelines//leads The number of leads in this pipeline
update// Associative array where the key is the pipeline ID, and the value - whether the change was applied to the pipeline with this identifier
server_time Time stamp of the current server time with offset to the time zone of the account (transmitted in timestamp format)
Example response
  1. {
  2.   "response": {
  3.     "pipelines": {
  4.       "add": {
  5.         "pipelines":{
  6.           "2116":{
  7.             "id":2116,
  8.             "value":2116,
  9.             "label":"Pipeline",
  10.             "name":"Pipeline",
  11.             "sort":1,
  12.             "is_main":true,
  13.             "statuses":{
  14.               "142":{
  15.                 "id":142,
  16.                 "name":"Closed - won",
  17.                 "color":"#CCFF66",
  18.                 "sort":10000,
  19.                 "editable":"N",
  20.                 "pipeline_id":2116
  21.               },
  22.               "143":{
  23.                 "id":143,
  24.                 "name":"Closed - lost",
  25.                 "color":"#D5D8DB",
  26.                 "sort":11000,
  27.                 "editable":"N",
  28.                 "pipeline_id":2116
  29.               },
  30.               "10216993":{
  31.                 "id":10216993,
  32.                 "name":"Initial Contact",
  33.                 "pipeline_id":2116,
  34.                 "sort":10,
  35.                 "color":"#99ccff",
  36.                 "editable":"Y"
  37.               },
  38.               "10216994":{
  39.                 "id":10216994,
  40.                 "name":"Offer made",
  41.                 "pipeline_id":2116,
  42.                 "sort":20,
  43.                 "color":"#ffff99",
  44.                 "editable":"Y"
  45.               },
  46.               "10216995":{
  47.                 "id":10216995,
  48.                 "name":"Negotiation",
  49.                 "pipeline_id":2116,
  50.                 "sort":30,
  51.                 "color":"#ffcc66",
  52.                 "editable":"Y"
  53.               },
  54.               "10216996":{
  55.                 "id":10216996,
  56.                 "name":"Contract Negotiation",
  57.                 "pipeline_id":2116,
  58.                 "sort":40,
  59.                 "color":"#ffcccc",
  60.                 "editable":"Y"
  61.               }
  62.             },
  63.             "leads":14
  64.           }
  65.         }
  66.       },
  67.     "update": {
  68.       "2521": true
  69.     }
  70.     }
  71.   }
  72. }
Adding a pipeline

To add a pipeline, you need to describe an array containing information about the pipeline and put it into an array of the following form: $ pipelines ['request'] ['pipelines'] ['add'] Our API also supports the simultaneous addition of several pipelines. To do this, we put several arrays into the $ pipelines ['request'] ['pipelines'] ['add'] array, each of which describes the necessary data to create the appropriate pipeline.

Example integration
  1. $pipelines['request']['pipelines']['add'] = array(
  2.   array(
  3.     'name'     => 'Test Pipeline',
  4.     'statuses' => array(
  5.       array(
  6.         'color' => '#deff81',
  7.         'name'  => 'Status #0',
  8.         'sort'  => 0,
  9.       ),
  10.       array(
  11.         'color' => '#ffeab2',
  12.         'name'  => 'Status #1',
  13.         'sort'  => 10,
  14.       ),
  15.       array(
  16.         'color' => '#ffdc7f',
  17.         'name'  => 'Status #2',
  18.         'sort'  => 20,
  19.       ),
  20.       array(
  21.         'color' => '#deff81',
  22.         'name'  => 'Status #3',
  23.         'sort'  => 30,
  24.       ),
  25.       array(
  26.         'color' => '#ebffb1',
  27.         'name'  => 'Status #4',
  28.         'sort'  => 40,
  29.       ),
  30.       array(
  31.         'color' => '#fffeb2',
  32.         'name'  => 'Status #5',
  33.         'sort'  => 50,
  34.       ),
  35.       array(
  36.         'color' => '#ffc8c8',
  37.         'name'  => 'Status #6',
  38.         'sort'  => 60,
  39.       ),
  40.       array(
  41.         'color' => '#c1e0ff',
  42.         'name'  => 'Status #7',
  43.         'sort'  => 70,
  44.       ),
  45.       array(
  46.         'color' => '#f3beff',
  47.         'name'  => 'Status #8',
  48.         'sort'  => 80,
  49.       ),
  50.       array(
  51.         'color' => '#ccc8f9',
  52.         'name'  => 'Status #9',
  53.         'sort'  => 90,
  54.       ),
  55.     ),
  56.     'is_main'  => 'on',
  57.   ),
  58. );
  59. /* Now prepare the data needed to query the server */
  60. $subdomain='test'; #Our account is a subdomain
  61. #Generate a link for the request
  62. $link='https://'.$subdomain.'.amocrm.com/private/api/v2/json/pipelines/set';
  63. /* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about
  64. work with this
  65. library you can read in the manual. */
  66. $curl=curl_init(); #Save the cURL session descriptor
  67. #Set the necessary parameters for the cURL session
  68. curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  69. curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
  70. curl_setopt($curl,CURLOPT_URL,$link);
  71. curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
  72. curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($pipelines));
  73. curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
  74. curl_setopt($curl,CURLOPT_HEADER,false);
  75. curl_setopt($curl,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
  76. curl_setopt($curl,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
  77. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
  78. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
  79. $out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
  80. $code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
  81. /* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
  82. $code=(int)$code;
  83. $errors=array(
  84.   301=>'Moved permanently',
  85.   400=>'Bad request',
  86.   401=>'Unauthorized',
  87.   403=>'Forbidden',
  88.   404=>'Not found',
  89.   500=>'Internal server error',
  90.   502=>'Bad gateway',
  91.   503=>'Service unavailable'
  92. );
  93. try
  94. {
  95.   #If the response code is not 200 or 204, we return an error message
  96.  if($code!=200 && $code!=204)
  97.     throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
  98. }
  99. catch(Exception $E)
  100. {
  101.   die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
  102. }
  103.  
  104. /**
  105.  * The data is obtained in the JSON format, therefore, to obtain readable data,
  106.  * We will have to translate the response into a format that PHP understands
  107.  */
  108. $Response=json_decode($out,true);
  109. $Response=$Response['response']['pipelines']['add'];
  110. $output='The ID of the pipelines added:'.PHP_EOL;
  111. $output .= implode(PHP_EOL, array_keys($Response));
  112. return $output;
Updating pipelines

To update the pipeline information, you need to describe an array containing information about the pipeline and put it into an array of the following form: $ pipelines ['request'] ['pipelines'] ['update'] Our API also supports the simultaneous updating of several pipelines simultaneously. To do this, we put several arrays in the $ pipelines ['request'] ['pipelines'] ['update' array, each of which describes the necessary data for updating the corresponding pipeline.

Example of integration
  1. $pipelines['request']['pipelines']['update'] = array(
  2.   2116 => array(
  3.     'id'       => 2116,
  4.     'name'     => 'Renamed Pipeline',
  5.     'sort'     => 1,
  6.     'is_main'  => FALSE,
  7.     'statuses' => array(
  8.       10216993 => array(
  9.         'id'          => 10216993,
  10.         'name'        => 'Initial Contact',
  11.         'sort'        => 10,
  12.         'color'       => '#99ccff',
  13.       ),
  14.       10216994 => array(
  15.         'id'          => 10216994,
  16.         'name'        => 'Offer made',
  17.         'sort'        => 20,
  18.         'color'       => '#ffff99',
  19.       ),
  20.       10216995 => array(
  21.         'id'          => 10216995,
  22.         'name'        => 'Negotiation',
  23.         'sort'        => 30,
  24.         'color'       => '#ffcc66',
  25.       ),
  26.       array(
  27.         'name'        => 'New status#1',
  28.         'sort'        => 40,
  29.         'color'       => '#ffff99',
  30.       ),
  31.       array(
  32.         'name'        => 'New status#2',
  33.         'sort'        => 50,
  34.         'color'       => '#99ccff',
  35.       ),
  36.       array(
  37.         'name'        => 'New status#3',
  38.         'sort'        => 60,
  39.         'color'       => '#ffcccc',
  40.       ),
  41.       142      => array(
  42.         'name'        => 'Closed_won',
  43.       ),
  44.       143      => array(
  45.         'name'        => 'Closed_lost',
  46.       ),
  47.     ),
  48.     'leads'    => 14,
  49.   ),
  50. );
  51. /* Now prepare the data needed to query the server */
  52. $subdomain='test'; #Our account is a subdomain
  53. #Generate a link for the request
  54. $link='https://'.$subdomain.'.amocrm.com/private/api/v2/json/pipelines/set';
  55. /* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about
  56. work with this
  57. library you can read in the manual. */
  58. $curl=curl_init(); #Save the cURL session descriptor
  59. #Set the necessary parameters for the cURL session
  60. curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  61. curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
  62. curl_setopt($curl,CURLOPT_URL,$link);
  63. curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
  64. curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($pipelines));
  65. curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
  66. curl_setopt($curl,CURLOPT_HEADER,false);
  67. curl_setopt($curl,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
  68. curl_setopt($curl,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
  69. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
  70. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
  71. $out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
  72. $code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
  73. /* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
  74. $code=(int)$code;
  75. $errors=array(
  76.   301=>'Moved permanently',
  77.   400=>'Bad request',
  78.   401=>'Unauthorized',
  79.   403=>'Forbidden',
  80.   404=>'Not found',
  81.   500=>'Internal server error',
  82.   502=>'Bad gateway',
  83.   503=>'Service unavailable'
  84. );
  85. try
  86. {
  87.   #If the response code is not 200 or 204, we return an error message
  88.  if($code!=200 && $code!=204)
  89.     throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
  90. }
  91. catch(Exception $E)
  92. {
  93.   die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
  94. }

Removing pipelines

The method allows you to remove pipelines one by one or batch.

Removing one pipeline in your account is not possible, if you delete the last pipeline, you get an error "Impossible to delete last pipeline"

Method URL

POST / private / api / v2 / json / pipelines / delete

Parameters
Parameter Type Description
id array The ID of the pipelines you want to delete. You can pass both a single number and an array of numbers.
Example response
  1. {"request":{"id":123}}
  2. {"request":{"id":[123,456]}}
Response parameters
Parameter Description
response// Associative array, where the key is the id of the pipeline, and the value is whether it was possible to remove the pipeline
response//errors If you can not delete the pipeline, the reason will be written here.
server_time Time stamp of the current server time with offset to the time zone of the account (transmitted in timestamp format)
Example response
  1. {
  2.   "response": {
  3.     123: true,
  4.     456: {"errors": "Impossible to delete last pipeline"}
  5.   }
  6. }
Removing the pipeline

To delete a pipeline, you need to describe the array containing the identifier (s) of the pipeline to be removed and put it into an array of the form: $ pipelines ['request'] ['id']

Example integration
  1. $pipelines['request']['id'] = array(123);
  2. /* Now prepare the data needed to query the server */
  3. $subdomain='test'; #Our account is a subdomain
  4. #Generate a link for the request
  5. $link='https://'.$subdomain.'.amocrm.com/private/api/v2/json/pipelines/delete';
  6. /* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about
  7. work with this
  8. library you can read in the manual. */
  9. $curl=curl_init(); #Save the cURL session descriptor
  10. #Set the necessary parameters for the cURL session
  11. curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  12. curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
  13. curl_setopt($curl,CURLOPT_URL,$link);
  14. curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
  15. curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($pipelines));
  16. curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
  17. curl_setopt($curl,CURLOPT_HEADER,false);
  18. curl_setopt($curl,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
  19. curl_setopt($curl,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__
  20. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
  21. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
  22. $out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
  23. $code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
  24. /* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
  25. $code=(int)$code;
  26. $errors=array(
  27.   301=>'Moved permanently',
  28.   400=>'Bad request',
  29.   401=>'Unauthorized',
  30.   403=>'Forbidden',
  31.   404=>'Not found',
  32.   500=>'Internal server error',
  33.   502=>'Bad gateway',
  34.   503=>'Service unavailable'
  35. );
  36. try
  37. {
  38.   #If the response code is not 200 or 204, we return an error message
  39.  if($code!=200 && $code!=204)
  40.     throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
  41. }
  42. catch(Exception $E)
  43. {
  44.   die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
  45. }
  46. /**
  47.  * The data is obtained in the JSON format, therefore, to obtain readable data,
  48.  * We will have to translate the response into a format that PHP understands
  49.  */
  50. $Response=json_decode($out,true);
  51. $Response=$Response['response'];
  52. $output = 'Query result:' . PHP_EOL;
  53. foreach ($Response as $pipeline_id => $result) {
  54.   if (isset($result['errors'])) {
  55.     $output .= 'Pipeline "' . $pipeline_id . '" not removed, reason: "' . $result['errors'] . '"' . PHP_EOL;
  56.   } else {
  57.     $output .= 'Pipeline "' . $pipeline_id . '" removed' . PHP_EOL;
  58.   }
  59. }
  60. return $output;

The list of pipelines and stages of sales

Method for obtaining a list of pipelines and stages of sales.

Method URL

GET / api / v2 / pipelines

GET parameters
Parameter Description
id Select the pipeline with the given ID
Response parameters
Parameter Type Description
id int The unique pipeline identifier
name string Pipeline name
sort int Pipeline number for display
is_main bool Is the pipeline the "main"
statuses array An array containing information about the stages of sales
statuses//id int The unique identifier of the step
statuses//name string The name of the phase
statuses//color string Stage color
statuses//sort int Sequence number of the stage when displayed
statuses//is_editable bool Is it possible to change or delete this step
_links array Array containing information about the request
_links/self array An array containing information about the current request
_links/self/href string Relative URL of the current request
_links/self/method string Method of the current request
_embedded array An array containing information adjacent to the query
_embedded/items array An array containing information for each individual element
Colors of the stages of sales
Code Example
#fffeb2 color example
#fffd7f color example
#fff000 color example
#ffeab2 color example
#ffdc7f color example
#ffce5a color example
#ffdbdb color example
#ffc8c8 color example
#ff8f92 color example
#d6eaff color example
#c1e0ff color example
#98cbff color example
#ebffb1 color example
#deff81 color example
#87f2c0 color example
#f9deff color example
#f3beff color example
#ccc8f9 color example
#eb93ff color example
#f2f3f4 color example
#e6e8ea color example
Example response
  1. {
  2.    _links: {
  3.       self: {
  4.          href: "/api/v2/pipelines",
  5.          method: "get"
  6.       }
  7.    },
  8.    _embedded: {
  9.       items: {
  10.          10104: {
  11.             id: 10104,
  12.             name: "Pipeline",
  13.             sort: 1,
  14.             is_main: true,
  15.             statuses: {
  16.                142: {
  17.                   id: 142,
  18.                   name: "Closed - Won",
  19.                   color: "#CCFF66",
  20.                   sort: 10000,
  21.                   is_editable: false
  22.                },
  23.                143: {
  24.                   id: 143,
  25.                   name: "Closed - Lost",
  26.                   color: "#D5D8DB",
  27.                   sort: 11000,
  28.                   is_editable: false
  29.                },
  30.                13667501: {
  31.                   id: 13667501,
  32.                   name: "Initial Contact",
  33.                   color: "#99ccff",
  34.                   sort: 10,
  35.                   is_editable: true
  36.                },
  37.                13667502: {
  38.                   id: 13667502,
  39.                   name: "Negotiations",
  40.                   color: "#ffff99",
  41.                   sort: 20,
  42.                   is_editable: true
  43.                },
  44.                13667503: {
  45.                   id: 13667503,
  46.                   name: "Make a decision",
  47.                   color: "#ffcc66",
  48.                   sort: 30,
  49.                   is_editable: true
  50.                },
  51.                13667504: {
  52.                   id: 13667504,
  53.                   name: "Contract Negotiation",
  54.                   color: "#ffcccc",
  55.                   sort: 40,
  56.                   is_editable: true
  57.                }
  58.             }
  59.          }
  60.       }
  61.    }
  62. }
Example integration
  1. $subdomain='test'; #Our account is a subdomain
  2. #Generate a link for the request
  3. $link='https://'.$subdomain.'.amocrm.com/api/v2/pipelines';
  4. /* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about
  5. work with this
  6. library you can read in the manual. */
  7. $curl=curl_init(); #Save the cURL session descriptor
  8. #Set the necessary parameters for the cURL session
  9. curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  10. curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
  11. curl_setopt($curl,CURLOPT_HTTPHEADER,['Accept: application/json']);
  12. curl_setopt($curl,CURLOPT_URL,$link);
  13. curl_setopt($curl,CURLOPT_HEADER,false);
  14. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
  15. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
  16. $out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
  17. $code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
  18. curl_close($curl);
  19. /* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
  20. $code=(int)$code;
  21. $errors=array(
  22.   301=>'Moved permanently',
  23.   400=>'Bad request',
  24.   401=>'Unauthorized',
  25.   403=>'Forbidden',
  26.   404=>'Not found',
  27.   500=>'Internal server error',
  28.   502=>'Bad gateway',
  29.   503=>'Service unavailable'
  30. );
  31. try
  32. {
  33.   #If the response code is not 200 or 204, we return an error message
  34.  if($code!=200 && $code!=204)
  35.     throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
  36. }
  37. catch(Exception $E)
  38. {
  39.   die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
  40. }
  41. /**
  42.  * The data is obtained in the JSON format, therefore, to obtain readable data,
  43.  * We will have to translate the response into a format that PHP understands
  44.  */
  45. $Response=json_decode($out,true);
  46. $Response=$Response['_embedded']['items'];