Answers.Body: <p>Unless there's a community plugin specifically built for connecting to this API, you're gonna have to build your own. But a simple module to connect to a third-party API and get some basic data is not super difficult.</p>
  <p>Here's all the code you need for a basic API request:</p>
  <pre class="lang-php prettyprint-override"><code>$guzzle = \Craft::createGuzzleClient();
  // replace with the URL &amp; endpoint you want to look up
  $requestUrl = 'https://your-api-domain.com/movies/123';
  $response = $guzzle-&gt;request(
      'GET',
      $requestUrl,
  );
  $success = $response-&gt;getStatusCode() === 200;
  $data = $response-&gt;getBody();
  </code></pre>
  <p>If the API requires authentication or specific headers, you can add those as the third argument to the <code>request()</code> method. See the documentation for <a href="https://docs.guzzlephp.org/en/stable/" rel="nofollow noreferrer">Guzzle for details</a>.</p>
  <p>Now you only need to figure out two things:</p>
  <ol>
  <li>WHEN do you query the API for WHAT information? On the press of a button, when a specific action is taken in the backend, whenever a specific page is visited? You can use event hooks to trigger your API requests at specific points in your workflow (for example, whenever an entry for an event is saved, so you can add additional information from the API).</li>
  <li>WHERE do you store the API response? If you want to save the response to your entries, look at documentation on how to update entries programmatically. If you want to display the response data directly, you may not need to save it at all (though I would make sure to cache it to avoid hitting the API too many times).</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-05T07:49:26.127Z
Answers.Text: Thank you @MoritzLost, As always straight to the point.
Answers.UserDisplayName: Ra3d K
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-01T15:19:44.287Z
Answers.LastActivityDate: 2021-12-01T15:19:44.287Z
Answers.UserDisplayName: MoritzLost
Body: <p>I have an event page for viewing movies showtime and i want to connect to a 3rd party api to get the movie's info ( show time, cinema name,...etc )
  how to do it?
  can i do this without having to create a plugin to control the request ?
  any ideas would help me get a clear understanding of this concept/code would be very appreciated.</p>
  
Tags: <craft3><request><api>
Title: How does Craft CMS gets data from a 3rd part API?
ThreadText: # How does Craft CMS gets data from a 3rd part API?
  
  (Asked by: username_0 on 2021-12-01)
  
  I have an event page for viewing movies showtime and i want to connect to a 3rd party api to get the movie's info ( show time, cinema name,...etc )
  how to do it?
  can i do this without having to create a plugin to control the request ?
  any ideas would help me get a clear understanding of this concept/code would be very appreciated.
  
  **Tags:** craft3, request, api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-12-01. Score: 3 | Accepted answer
  
  Unless there's a community plugin specifically built for connecting to this API, you're gonna have to build your own. But a simple module to connect to a third-party API and get some basic data is not super difficult.
  
  Here's all the code you need for a basic API request:
  
  ```php
  $guzzle = \Craft::createGuzzleClient();
  // replace with the URL & endpoint you want to look up
  $requestUrl = 'https://your-api-domain.com/movies/123';
  $response = $guzzle->request(
      'GET',
      $requestUrl,
  );
  $success = $response->getStatusCode() === 200;
  $data = $response->getBody();
  
  ```
  
  If the API requires authentication or specific headers, you can add those as the third argument to the `request()` method. See the documentation for [Guzzle for details](https://docs.guzzlephp.org/en/stable/).
  
  Now you only need to figure out two things:
  
  1. WHEN do you query the API for WHAT information? On the press of a button, when a specific action is taken in the backend, whenever a specific page is visited? You can use event hooks to trigger your API requests at specific points in your workflow (for example, whenever an entry for an event is saved, so you can add additional information from the API).
  2. WHERE do you store the API response? If you want to save the response to your entries, look at documentation on how to update entries programmatically. If you want to display the response data directly, you may not need to save it at all (though I would make sure to cache it to avoid hitting the API too many times).
  
  > **Comments:**
  > **username_0**: Thank you @username_1, As always straight to the point.  
  
  ---
  
  