I am trying to post data using Guzzle 6,
The request which I am generating dynamically looks as below:
$postRequest = Array(
'headers' => array(
['x-api-key'] => 'srDxd39M2FQxxvfvxxcIohcLfKDcdcRUU'
)
'form_params' => array(
[0] => Array (
['name'] => 'function_key'
['contents'] => 'REGISTER'
)
[1] => Array (
['name'] => 'email'
['contents'] => 'tester#test.com'
)
[2] => Array (
['name'] => 'password'
['contents'] => 'test'
)
[3] => Array (
['name'] => 'name'
['contents'] => 'tester'
)
[4] => Array (
['name'] => 'is_org'
['contents'] => 'N'
)
)
)
// Sending Request using 'POST' Method
$client = new GuzzleHttp\Client();
$response = $client->request('POST','abcdxyz.com',$getRequest);
Now my problem is, The Response which I am receiving after sending the above request says "API 'function_key' is missing".
But I am sending 'function_key' as part of request, then What I am missing here ?? Why it is not able to find 'function_key'
Any help is Appreciated
TIA
Try formating it as follows:
$postRequest = [
'headers' => [
'x-api-key' => 'srDxd39M2FQxxvfvxxcIohcLfKDcdcRUU'
],
'form_params' => [
'function_key' => 'REGISTER',
'email' => 'tester#test.com',
'password' => 'test',
'name' => 'tester',
'is_org' => 'N'
]
]
Related
I'm trying to update an item particularly with the "rows" feature in WordPress ACF plugin via PHP using Wordpress API.
The value I'm looking to change is "Monday"
Here's the json from the endpoint:
{
"id": 765,
"acf": {
"contact": "2150",
"sched": [
{
"field_611218a978d03": "Monday",
"field_6112197d78d04": "00:00:00",
"field_6112199f78d05": "17:00:00"
}
],
},
}
I can change the value of "2150" to "2151" with the following:
'body' => array(
'acf' => array (
'contact' => "2151",
),
)
But I can't change the value of "Monday", I've already tried the following:
'body' => array(
'acf' => array (
'sched' => array ( array ( "field_611218a978d03" => "Tuesday")
)
)
As well as:
'body' => array(
'acf' => array (
'sched' => array (
[0] => array( "field_611218a978d03" => "Tuesday")
)
)
)
I've been searching and there seems to be no answer pertaining to this specific problem. I've been stumped for days now. Any help would sincerely be appreciated!
Edit:
To answer CBroe this is the code I'm working with:
$api_response = wp_remote_post( 'domain.com/wp-json/wp/v2/person/765', array(
'headers' => array('Authorization' => 'Basic ' . base64_encode( 'user:pass' )),
'body' => array(
'acf' => array (
'contact' => '2150',
'sched' => array ( array ( "field_611218a978d03" => "Tuesday")
),
)
));
$body = json_decode( $api_response['body'],true);
actually i am tring to get data from url which i already got but i can't able to insert data into the array please check values are dummy1 dummy2
Array ( [id] => 491 [headings] => ‘సౌందర్య లహరి’ ఎలా ఉంది అంటే..? [content] => శ్రీ వాసు దర్శకత్వం లో బెల... [userPic] => 682473.jpg ) JSON sent: {"app_id":"35fi6c27-5f39-4s9f-94db-79bf123g0f9","included_segments":["All"],"data":{"foo":"bar"},"contents":{"en":"dummy1"},"headings":{"en":"dummy2"},"url":"http:\/\/www.gggg.in\/view.php?id=[id]","chrome_web_image":"http:\/\/www.ggg.in\/admin\/user_images\/[userPic]"} JSON received: {"allresponses":"{\"id\":\"f66a03a4-1b17-8tf3-93ed-f3ad6rt7cdb9\",\"recipients\":6}"}
the above data got from url
http://www.ggg.in/gistfile1.php?id=491&headings=%E2%80%98%E0%B0%B8%E0%B1%8C%E0%B0%82%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%AF%20%E0%B0%B2%E0%B0%B9%E0%B0%B0%E0%B0%BF%E2%80%99%20%E0%B0%8E%E0%B0%B2%E0%B0%BE%20%E0%B0%89%E0%B0%82%E0%B0%A6%E0%B0%BF%20%E0%B0%85%E0%B0%82%E0%B0%9F%E0%B1%87..?&content=%20%E0%B0%B6%E0%B1%8D%E0%B0%B0%E0%B1%80%20%E0%B0%B5%E0%B0%BE%E0%B0%B8%E0%B1%81%20%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%95%E0%B0%A4%E0%B1%8D%E0%B0%B5%E0%B0%82%20%E0%B0%B2%E0%B1%8B%20%E0%B0%AC%E0%B1%86%E0%B0%B2...&userPic=682473.jpg
and i need to insert the values in this function
function sendMessage() {
$content = array(
"en" => 'dummy1'
);
$headings = array(
"en" => 'dummy2'
);
$hashes_array = array();
$fields = array(
'app_id' => "35fi6c27-5f39-4s9f-94db-79bf123g0f9",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $headings,
'url' => 'http://www.gggg.in/view.php?id=[id]',
'chrome_web_image' => 'http://www.ggg.in/admin/user_images/[userPic]',
);
OneSignal does not support substituting variable data directly into API calls. However, you can achieve this with Tag and Variable Substitution: https://documentation.onesignal.com/docs/personalization
this is the solutions for this Question i asked about
actually i have a varable passing throug url and i need them to insert into function
$array = [
'id' => 498,
'value2' => 'యూట్యూబ్లో “భరత్ అనే నేను” అన్ కట్ సీన్లు..!',
'value1' => 'కొరటాల శివ దర్శకత్వం లో సూ...',
'value3' => '525722.jpg'
];
sendMessage($array);
function sendMessage($array) {
$content = array(
"en" => $array['value1']
);
$headings = array(
"en" => $array['value2']
);
$hashes_array = array();
$fields = array(
'app_id' => "31pe2347-5i39-4y9f-2222-79b5875f00f9",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $headings,
'url' => 'http://w...content-available-to-author-only...9.in/view.php?id=' . $array['id'],
'chrome_web_image' => 'http://w...content-available-to-author-only...9.in/admin/user_images/' . $array['value3'],
);
print_r($fields);
}
I'm using this shopify api code. I've managed to get my app to install but now when I try to set up a charge for my app when I make the call I get this error:
Exception in api.php line 512:
ERROR #3: <url> malformed
This is my code:
$charge_params = array (
'recurring_application_charge' => array (
'name' => 'Name Of Charge',
'price' => 10,
'return_url' => 'https://dev.shopify.com/show_products/', // also tried escaping the url so https:\/\/dev.shopify.com\/show_products\/
'test' => true
)
);
$charge = $sh->call(['URL' => '/admin/recurring_application_charges.json', 'METHOD' => 'GET', 'DATA' => ['charge_params' => $charge_params]], false);
Can anyone see what I'm doing wrong? I suspect it might be the way the $charge_params is being passed in. There's no documentation on how to pass the charge data through that I can see.
I am just trying to recall what I did on an old project, here is how I handled it, I am using the following package for this https://github.com/phpish/shopify:
$connection = shopify\client($shop, Config::get('shopify.app_api_key'), $token);
$billing = $connection('POST /admin/recurring_application_charges.json', [
'recurring_application_charge' => [
'name' => 'Standard',
'price' => '5.0',
'return_url' => Config::get('app.url') . '/shopify/billing',
'test' => Config::get('shopify.test_mode')
]]);
Not sure if this is any help to you...
Had to pass the full URL and pass the charge array slightly differently. Also changed the method to "POST".
This code did the trick:
$charge = $sh->call([
'URL' => 'https://mystore.myshopify.com/admin/recurring_application_charges.json',
'METHOD' => 'POST',
'DATA' => array (
'recurring_application_charge' => array (
'name' => 'Name Of Charge',
'price' => 10,
'return_url' => 'https://dev.shopify.com/show_products/',
'test' => true
)
)
], false);
print_r($charge);
exit;
This returned the following:
stdClass Object ( [recurring_application_charge] => stdClass Object ( [id] => 2655692 [name] => Name Of Charge [api_client_id] => 1182423 [price] => 10.00 [status] => pending [return_url] => https://dev.shopify.com/show_products/ [billing_on] => [created_at] => 2016-08-03T13:50:11-04:00 [updated_at] => 2016-08-03T13:50:11-04:00 [test] => 1 [activated_on] => [trial_ends_on] => [cancelled_on] => [trial_days] => 0 [decorated_return_url] => https://dev.shopify.com/show_products/?charge_id=2655692 [confirmation_url] => https://mystore.myshopify.com/admin/charges/2655692/confirm_recurring_application_charge?signature=BAhpA8yFKA%3D%3D--8f87b4bd0d3cb9a588dfcb1566572731c0118776 ) )
I am trying to write a simple PHP client to get some data from Betfair through the Free Access API http://bdp.betfair.com/?option=com_content&task=view&id=33&Itemid=62
I can login & get a session token, this way
$wsdl = 'https://api.betfair.com/global/v3/BFGlobalService.wsdl';
$soapClient = new SoapClient($wsdl);
try {
$ap_param = array(
'request' =>
array(
'username' => 'my_username',
'password' => 'my_password',
'productId' => '82',
'ipAddress' => '',
'locationId' => '',
'vendorSoftwareId' => '',
),
);
$response = $soapClient->__call("login", array($ap_param));
...
$response is an object containing the sessionToken param
But after several tries I am afraid I am sending the APIRequestHeader param (http://bdp.betfair.com/docs/) malformed, cause the response to any call (getAllEventTypes, for instance) is always returning the same: NO_SESSION
One try...
$ap_param = array(
'request' =>
array(
'header' => array(
'session_token' => $response->Result->header->sessionToken,
'clientStamp' => 0,
),
),
);
Another try...
$ap_param = array(
'request' =>
array(
'session_token' => $response->Result->header->sessionToken,
'clientStamp' => 0,
),
);
And lot of other tries... but
$response = $soapClient->__call("getAllEventTypes", array($ap_param));
$response is always the same
stdClass Object
(
[Result] => stdClass Object
(
[header] => stdClass Object
(
[errorCode] => NO_SESSION
[minorErrorCode] =>
[sessionToken] =>
[timestamp] => 2013-11-09T08:41:01.015Z
)
[eventTypeItems] =>
[minorErrorCode] =>
[errorCode] => API_ERROR
)
)
Someone here has faced the same problem?
Stupid typo error there...
session_token should be sessionToken
$ap_param = array(
'request' =>
array(
'header' => array(
'sessionToken' => $response->Result->header->sessionToken,
'clientStamp' => 0,
),
),
);
The script below apparently uses the API documented at http://www.hasoffers.com/wiki/Offer:create. S the question has (at least) two parts: a) How to store more than one data set within an array. b) Does the API accept it....
When i run the script it only stores the last value inside 'data' how can i get it to store more data at once?
The code below has for example 2 values. one is caled LOLO and the other one is caled LELE.
The output shows only the value LELE.
this is the code.
<?php
header('Content-type: application/json');
$base = 'http://api.hasoffers.com/Api?';
$params = array(
'Format' => 'json'
,'Target' => 'Offer'
,'Method' => 'create'
,'Service' => 'HasOffers'
,'Version' => 2
,'NetworkId' => 'demo'
,'NetworkToken' => '....'
,'data' => array(
'name' => 'LOLO'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
,'name' => 'LELE'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
)
);
$url = $base . http_build_query( $params );
$result = file_get_contents( $url );
print_r( json_decode( $result) );
?>
and this is the output
[request] => stdClass Object
(
[Target] => Offer
[Format] => json
[Service] => HasOffers
[Version] => 2
[Method] => create
[NetworkId] => demo
[NetworkToken] => NETU2nzMw8AYS6EGgjFrjGR88GcSiF
[data] => stdClass Object
(
[name] => LELE
[description] => test
[offer_url] => http://google.nl
[preview_url] => http://google.nl
[expiration_date] => 08-08-2013
)
)
'data' => array(
array (
'name' => 'LOLO',
'description' => 'test',
'offer_url' => 'http://google.nl',
'preview_url' => 'http://google.nl'
'expiration_date' => '08-08-2013'),
array (
'name' => 'LELE',
'description' => 'test',
'offer_url' => 'http://google.nl',
'preview_url' => 'http://google.nl',
'expiration_date' => '08-08-2013'))
,'data' => array( array(
'name' => 'LOLO'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
),
array(
,'name' => 'LELE'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
)
)
You need to add it as a multi dimensional array or else it will overwrite the elements with same key. Please note the array (....) addd inside your array
array( array(
Or you can store it in this way
$data = array();
$data[0] = array('name' => 'LELE'
, 'description' => 'test'
, 'offer_url' => 'http://google.nl'
, 'preview_url' => 'http://google.nl'
, 'expiration_date' => '08-08-2013'
);
$data[1] = array('name' => 'LOLO'
, 'description' => 'test'
, 'offer_url' => 'http://google.nl'
, 'preview_url' => 'http://google.nl'
, 'expiration_date' => '08-08-2013'
);
$params = array(
'Format' => 'json'
, 'Target' => 'Offer'
, 'Method' => 'create'
, 'Service' => 'HasOffers'
, 'Version' => 2
, 'NetworkId' => 'demo'
, 'NetworkToken' => 'NETU2nzMw8AYS6EGgjFrjGR88GcSiF'
, 'data' => $data
);
print_r($params);
// Output
Array
(
[Format] => json
[Target] => Offer
[Method] => create
[Service] => HasOffers
[Version] => 2
[NetworkId] => demo
[NetworkToken] => NETU2nzMw8AYS6EGgjFrjGR88GcSiF
[data] => Array
(
[0] => Array
(
[name] => LELE
[description] => test
[offer_url] => http://google.nl
[preview_url] => http://google.nl
[expiration_date] => 08-08-2013
)
[1] => Array
(
[name] => LOLO
[description] => test
[offer_url] => http://google.nl
[preview_url] => http://google.nl
[expiration_date] => 08-08-2013
)
)
)
a) How to store more than one data set within an array.
$fixed_params = array(
'Format' => 'json'
,'Target' => 'Offer'
,'Method' => 'create'
,'Service' => 'HasOffers'
,'Version' => 2
,'NetworkId' => 'demo'
,'NetworkToken' => '....'
);
$offer_data = array(
array(
'name' => 'LOLO'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
),
array(
'name' => 'LELE'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
)
);
// store all results here
$result = array();
// iterates two times since $offer_data has two elements.
foraech ($offer_data as $offern => $data ){
// store offer's data into fixed_params['data'] element.
$fixed_params['data'] = $data;
$url = $base . http_build_query( $fixed_params );
$result[] = json_decode( file_get_contents( $url ));
}
print_r($result);
b) Does the API accept it....
As I understand the API, it accepts only one create at time. See http://www.hasoffers.com/wiki/Offer:create it says: Creates a new offer.
This is what i did and it works
<?php
// Bestand openen
if (($file = fopen("test2.csv", "r")) !== FALSE) {
// Eerste rij van Excel als value gebruiken
$header = fgetcsv($file, 1000, ";");
// Een loop door Excel file
while (($data = fgetcsv($file, 1000, ";")) !== FALSE) {
// combineer de eerste rij met de gegevens
$combined = array_combine($header,$data);
// Connectie maken met Hasoffers bij elke waarden
$base = 'http://api.hasoffers.com/Api?';
$params = array(
'Format' => 'json'
,'Target' => 'Offer'
,'Method' => 'create'
,'Service' => 'HasOffers'
,'Version' => 2
,'NetworkId' => 'demo'
,'NetworkToken' => '.....'
,'data' => $combined
);
$url = $base . http_build_query( $params );
$result = file_get_contents( $url );
// Tijdelijk printen
print_r( json_encode( $result) );
}
}
?>
I've created a loop including a CSV file.
the problem was that it connected only once with hasoffer and that allowed only one value.