Office 365 API - Request returned HTTP error 400 - rest

I'm trying to follow a tutorial where I pull mail and calendar events from the Office 365 API. I was able to pull mail but when I try to pull calendar events I get back error 400 which, from some Googling, is apparently that one of my headers being too long. I put a var_dump(getallheaders()); and can see the following:
array (size=10)
'Host' => string 'localhost:9999' (length=14)
'Connection' => string 'keep-alive' (length=10)
'Pragma' => string 'no-cache' (length=8)
'Cache-Control' => string 'no-cache' (length=8)
'Accept' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' (length=74)
'Upgrade-Insecure-Requests' => string '1' (length=1)
'User-Agent' => string 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' (length=121)
'Accept-Encoding' => string 'gzip, deflate, sdch' (length=19)
'Accept-Language' => string 'en-US,en;q=0.8' (length=14)
'Cookie' => string 'PHPSESSID=286082ac61749c4e351c1218495859bb; SQLiteManager_currentLangue=2' (length=73)
This all looks fine to me. What am I missing?
EDIT - when I do $response = curl_exec($curl); followed by var_dump($response); I get this:
string '{"error":{"code":"RequestBroker-ParseUri","message":"The $orderby expression must evaluate to a single value of primitive type."}}' (length=130)
The function with $orderby expression is this:
public static function getEvents($access_token, $user_email) {
$getEventsParameters = array (
// Only return Subject, Start, and End fields
"\$select" => "Subject,Start,End",
// Sort by Start, oldest first
"\$orderby" => "Start",
// Return at most 10 results
"\$top" => "10"
);
$getEventsUrl = self::$outlookApiUrl."/Me/Events?".http_build_query($getEventsParameters);
return self::makeApiCall($access_token, $user_email, "GET", $getEventsUrl);
}

Ok. The issue is that we changed the type for the Start property. It's now a complex type. You want to sort on the DateTime property of the Start property, so you'd want to change this line:
"\$orderby" => "Start",
To this:
"\$orderby" => "Start\DateTime",
I thought we had updated the tutorials, but I see that the PHP one isn't updated. I'll work on getting that fixed today!

Related

Invalid character found in method name. HTTP method names must be tokens, persists even with http request

I am trying to warm up my controller so that the service gets hot during each deployment.
In order to do this i have written a perl script as below:
#!perl
use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Request;
my $ua = WWW::Mechanize->new();
my $r = HTTP::Request->new(
'GET' =>
'http://gaurav_setia.microsoft.com:8080/b2h/homepage?_encoding=UTF8&opf_redir=1&portalDebug=1',
[
'Connection' => 'Keep-Alive',
'Via' => 'HTTP/1.1 ShoppingSchedule',
'Accept' =>
'text/x-html-parts,text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Charset' => 'UTF-8',
'Accept-Encoding' => 'identity',
'Accept-Language' => 'en-US',
'Host' => 'gaurav_setia.microsoft.com',
'User-Agent' =>
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
'Cookie' =>
'Original-X-Forwarded-For' => '10.45.103.166',
'X-MS-Internal-Ip-Class' => 'rfc1918',
'X-MS-Internal-Via' =>
'1.1 us-beta-opf-1a-1-67440dc2.us-east-1.ms.com (OPF)',
'X-MS-Urlspace' => 'NoPageType',
'X-MS-Portal-Customer-Id' => 'AMY4OD2PMM9T31',
'X-MS-Portal-Default-Merchant-Id' => 'BTLPDKIKX0DE41',
'X-MS-Portal-Device-Attr' => 'desktop',
'X-MS-Portal-Language' => 'en_US',
'X-MS-Portal-Marketplace-Id' => 'ATVPDKIKX0DER',
'X-MS-Portal-Page-Type' => 'AQGate',
'X-MS-Portal-Request-Attr' => 'internal, http, portal-debug',
'X-MS-Portal-Session-Id' => '1M0-493PO66-0596753',
'X-MS-Portal-Ubid' => '1P2-465OP632-8831161',
'X-MS-Portal-User-Attr' => 'business',
'X-MS-Rid' => 'G308MPK95BWTA69EY2MW',
'X-Forwarded-For' => '10.45.101.126',
'X-Forwarded-Host' => 'development.ms.com',
'X-Forwarded-Server' =>
'development.ms.com, b-hp-shpomnpng-na-2b-02af3555.us-west-2.amazon.com',
'X-Original-Args' => 'portalDebug=1',
'X-Original-Method' => 'GET',
'X-Original-Scheme' => 'http',
'X-Original-Uri' => '/',
],
);
my $res = $ua->request( $r, );
if ( $res->is_success() )
{
print $response->is_success();
}
print $response->status_line;
This script should run after each deployment.
But in the catalina.out logs i am getting the following error:
Dec 13, 2018 9:08:11 AM org.apache.coyote.http11.AbstractHttp11Processor process
INFO: Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
at org.apache.coyote.http11.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:235)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1055)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
I am unable to find the fix!
Many answers say that this is due to https/http issue, but i am making a http call here itself!
In amongst your pile of headers, you have this:
'User-Agent' =>
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
'Cookie' =>
'Original-X-Forwarded-For' => '10.45.103.166',
Notice that there's no value for the Cookie header. That means all of the headers after that will be wrong (the names and values will be muddled up).
Either remove the Cookie line completely or set its value to undef.
'Cookie' => undef,
(Removing it is probably best)

Why does LWP::UserAgent succeed and Mojo::UserAgent fail?

If I make a request like this:
my $mojo_ua = Mojo::UserAgent->new->max_redirects(5);
$mojo_ua->inactivity_timeout(60)->connect_timeout(60)->request_timeout(60);;
$mojo_ua->transactor->name('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36');
my $headers = {
'Accept' => 'application/json',
'Accept-Language' => 'en-US,en;q=0.5',
'Connection' => 'keep-alive',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
'x-csrf-token' => 'Fetch',
'Accept-Encoding' => 'gzip, deflate, br',
'DataServiceVersion' => '2.0',
'MaxDataServiceVersion' => '2.0',
'Referer' => 'https://blah.blas.com/someThing.someThing'
};
my $url = Mojo::URL->new('https://blah.blah.com/irj/go/sap/FOO_BAR_BAZ/');
my $tx = $mojo_ua->get($url, $headers);
$tx = $mojo_ua->start($tx);
my $res = $tx->result;
the request times out, but if I take the exact same request, built in the same way and do this:
my $lwp_ua = LWP::UserAgent->new;
my $req = HTTP::Request->parse( $tx->req->to_string );
$req->uri("$url");
my $res = $lwp_ua->request($req);
it succeeds.
It happens in a few cases that Mojo::UserAgent fails, and LWP::UserAgent succeeds with exactly the same transaction, and I'm starting to get curious.
Any idea as to why?
Your call to
$mojo_ua->get($url, $headers)
has already sent the HTTP request and received the response from the server, errored, or timed out. You don't need to call
$mojo_ua->start($tx)
as well, and that statement should be removed
If you really want to first build the transaction and then start it, you need
my $tx = $mojo_ua->build_tx(GET => $url, $headers);
$tx = $mojo_ua->start($tx);
but I don't see any reason why you should need to do it this way

guzzle 6 post does not work

I am trying to submit a post with JSON content. I always get this message back:
"Client
error: POST
https://sandbox-api-ca.metrc.com//strains/v1/create?licenseNumber=CML17-0000001
resulted in a 400 Bad Request response: {"Message":"No data was
submitted."}"
(All keys and license number are sandbox. I changed keys slightly so auth wont work. )
here is my code
public function metrc()
{
$client = new Client();
$url = 'https://sandbox-api-ca.metrc.com//strains/v1/create?licenseNumber=CML17-0000001';
$request = $client->post($url, [
'headers' => ['Content-Type' => 'application/json'],
'json' => ['name' => "Spring Hill Kush"],
'auth' => ['kH-qsC1oJPzQnyWMrXjw0EQh812jHOX52ALfUIm-dyE3Wy0h', 'fusVbe4Yv6W1DGNuxKNhByXU6RO6jSUPcbRCoRDD98VNXc4D'],
]);
}
Your code is correct, it should works as expected. Seems that the issue is on the server side. Maybe the format of the POST request is not correct?
BTW, 'headers' => ['Content-Type' => 'application/json'] is unnecessary, Guzzle sets the header by itself automatically when you use json option.

mixed up POST values in Perl script

I need to send POST values to server url, and I'm using this code:
$ogone_ua = new LWP::UserAgent;
$ogone_response = $ogone_ua->post("http://server.url/", {
'ACCEPTURL' => 'http://server.url2',
'AMOUNT' => '1000',
'CURRENCY' => 'USD',
'LANGUAGE' => 'en_US',
'ORDERID' => '20130105220939',
'PSPID' => 'vukasin',
'SHASIGN' => '6AEE128943C7C896A6449FF7C2CE702222995B7F'
} );
but server receives:
POST / HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Host: athlon.herrpan.com:2389
User-Agent: SSL-AirKiosk/1.0
Content-Length: 206
Content-Type: application/x-www-form-urlencoded
LANGUAGE=en_US&ACCEPTURL=http%3A%2F%2Fserver.url2&SHASIGN=6AEE128943C7C896A6449FF7C2CE702222995B7F&CURRENCY=USD&AMOUNT=1000&PSPID=vukasin&ORDERID=20130105220939
Why it is not in order? The bank API needs POST values to be sorted, just like in code.
Hashes don't have an inherent order, so the order is lost before ->post is even called. However, POST (to which ->post passes its args) also accepts an array reference.
->post("http://server.url/", [
ACCEPTURL => 'http://server.url2',
AMOUNT => '1000',
CURRENCY => 'USD',
LANGUAGE => 'en_US',
ORDERID => '20130105220939',
PSPID => 'vukasin',
SHASIGN => '6AEE128943C7C896A6449FF7C2CE702222995B7F',
]);

Paypal CreateRecurringPaymentsProfile 10002 error

I'm trying to create recurring payment profile using CreateRecurringPaymentsProfile method of Paypal API version 54.0 56.0 in Sandbox mode.
Unfortunately I'm getting 10002 error "You do not have permissions to make this API call".
I've rechecked API credentials for few times and it looks correct. Also other methods of API (ex. DoDirectPayment) works perfectly.
Does anybody faced such a problem? What a solution?
Thank you very much I need your help.
UPD:
The request is performed by Zend_Http_Client. Sending get array like:
array (
'USER' => 'user_1324103739_biz_api1.domain.com',
'PWD' => 'DCM6SLXFXLW99RRR',
'SIGNATURE' => 'signature',
'VERSION' => '56.0',
'METHOD' => 'CreateRecurringPaymentsProfile',
'TOKEN' => 'EC-12C13621A5208361W',
'IPADDRESS' => '127.0.0.1',
'USER_AGENT' => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7',
'AMT' => 100,
'SUBJECT' => 'Silver plan monthly payment',
'CURRENCYCODE' => 'USD',
'COUNTRYCODE' => 'US',
'EMAIL' => 'user#email.com',
'PROFILESTARTDATE' => '2012-19-01CST3:48:2418',
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => 1)
The request example:
GET /nvp?USER=user_1324103739_biz_api1.domain.com&PWD=DCM6SLXFXLW99RRR&SIGNATURE=signature&VERSION=56.0&METHOD=CreateRecurringPaymentsProfile&TOKEN=EC-12C13621A5208361W&IPADDRESS=127.0.0.1&USER_AGENT=Mozilla%2F5.0+%28X11%3B+Linux+i686%29+AppleWebKit%2F535.7+%28KHTML%2C+like+Gecko%29+Chrome%2F16.0.912.63+Safari%2F535.7&AMT=100&SUBJECT=Silver+plan+monthly+payment&CURRENCYCODE=USD&COUNTRYCODE=US&EMAIL=user%40email.com&PROFILESTARTDATE=2012-19-01CST3%3A48%3A2418&BILLINGPERIOD=Month&BILLINGFREQUENCY=1 HTTP/1.1
Host: api-3t.sandbox.paypal.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Response example:
TIMESTAMP=2011%2d12%2d19T09%3a55%3a14Z&CORRELATIONID=3fcaa599c0ad0&ACK=Failure&VERSION=56%2e0&BUILD=2230381&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2fAuthorization%20Failed&L_LONGMESSAGE0=You%20do%20not%20have%20permissions%20to%20make%20this%20API%20call&L_SEVERITYCODE0=Error
SUBJECT is causing this. SUBJECT is meant for third-party API authorization where the value of SUBJECT is the email address / secure merchant ID of a third party which authorized you to call the API on their behalf, not as a descriptive text. For that you'll want to use 'DESC'.
I would also suggest removing:
IPADDRESS (not part of CreateRecurringPaymentsProfile API)
COUNTRYCODE (not part of CreateRecurringPaymentsProfile API)