curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: How to work with Amadeus ?

From: Dan Richter via curl-users <curl-users_at_cool.haxx.se>
Date: Tue, 8 Sep 2020 13:10:48 +0200

That's great, it works perfectly (I used my access rights, API Key & API
Secret). Thank you very much.

I got reply from Amadeus (strings altered for posting here ;-)):

...
< Server: Amadeus
<
* Connection #0 to host test.api.amadeus.com left intact

         {
             "type": "amadeusOAuth2Token",
             "username": "name_at_xxx.com",
             "application_name": "Test",
             "client_id": "xF1ywe4wwzDg3aFVAq19WecrgA3jthKx",
             "token_type": "Bearer",
             "access_token": "VLHdm2tTNf6ojlg7J2ZLla5pACNa",
             "expires_in": 1799,
             "state": "approved",
             "scope": ""
         }

Next step is how to parse "access_token" and store its value into
variable for further use (Amadeus API calls).
See description here, Step 4: Make your first call:
https://developers.amadeus.com/get-started/get-started-with-self-service-apis-335

Than how to continue with received token to send the first API inquiry
to Amadeus ?

curl -X GET
'https://test.api.amadeus.com/v1/shopping/flight-destinations?origin=PAR&maxPrice=200'
-H 'Authorization: Bearer {{token}}'

--dr

Dne 08.09.2020 v 12:29 Gisle Vanem via curl-users napsal(a):
> Dan Richter wrote:
>
>> I am a newbie to cURL on C++ (Visual Studio 2017).
>>
>> Any advice how to modify the working sample code below to send
>> Authorization Request/Response (token) to Amadeus API and than send
>> the actual Amadeus command ? See
>> https://developers.amadeus.com/self-service/apis-docs/guides/authorization-262
>>
>> // CurlTest.cpp
>>
>> #define CURL_STATICLIB
>> #include <iostream>
>> #include <string>
>>
>> #include "curl/curl.h"
>>
>> static size_t my_write(void* buffer, size_t size, size_t nmemb, void*
>> param)
>> {
>>      std::string& text = *static_cast<std::string*>(param);
>>      size_t totalsize = size * nmemb;
>>      text.append(static_cast<char*>(buffer), totalsize);
>>      return totalsize;
>> }
>>
>> int main()
>> {
>>      /*std::cout << "Hello World!\n";*/
>>      std::string result;
>>      CURL* curl;
>>      CURLcode res;
>>
>>      curl = curl_easy_init();
>>      if (curl) {
>>          curl_easy_setopt(curl, CURLOPT_URL,
>> "https://tcno.co/hello.txt");
>>          curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write);
>>          curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
>>
>>          curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
>>
>>          res = curl_easy_perform(curl);
>>
>>          curl_easy_cleanup(curl);
>>
>>          if (CURLE_OK != res) {
>>              std::cerr << "CURL error: " << res << '\n';
>>          }
>>      }
>>      curl_global_cleanup();
>>
>>      std::cout << result << "\n\n";
>> }
>>
>
> Using the '--libcurl -' option is handy to see what would
> be done.
>
> Put something like this in a 'curl-amadeus.bat':
>   set CLIENT_ID=none
>   set CLIENT_SECRET=01234567
>
>   curl.exe -X POST --libcurl - %*   ^
>      -H "Content-Type: application/x-www-form-urlencoded" ^
>      -d
> "grant_type=client_credentials&client_id=%CLIENT_ID%&client_secret=%CLIENT_SECRET%"
> ^
>      --write-out json ^
>      https://test.api.amadeus.com/v1/security/oauth2/token
>
> and note what 'curl.exe' spits out:
>   CURLcode ret;
>   CURL *hnd;
>   struct curl_slist *slist1;
>
>   slist1 = NULL;
>   slist1 = curl_slist_append(slist1, "Content-Type:
> application/x-www-form-urlencoded");
>
>   hnd = curl_easy_init();
>
>   ...
>   curl_easy_setopt(hnd, CURLOPT_POSTFIELDS,
> "grant_type=client_credentials&client_id=none&client_secret=01234567");
>   curl_easy_setopt(hnd, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)67);
>
>   curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
>   curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
>   ...
>
> So add those libcurl calls to your code.
>
> But Amadeus says:
>   "title": "Invalid parameters"
>

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-09-08