-1

i am trying to get hotels review from expedia.com using graphql API call, i have graphql query and its variable

when i trying with postman its returning proper result but when i trying with cURL php its nothing return

here is my URL

https://www.expedia.com/graphql

here is my row data for post request

{
  "operationName": "Reviews",
  "query": "query Reviews($context: ContextInput!, $propertyId: String!, $pagination: PaginationInput!, $sortBy: PropertyReviewSort!, $filters: PropertyReviewFiltersInput!) {propertyInfo(propertyId: $propertyId,  context: $context) {reviewInfo(sortBy: $sortBy, pagination: $pagination, filters: $filters) { summary { superlative totalCount { raw formatted } reviewCountLocalized averageOverallRating { raw formatted } cleanliness { raw formatted } serviceAndStaff { raw formatted } amenityScore { raw formatted } hotelCondition { raw formatted } cleanlinessPercent cleanlinessOverMax serviceAndStaffPercent serviceAndStaffOverMax amenityScorePercent amenityScoreOverMax hotelConditionPercent hotelConditionOverMax ratingCounts { count { formatted raw } percent rating } lastIndex reviewDisclaimer } reviews { id ratingOverall superlative submissionTime { raw } title text locale author userLocation stayDuration helpfulReviewVotes negativeRemarks positiveRemarks locationRemarks photos { description url } managementResponses { id date displayLocale userNickname response } travelers themes { icon { id description } label } } sortAndFilter { sortAndFilter { name label options { label isSelected optionValue } } } } } }",
  "variables": {
    "context": {
      "siteId": 1,
      "locale": "en_US",
      "currency": "USD",
      "device": {
        "type": "DESKTOP"
      },
      "identity": {
        "duaid": "986e9653-0e36-413f-8fff-19bd7bddbe9b",
        "expUserId": "-1",
        "tuid": "-1",
        "authState": "ANONYMOUS"
      },
      "debugContext": {
        "abacusOverrides": [

        ],
        "alterMode": "RELEASED"
      }
    },
    "propertyId": "1173275",
    "sortBy": "NEWEST_TO_OLDEST",
    "filters": {
      "includeRecentReviews": false,
      "includeRatingsOnlyReviews": true
    },
    "pagination": {
      "startingIndex": 10,
      "size": 10
    }
  }
}

here is my php cURL code

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.expedia.com/graphql",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"operationName\": \"Reviews\",\n  \"query\": \"query Reviews($context: ContextInput!, $propertyId: String!, $pagination: PaginationInput!, $sortBy: PropertyReviewSort!, $filters: PropertyReviewFiltersInput!) {propertyInfo(propertyId: $propertyId,  context: $context) {reviewInfo(sortBy: $sortBy, pagination: $pagination, filters: $filters) { summary { superlative totalCount { raw formatted } reviewCountLocalized averageOverallRating { raw formatted } cleanliness { raw formatted } serviceAndStaff { raw formatted } amenityScore { raw formatted } hotelCondition { raw formatted } cleanlinessPercent cleanlinessOverMax serviceAndStaffPercent serviceAndStaffOverMax amenityScorePercent amenityScoreOverMax hotelConditionPercent hotelConditionOverMax ratingCounts { count { formatted raw } percent rating } lastIndex reviewDisclaimer } reviews { id ratingOverall superlative submissionTime { raw } title text locale author userLocation stayDuration helpfulReviewVotes negativeRemarks positiveRemarks locationRemarks photos { description url } managementResponses { id date displayLocale userNickname response } travelers themes { icon { id description } label } } sortAndFilter { sortAndFilter { name label options { label isSelected optionValue } } } } } }\",\n  \"variables\": {\n    \"context\": {\n      \"siteId\": 1,\n      \"locale\": \"en_US\",\n      \"currency\": \"USD\",\n      \"device\": {\n        \"type\": \"DESKTOP\"\n      },\n      \"identity\": {\n        \"duaid\": \"986e9653-0e36-413f-8fff-19bd7bddbe9b\",\n        \"expUserId\": \"-1\",\n        \"tuid\": \"-1\",\n        \"authState\": \"ANONYMOUS\"\n      },\n      \"debugContext\": {\n        \"abacusOverrides\": [\n          \n        ],\n        \"alterMode\": \"RELEASED\"\n      }\n    },\n    \"propertyId\": \"1173275\",\n    \"sortBy\": \"NEWEST_TO_OLDEST\",\n    \"filters\": {\n      \"includeRecentReviews\": false,\n      \"includeRatingsOnlyReviews\": true\n    },\n    \"pagination\": {\n      \"startingIndex\": 10,\n      \"size\": 10\n    }\n  }\n}",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/json",
    "postman-token: 1a092745-0b00-5abb-3680-8fcd30eae915"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

i also tried with node js request call but its return data in buffer and that data not able to convert to json format

please help me for this issue

Trushar Narodia
  • 3,511
  • 2
  • 11
  • 17

1 Answers1

0

There is an error with your GraphQL query, I'm not sure exactly what, but I used GraphQL Playground and selected "Copy Curl" and pasted the query into your code and that works for me:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.expedia.com/graphql",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => '{"query":"query Reviews($context: ContextInput!, $propertyId: String!, $pagination: PaginationInput!, $sortBy: PropertyReviewSort!, $filters: PropertyReviewFiltersInput!){\n  propertyInfo(propertyId: $propertyId, context: $context) {\n    reviewInfo(sortBy: $sortBy, pagination: $pagination, filters: $filters) {\n      summary {\n        superlative\n        totalCount {\n          raw\n          formatted\n        }\n        reviewCountLocalized\n        averageOverallRating {\n          raw\n          formatted\n        }\n        cleanliness {\n          raw\n          formatted\n        }\n        serviceAndStaff {\n          raw\n          formatted\n        }\n        amenityScore {\n          raw\n          formatted\n        }\n        hotelCondition {\n          raw\n          formatted\n        }\n        cleanlinessPercent\n        cleanlinessOverMax\n        serviceAndStaffPercent\n        serviceAndStaffOverMax\n        amenityScorePercent\n        amenityScoreOverMax\n        hotelConditionPercent\n        hotelConditionOverMax\n        ratingCounts {\n          count {\n            formatted\n            raw\n          }\n          percent\n          rating\n        }\n        lastIndex\n        reviewDisclaimer\n      }\n      reviews {\n        id\n        ratingOverall\n        superlative\n        submissionTime {\n          raw\n        }\n        title\n        text\n        locale\n        author\n        userLocation\n        stayDuration\n        helpfulReviewVotes\n        negativeRemarks\n        positiveRemarks\n        locationRemarks\n        photos {\n          description\n          url\n        }\n        managementResponses {\n          id\n          date\n          displayLocale\n          userNickname\n          response\n        }\n        travelers\n        themes {\n          icon {\n            id\n            description\n          }\n          label\n        }\n      }\n      sortAndFilter {\n        sortAndFilter {\n          name\n          label\n          options {\n            label\n            isSelected\n            optionValue\n          }\n        }\n      }\n    }\n  }\n}","variables":{"context":{"siteId":1,"locale":"en_US","currency":"USD","device":{"type":"DESKTOP"},"identity":{"duaid":"986e9653-0e36-413f-8fff-19bd7bddbe9b","expUserId":"-1","tuid":"-1","authState":"ANONYMOUS"},"debugContext":{"abacusOverrides":[],"alterMode":"RELEASED"}},"propertyId":"1173275","sortBy":"NEWEST_TO_OLDEST","filters":{"includeRecentReviews":false,"includeRatingsOnlyReviews":true},"pagination":{"startingIndex":10,"size":10}}}',
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/json",
    "postman-token: 1a092745-0b00-5abb-3680-8fcd30eae915"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
DJ_Polly
  • 434
  • 3
  • 12