Trip advisor Axesso Api - php

I am working with Trip advisor Axesso Api , I want to format my response to json formatted format ,
this is the code I have used
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://axesso-expedia-data-service.p.rapidapi.com/exp/expedia-lookup-reviews?page=2&propertyId=xxxxxx",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-rapidapi-host: axesso-expedia-data-service.p.rapidapi.com",
"x-rapidapi-key: xxxxxxxxxxxxxxe"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo '<pre>';
echo $response;
echo '<pre>';
}
I have tried also
$response = json_encode($response, JSON_PRETTY_PRINT);
But none of them has worked,
Do anyone has an idea about this problem,
Thanks in advance

I'm not a PHP expert but here to help. I believe this should work:
$array = json_decode($response, true);

Related

PHP API request

can anyone help with an API
I having an API that should get parameters in
https://app.wappapi.in/api/send.php?number=9198480xxxxx&type=text&message=test-message&instance_id=609ACF283XXXX&access_token=e10adcxxxxba59axxx56e0xxxxxxxxxx
in post method
the question is if I send it like using this god will it get it like needed?
<?php
$curl = curl_init();
$number=$_POST['type'];
$message=$_POST['type'];
$id=$_POST['type'];
$token=$_POST['type'];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://app.wappapi.in/api/send.php",
CURLOPT_POSTFIELDS => "number={$number}type=text&message={$message}&instance_id={$id}&access_token={$token}",
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST"));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Don't use CURLOPT_POSTFIELDS, because the query parameters come with the URI
Instead:
CURLOPT_URL => "https://app.wappapi.in/api/send.php?number={$number}"
."&type=text&message={$message}&instance_id={$id}&access_token={$token}",
CURLOPT_POST => 1
Hope it solved your problem.

Microsoft Translator Text API CUrl PHP

I have to translate some information of my database to make PDF. I make a PHP function called "translate" that receive the strinf to be trtanslated by parameter. I have this API cURL code:
function translate($text)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://microsoft-translator-text.p.rapidapi.com/translate?to=fr&api-version=3.0&from=pt&profanityAction=NoAction&textType=plain",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "[\r
{\r
\"Text\": \"I would really like to drive your car around the block a few times.\"\r
}\r
]",
CURLOPT_HTTPHEADER => [
"X-RapidAPI-Host: microsoft-translator-text.p.rapidapi.com",
"X-RapidAPI-Key: KEY",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$json = json_decode($response);
echo $json[0]->translations[0]->text;
}
}
I want to replace:
CURLOPT_POSTFIELDS => "[\r
{\r
\"Text\": \"I would really like to drive your car around the block a few times.\"\r
}\r
]",
with:
$text
But i donĀ“t know how. Can you help me?

How can I send whatsapp message to multiple numbers by using ultramsg and PHP

I am trying to send WhatsApp message to multiple numbers by using Ultramsg.com using PHP
by reference: https://docs.ultramsg.com/api/post/messages/chat
the code is like this:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.ultramsg.com/instance1xxx/messages/chat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "token=exxxxxxxx&to=1408XXXXXX1 #c.us,1408XXXXXX2 #c.us&body=WhatsApp API on UltraMsg.com works good&priority=10",
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
but I am getting this error
"to": "Wrong 'to' format for element (1408xxxxxxx #c.us,1408xxxxxxx #c.us). 'to' format : 14155552671#c.us or 14155552671-441234567890#g.us"
I am not understanding this.
I think should try to remove space before #c.us

Cant Extract data from PHP curl response

I learning to use API from: https://rapidapi.com/lambda/api/face-recognition-and-face-detection/endpoints
I want to save or echo albumkey to variable and store in database. I have tried $response->albumkey and didn't work.
here my response below:
{
album: "amanda11",
msg: "Please put this in a safe place and remember it, you'll need it!",
albumkey: "c00bc5d3b1bf64a1ba68f690d4dabee494a2c6fbf48cf8f09c6d41fbece45b7b"
}
And here my code:
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://lambda-face-recognition.p.rapidapi.com/album",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "album=amanda11",
CURLOPT_HTTPHEADER => [
"content-type: application/x-www-form-urlencoded",
"x-rapidapi-host: lambda-face-recognition.p.rapidapi.com",
"x-rapidapi-key: 932571abf0msh45cf0f3cef74aacp19e151jsn33e9949a1974"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo $err;
} else {
echo $response;
}
You need to parse the JSON before you can access its values. In PHP you do that with json_decode():
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo $err;
} else {
$json = json_decode($response);
echo $json->albumkey ;
}
Here's a basic example:
$response = '{
"album": "amanda11",
"msg": "Please put this in a safe place and remember it, you\'ll need it!",
"albumkey": "c00bc5d3b1bf64a1ba68f690d4dabee494a2c6fbf48cf8f09c6d41fbece45b7b"
}';
$json = json_decode($response);
echo $json->albumkey;
Demo

PHP Request for Grafana API Returning Error

I am making a request for api chart to be automatically redirected, without password, after redirection, receive the following alert:
SCRIPT
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "3000",
CURLOPT_URL => "http://localhost:3000/d/BSFmuV5Zz/dash?orgId=1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer api-key-here"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "CURL Error #:" . $err; ?>
<?php } else {
echo $response;
}
?>
Operating System: Windows
Download Link: https://grafana.com/grafana/download?platform=windows

Categories