$url ="https://marketplace.walmartapis.com/v3/items?nextCursor=250&includeDetails=true&offset=0&limit=20"; - walmart-api

$url ="https://marketplace.walmartapis.com/v3/items?nextCursor=250&includeDetails=true&offset=0&limit=20";
this url not working giving error in the walmart.
[error] => Array
(
[0] => Array
(
[code] => INVALID_REQUEST.GMP_ITEM_QUERY_API
[field] => 400_BAD_REQUEST
[description] => Bad Request. Missing Important Headers ( like ConsumerId) or Inputs.
[info] => Request invalid.
[severity] => ERROR
[category] => DATA
)
)

I haven't been able to get the offset to work, but you can use the nextCursor parameter to page through the list.
The nextCursor=250 part is what's causing the 400 Bad request error. That's not how it's used, or what the API is expecting. Leave it off completely for your first request:
https://marketplace.walmartapis.com/v3/items?includeDetails=true&offset=0&limit=20
Then use the value of the nextCursor from the response you get as the parameter for the next call.
https://marketplace.walmartapis.com/v3/items?nextCursor=VGhpc1dvdWxkQmVUaGVuZXh0Q3Vyc29yVmFsdWU=

Related

Forward message similar to webhook from a Studio Flow

I have the ability to receive the full incoming message from setting a url in the number section under "A message comes in" to Webhook and entering my url. I would like my messages to be processed in a Studio Flow first. Is there any way from the flow I could then pass it out to a webhook url? I know the webhook sends this info in json, but I'm not sure if I can build all of this data with the html widget. Any idea for how I could do it?
(
[inbound] =>
[ToCountry] => US
[ToState] => OK
[SmsMessageSid] => xxx
[NumMedia] => 0
[ToCity] => NOBLE
[FromZip] => 73003
[SmsSid] => xxx
[FromState] => OK
[SmsStatus] => received
[FromCity] => EDMOND
[Body] => Test
[FromCountry] => US
[To] => +xxx
[ToZip] => 73068
[NumSegments] => 1
[MessageSid] => xxx
[AccountSid] => xxx
[From] => +xxx
[ApiVersion] => 2010-04-01
)
Twilio developer evangelist here.
You could certainly pass it to a Studio Flow first, as you describe, and then use the HTTP request to send all the data onto a webhook URL of your own.
To send all the data onto your own URL, you would need to add all the parameters to the widget too. You'll find all that data in the trigger object within the flow.

"Unexpected. Please try again." error when performing simple query

I keep receiving a status 500 error: "Unexpected. Please try again" message when I perform a query using the Ruby client. This query works when I input this into the API explorer on the google site.
Here is the code:
result = client.execute(
:api_method => bigquery.jobs.query,
:parameters => {"projectId" => "projectId"},
:body_object => { "kind" => "bigquery#queryRequest", "query" => "SELECT date FROM
[google.com:adsense-reports:Reports.DailyAdUnitReport] WHERE date = CURRENT_DATE()"}
)
Is there an error in this syntax?
When you say {"projectId" => "projectId"} did you actually have your project-ID in the code and redacted it here or did you pass the string "projectID" there?
If the latter is true, you might want to substitute that to pass your project-id which is a string that can be found in the project console here: https://cloud.google.com/console/project

Drupal: $_POST and MENU_CALLBACK. How works?

i've read this ad this but nothing is working for me
I'd like to create a menu like this
$items['login'] = array(
'page callback' => 'mymodule_login',
'access arguments' => array('access content'),
'access callback' => true,
'type' => MENU_CALLBACK,
);
in order to send a POST to http://www.example.com/login. The body contains a json with username e password. Everything is ok, except for $_POST under function mymodule_login that does not works. $_POST is empty. What's wrong? Is there another "drupalic" way?
Try this:
$data = file_get_contents("php://input");
Or make sure your form url using trailing slash:
<form action="login/" method="post">

How to correctly form yahoo boss url query

I am a novice programmer trying to understand how the api works. Been studying it for the last few days and been making some progress, but still need some help.
This seems to be the url to submit the query to, don't quite understand how to correctly form it?
$url = "http://yboss.yahooapis.com/ysearch/web";
If I want the results to come back as json, would this be correct?
$url = "http://yboss.yahooapis.com/ysearch/web?q={keywords}&format=json";
This really has me stumped, not sure at all how to get the actual query from the html form passed, would this be correct?
$url = "http://yboss.yahooapis.com/ysearch/web?q={keywords}";
If so, would I then need to include:
$args["keywords"]
If I could figure out how to correctly pass the query from the html form, I believe most of my other questions would also be answered.
Regarding this section, I assume these are the variables for various arguments that the api service allows. For each argument, do I have to include corresponding $args[""] code in the list below? For example, if I have &format=json in the url query, then I would also need to keep $args["format"] = json"; in the list below?
$args = array();
$args["q"] = "yahoo";
$args["format"] = "json";
Or say, if wanted to include:
$url = "http://yboss.yahooapis.com/ysearch/web?q={keywords}&abstract=long";
would I also need to include:
$args[abstract] = "long";
to the $args list above?
The part that really has me stumped is how do I get the actual query that is submitted through the html form to pass?
$url = "http://yboss.yahooapis.com/ysearch/web?q={keywords}
Do I then include a:
$args["keywords"]
to the $args list?
When I go to test it this is the results I get:
domain.com/search.php?q=car
stdClass Object ( [bossresponse] => stdClass Object ( [responsecode] => 200 [web] => stdClass Object ( [start] => 0 [count] => 50 [totalresults] => 112000000 [results] => Array ( [0] => stdClass Object ( [date] => [clickurl] => http://www.yahoo.com/ [url] => http://www.yahoo.com/ [dispurl] => www.yahoo.com [title] => Yahoo! [abstract] => Yahoo! home page with the latest breaking news and interesting articles, what items are trending now on the internet, links to other Yahoo! sites and local news and ... ) [1] => stdClass Object ( [date] => [clickurl] => http://mail.yahoo.com/ [url] => http://mail.yahoo.com/ [dispurl] => mail.yahoo.com [title] => Sign in to Yahoo! [abstract] => Yahoo! makes it easy to enjoy what matters most in your world. Best in class Yahoo! Mail, breaking local, national and global news, finance, sports, music, movies and ... ) [2] => stdClass Object ( [date] => [clickurl] => http://us.yahoo.com/ [url] => http://us.yahoo.com/ [dispurl] => us.yahoo.com [title] => Yahoo! [abstract] => A new welcome to Yahoo!. The new Yahoo! experience makes it easier to discover the news and information that you care about most. It's the web ordered for you. ) [3] => stdClass Object ( [date] => [clickurl] => http://sports.yahoo.com/ [url] => http://sports.yahoo.com/ [dispurl] => sports.yahoo.com [title] => Yahoo! Sports - Sports News, Scores, Rumors, Fantasy Games ... [abstract] => All the latest sports news, scores, rumors, fantasy games, and more ) [4] => stdClass Object ( [date] => [clickurl] => http://my.yahoo.com/ [url] => http://my.yahoo.com/ [dispurl] => my.yahoo.com [title] => Sign in to Yahoo! [abstract] => My Yahoo is a customizable web page with news, stock quotes, weather, and many other features. ) [5] => stdClass Object ( [date] => [clickurl] => http://dir.yahoo.com/ [url] => http://dir.yahoo.com/ [dispurl] => dir.yahoo.com [title] => Yahoo! Directory [abstract] => Help us improve the Yahoo! Directory - Share your ideas ) [6] => stdClass Object ( [date] => [clickurl] => http://search.yahoo.com/ [url] => http://search.yahoo.com/ [dispurl] => search.yahoo.com [title] => Yahoo! Search - Web Search [abstract] => The search engine that helps you find exactly what you're looking for. Find the most relevant information, video, images, and answers from all across the Web. ) [7] => stdClass Object ( [date] => [clickurl] => http://news.yahoo.com/ [url] => http://news.yahoo.com/ [dispurl] => news.yahoo.com [title] => Yahoo! News - Latest News & Headlines [abstract] => The latest news and headlines from Yahoo! News. Get breaking news stories and in-depth coverage with videos and photos. ) [8] => stdClass Object ( [date] => [clickurl] => http://autos.yahoo.com/ [url] => http://autos.yahoo.com/ [dispurl] => autos.yahoo.com [title] => New car pictures, prices and reviews - Yahoo! Autos [abstract] => See new car pictures, find out new car prices and read new car reviews on Yahoo! Autos. Compare cars and get a free price quote from dealers near you. Check out Clear ... ) [9] => stdClass Object ( [date] => [clickurl] => http://us.m.yahoo.com/ [url] => http://us.m.yahoo.com/ [dispurl] => us.m.yahoo.com [title] => Yahoo! Mobile [abstract] => At your Yahoo!
Obviously the query is not being passed properly because the result is all about Yahoo instead of the query "car". And it looks like it is an unformatted json response because I know xml is way different. Any links to a good tutorial on json would be great.
If I could figure out how to get the actual query passed from the html form, I believe it would answer many of these questions.
Below is what I believe to be the default code that yahoo supplies to display the results:
$results = json_decode($rsp);
print_r($results);
Would I need to set up some type of json code for that? Could an example or link be provided to help me better understand json, I know the basis of it is key value pairs, but have never worked with json before, not sure where to start....
I apologize for such a long question, but I have many questions and instead of submitting mutliple questions, I figured 1 long question would be best.
This is what I'm using for Yahoo BOSS API in PHP, I hope it helps
<?php
// This enable debugging
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require("OAuth.php"); // You will need to make your own OAuth.php
$cc_key = "---FILL THIS IN WITH YOUR INFO---";
$cc_secret = "---FILL THIS IN WITH YOUR INFO---";
$url = "http://yboss.yahooapis.com/ysearch/web"; // This can be tweaked to search images, videos etc
$args = array();
$args["q"] = "--FILL THIS IN WITH WHAT YOU WANT TO SEARCH FOR---"; // search operator, fill in with query value
$args["count"] = "10"; // Default is 50, restricts results down to 10
$args["web.sites"] = ""; // comma separated value, optional -- usnews.com,nytimes.com, etc
$args["format"] = "json"; // Default is json, options are xml or json, code below only works for JSON at the moment
$consumer = new OAuthConsumer($cc_key, $cc_secret);
$request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $url, $args);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
$url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
echo $url . "<br>";
$ch = curl_init();
$headers = array($request->to_header());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$rsp = curl_exec($ch);
$results = json_decode($rsp); // Decodes JSON
print_r($results); // Prints results to screen
?>

Accessing data from httparty response

Using httparty I can get the following response:
puts Representative.find_by_zip(46544).inspect
-->
{"results"=>[{"name"=>"Joe Donnelly", "district"=>"2", "office"=>"1218 Longworth", "phone"=>"(202) 225-3915", "link"=>"http://donnelly.house.gov/", "state"=>"IN"}]
source of the example: http://railstips.org/blog/archives/2008/07/29/it-s-an-httparty-and-everyone-is-invited/
but I fail to access the data, for example:
Representative.find_by_zip(46544).inspect["name"] returns nil
How can I access individual elements of this response?
Object#inspect returns a string, not a hash. You want this:
Representative.find_by_zip(46544)['results'][0]['name']
This is what's going on: Representative#find_by_zip returns a Hash with just one index: 'results'. The item at 'results' is an array, which in this case only contains one element, so we use [0] to get the first (and only) element. That element is itself a hash that has the 'name' key, which points to the name of the first (and only) representative returned.
When you have complex hashes and arrays it's sometimes useful to format it in a more readable way to figure out how to get at the data you want:
{ "results" => [
{ "name" => "Joe Donnelly",
"district" => "2",
"office => "1218 Longworth",
"phone" => "(202) 225-3915",
"link" => "http://donnelly.house.gov/",
"state" => "IN"
}
]
}
That should make it more clear what's inside what here.
To Access the individual elements, You can use:-
If the response is JSON:-
You can use:-
response.parsed_response["key"]
If your response is a string then, you can use:-
data = JSON.parse(resp.body)
The response type depends, on the content type you are setting while requesting the data:-
'Content-Type' => 'application/json'
If you don't set the content type it returns response as string.

Resources