Arzoo Bus booking API integration using PHP Curl and XML - php

I'm working on Bus API of arzoo. The server must receive the posted data in simple POST Request. To achieve this i'm using PHP cURL. In the API Document it is clearly mention that the data should be sent in the following format:
<BusRequest>
<source>HYDERABAD</source>
<dest>BANGALORE</dest>
<dep_date>25-Mar-2016</dep_date>
<PartnerId>ID of the partner given by arzoo</PartnerId>
<Clientid>ID of the client given by arzoo</Clientid>
<Clientpassword>Client password given by arzoo</Clientpassword>
<Clienttype>ArzooBUSWS1.0</Clienttype>
</BusRequest>
My PHP cURL code is as follows:
$input_xml = '<BusRequest>
<source>Ernakulam</source>
<dest>Kozhikode</dest>
<dep_date>15-Nov-2017</dep_date>
<PartnerId>partner</PartnerId>
<Clientid>clientid</Clientid>
<Clientpassword>password</Clientpassword>
<Clienttype>clienttype</Clienttype>
</BusRequest>';
$url = "url";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"xmlRequest=" . $input_xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
curl_close($ch);
I'm not getting any valid xml as response.Am i doing anything wrong ?. Your reply will be appreciated. Thank You.

Related

How to access odata that produced by Nav webservice into html layout using PHP

I try to get odata produced by a navision webservice. When I directly access the url given using chrome browser, the page asks for user name and password and then chrome shows xml data as expected.
But when i use a PHP script, it always returns "1".
My code looks like this:
$url = 'http://103.7.1.182:14048/DynamicsNAV71-6/OData/Company(\'Unit%20G%205\')/Item_Master_on_hand_no_Desc';
$login = 'Gem-gae\senzo1:Bsbsenzo2018';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $login);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/x-www-form-urlencoded',
'Content-Length: ' . strlen(1))
);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
Is there any mistakes with that code ?
Thanks for your help
There's no mistake on your code, it successfully connects to the external server via cURL and retrieves the data.
The value in $output (if you do a var_dump) is true (that's why you see 1 if you echo it).
Said that, the issue is on the server you are contacting (103.7.1.182:14048).
You probably need to send some data or something, I can't tell you exactly what because I don't know what is in that server.
To send data, you can add a curl_setopt line:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
Where $data is an array.

How to retrieve Mailchimp campaign id using api v3

I'm new to the Mailchimp api v3.0 (using php). I've created a campaign with the api and want to retrieve the campaign id from the cURL return data but can't seem to extract just the id. I've been away from php for awhile so I guess I'm just being brain dead. Clearly, I can print the entire result but just need to extract the campaign id in order to add/update content. Most of the test code follows. How do I extract just the id from $retval?
$json_data = json_encode($options);
$auth = base64_encode('prcAdmin:'. $apikey);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://usn.api.mailchimp.com /3.0/campaigns');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content_Type: application/json',
'Authorization: Basic ' . $auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.0');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$retval = curl_exec($ch);
A few typos in your code, let's fix them first.
An extra space in the url
Content_Type to Content-Type. Good to correct it, though the endpoint returns data in a JSON format.
Assuming that you have a valid Auth with valid campaign data, it should return campaign data in JSON format. To extract the campaign id is pretty easy.
$campaign = json_decode($retval, true);
$campaignId = $campaign['id'];
If you can't get correct a campaign id, try to print out the result by using print_r($retval);. The correct data should look similar to an example response found on this page - http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/. (From and between curly brackets).
I resolved the problem: I added a:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
and it obviously returned the response differently so the "id" tag could be referenced as:
$id = json_decode($retval);
echo $id->id;
Now it extracts just the "id".

how to integrate yatra xml soap APi in php

I want to integrate flight API of "yatra". I have xml that we need to to get the result. I have written the following code inside api folder in index.php file, but it keeps reloading the page
hi i am trying to integrate the travel API. i am using following POS code:-
$xml='<POS xmlns="http://www.opentravel.org/OTA/2003/05">
<Source AgentSine="" PseudoCityCode="NPCK" TerminalID="1"><RequestorID ID="AFFILIATE"/>
</Source>
<YatraRequests>
<YatraRequest DoNotHitCache="true" DoNotCache="false" RequestType="SR" AffiliateID="TRAVELPARTNER" MidOfficeAgentID="7499" YatraRequestTypeCode=”SMPA”/>
</YatraRequests>
</POS>';
`$url = "http://localhost/api/index.php";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS,"xmlRequest=" . $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 900);
$data = curl_exec($ch);
curl_close($ch);
print_r($data); die;
//convert the XML result into array
$array_data = json_decode(json_encode(simplexml_load_string($data)), true);
please let me know if I am missing something. above is POS node.The POS element node is common for all the requests send to Yatra Application Framework.

Convert cURL from PHP to ruby code

I am trying to create a form for the user to buy product from my Ruby on Rails website by using their "Scratch Card for Mobile Phones".
The problem is that the service only provides Module code for PHP. So I have to convert it to Ruby to put into my website. Here are the codes I want to convert to Ruby:
$post_field = 'xyz=123&abc=456';
$api_url = "https://www.nganluong.vn/mobile_card.api.post.v2.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$api_url);
curl_setopt($ch, CURLOPT_ENCODING , 'UTF-8');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field);
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
I have tried to convert them to Ruby code but always got confused. Can anyone help me convert these codes into working Ruby codes? Thanks in advance!
Here is my silly code so far:
RestClient.post($api_url, $post_field, "Content-Type" => "application/x-www-form-urlencoded")
Basically all that I need is a ruby version of the php curl code. I'm a newbie, not an experienced programmer, so please help.
Try something like this:
require 'rest-client'
require 'rack'
post_query = 'xyz=123&abc=456'
api_url = "https://www.nganluong.vn/mobile_card.api.post.v2.php"
query_hash = Rack::Utils.parse_nested_query(post_query)
begin
response = RestClient.post api_url, :params => query_hash
print response.code
print response.body
rescue Exception => e
print e.message
end
All the code is doing is sending a payload xyz=123&abc=456 through a POST request to a specified URL.
You might use e.g. the curb gem for this:
response = Curl.post("https://www.nganluong.vn/mobile_card.api.post.v2.php", {:xyz => 123, :abc => 456})
result = response.body_str
status = response.status

post xml using curl

i'm trying to post xml via HTTP POST method...the code works fine and displays the desired message.."Data received successfully"..problem is, on looking it up on the backend, the data is not posted on the Agenda Creative backend..where could i have messed up??thanks in advance.
<?php
function sendXmlOverPost($url, $xml) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// For xml, change the content-type.
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned
// Send to remote and return data to caller.
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$postargs = '<?xml version="1.0" encoding="utf-8"?>
<Vacancy>
<Poster>LOGICMELON</Poster>
<Action>Add</Action>
<Username>agendacreative</Username>
<Password>A12!.ndasa55</Password>
<JobReference>AC Test 1</JobReference>
<JobTitle>AC Test 1</JobTitle>
<JobType>F</JobType>
<JobHours>F</JobHours>
<Industry>137</Industry>
<SalaryCurrency>GBP</SalaryCurrency>
<SalaryFrom>100.0000</SalaryFrom>
<SalaryTo>200.0000</SalaryTo>
<SalaryPer>D</SalaryPer>
<SalaryBenefits>Benefits</SalaryBenefits>
<Salary>£100 - 200 per day + Benefits</Salary>
<JobLocation>4</JobLocation>
<JobCountry>GB</JobCountry>
<JobDescription><p>LOGIC MELON TEST VACANCY - PLEASE DO NOT APPLY!!!</p><p>Testing the initial integration to Agenda Creative to make sure that the template is compiled properly andt hat the fields are getting sent through correctly.</p><p>THIS IS A LOGIC MELON TEST VACANCY - PLEASE DO NOT APPLY FOR THIS ROLE AS IT DOES NOT EXIST!!!</p><p>&euro; - Testing Euro Sign</p><p>&pound; - Testing Pound Sign</p></JobDescription>
<ContactName>Logic Melon Support</ContactName>
<ContactEmail>jade.sinclair.1267EC41.0#applythis.net</ContactEmail>
<ApplicationEmail>jade.sinclair.1267EC41.0#applythis.net</ApplicationEmail>
<ApplicationURL></ApplicationURL>
<WeeksToAdvertise>1</WeeksToAdvertise>
</Vacancy>
';
$request = "http://agendacreativerecruitment.co.uk/feed.php";
echo (sendXmlOverPost($request, $postargs));
?>
I don't know about Agenda Creative. But try something like this?
curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml' => $xml));
where 'xml' is the post field your xml data should be in.

Categories