Need to execute the following API call:
GET /v1/users HTTP/1.1
Host: https://api.someserver.com
Authorization: Bearer MyT0KenGoesH3r3
so far for Yii2 there is lots of documentation about creating your own API, but not how to send a query. Do I need an extension to do this, or am I looking at something like https://github.com/guzzle/guzzle?
There is a HTTP Client Extension for Yii 2. Take a look at https://github.com/yiisoft/yii2-httpclient
Related
Some PUBG API endpoints are returning 404 with the message "Player Not Found"
I've checked that my API key is working properly because I can successfully query other endpoints.
I'm using postman to submit a GET request to the following address:
https://api.pubg.com/shards/steam/players/13DEMAH
I have the following two items included in my header:
Authorization: Bearer myApiKey
accept: application/vnd.api+json
A link to the PUBG documentation: PUBG Documentation
If anyone knows what I'm doing wrong it would be really helpful because I can't figure it out!
What you are doing wrong is that you are using this endpoint /players/{accountId} which require the internal ID in the PUBG API.
So what you can use is:
https://api.pubg.com/shards/steam/players?filter[playerNames]=13DEMAH
To get the information about a PUBG username. (you can also use this endpoint to fetch up to 10 players stats)
What I am tried to do is to have a lambda function proccess emails forwarded by mailgun.
So far, I have setup mailgun's route so it will forward emails to a AWS api gateway, then the api gateway triggers a lambda function.
The problem comes when I try to process the mail, instead of getting a pretty Json that I am expecting inside the lambda's event.body, I m getting raw post form data like
--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Content-Type\"\r\n\r\nmultipart/mixed; boundary=\"001a1140216cee404d05440c49e7\"\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Date\"\r\n\r\nTue, 20 Dec 2016 13:40:53 +1300\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent ......
My question is, what should I do to get the JSON version of the forwarded emails in lambda?
Not sure if you ever came to a solution, but I have this working with the following settings.
Setup your API Gateway method to use "Use Lambda Proxy integration"
In your lambda (I use node.js) use busboy to work through the multi-part submission from mailgun. (use this post for help with busboy Busboy help)
Make sure that any code you are going to execute after all busboy is complete is executed in the 'finish' portion of the busboy code.
This suggests that your mailgun route is misconfigured and ends with a MIME request:
When you specify a URL of your application as a route destination through a forward() action, Mailgun will perform an HTTP POST request into it using one of two following formats:
Fully parsed: Mailgun will parse the message, transcode it into UTF-8 encoding, process attachments, and attempt to separate quoted parts from the actual message. This is the preferred option.
Raw MIME: message is posted as-is. In this case you are responsible for parsing MIME. To receive raw MIME messages, the destination URL must end with mime
From Receiving Messages via HTTP through a forward() action
I'm trying to get a Skywire LTE Cat 1 modem (http://nimbelink.com/skywire-4g-lte-cat-1/) to update a thing shadow on AWS IoT. I have the device talking to AWS via HTTP, and am able to execute a GET command per their tutorial.
Now I am trying to execute a POST command to update my thing's shadow. However, whenever I try to send my POST command:
POST /things/AWS_Test_Thing/shadow HTTP/1.1
BODY: {"state":{"reported":{"Temp":55}}}
AWS sends me the following error:
HTTP/1.1 Bad Request
{"message":"Payload contains invalid json","traceId":"e53be1d6-7967f52c-4dd6-d7b95cc20628"}
I've never used JSON before, but from what I can gather,
{"state":{"reported":{"Temp":55}}}
should be valid JSON and complies with AWS IoT documentation (http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-document-syntax.html#thing-shadow-example-request-json). What am I missing?
If you are updating the shadow via a POST request, you should have a "desired" statement instead of "reported".
Make sure you have the Content-Length header included as part of the request and signing procedure. The Content-Length must reflect the size of the JSON payload you are sending.
I'm testing the Authorization Code Grant protocol on the instance of KeyRock GE at FIWARE-Lab using DHC web client.
So far I have succeeded on implementing the Authorization Request, and I obtain the code to be used on the Access Token Request. The URL for the Authorization Request is the following (although not executed on DHC, but on a regular browser so I can introduce my user and password):
https://account.lab.fiware.org/oauth2/authorize/?response_type=code&client_id=2122&redirect_uri=http%3A%2F%2Flocalhost%2FCallback
I have checked that the client_id and the redirect_uri are both correct against the values related with my application at my account at FIWARE-Lab.
Executing the following request (can't post images, so I'll describe)
POST
https:// account.lab.fiware.org/oauth2/token?grant_type=authorization_code&code=<code>&redirect_uri=http%3A%2F%2Flocalhost%2FCallback -- <code> is the code obtained on the Auth. Request
Authorization: Basic <XXXX> --- <XXXX> is the result of base64(client_id+":"+client_secret)
Content-Type: application/x-www-form-urlencoded
...I get the following error message:
{
"error":{
"message": "create_access_token() takes exactly 3 arguments (2 given)",
"code": 400,
"title": "Bad Request"
}
}
I've checked the authorization is correct (Basic using the OAuth credentials from my application), and I'm using the same redirect_uri used at the previous Authorization Request, and the code obtained from it.
¿What is wrong?
P.S.: If I remove any or all of the query parameters, I still get the same error
Don't pass the parameters in the url. Instead, add them to request's body as query string:
POST /oauth2/token HTTP/1.1
Host: account.lab.fiware.org
Content-Type: application/x-www-form-urlencoded
Authorization: Basic <XXXX> --- <XXXX>
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=1234&redirect_uri=http%3A%2F%2Flocalhost%3A9000%2Fcodecallback.html
I suggest to follow the steps in the presentation:
Adding Identity Management and Access Control to your Application
It gives you details about what are the different requests that you have to follow and also what are the expected response of them.
First, thanks you for your replies.
I try to make an REST API with nodeJS, and i think, oAuth2 is the best way to authenticates users against my system.
Users are stored in LDAP, and api keys will be keep on MySQL engine. Client account code will be also store in MySQL.
All process is OK, users are authenticated, API token has been saved in MySQL but when i try to use this token, passport refuse to authenticated my request and return :
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:691:11)
at ServerResponse.res.setHeader (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/node_modules/connect/lib/patch.js:62:20)
at ServerResponse.res.header (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/lib/response.js:280:8)
at ServerResponse.res.json (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/lib/response.js:135:8)
at exports.info (/home/lolostates/Developpement/nodejs/oauth2/test/user.js:13:9)
at callbacks (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/lib/router/index.js:272:11)
at complete (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/middleware/authenticate.js:218:13)
at /home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/middleware/authenticate.js:200:15
at pass (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/index.js:399:14)
at Passport.transformAuthInfo (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/index.js:415:5)
Request are send by curl:
curl -H "Authorization: Bearer NoulKM889Aksf60rQONcUJwMuZHI3PDqzeXfkX3Li2BohsxNVsOrd2LLdvJAGZuE168IukUCPbviazhvBjt7VDfLFUMJRIY1fa95kGXQQKzE7etFhocsnYvbLSixbHRmCwXNx5FKj6v83Ci9f9xLqRinEKwaAUIjs03hhq8dCWIp7S0Cbi5jdkxlzwfpZxuShoAZYaFInlf4ymG5oyzQe0WJ2POXOaMarGLO7NkjyIMJXWh7s0Y" http://localhost:3000/api/userinfo
I use passport-http-bearer, oAuth2orize, and all example functions presented in OAuth2orize examples.
Could you please explain me why ?
It appears that you attempted to set a response header after the response was sent back. Check to make sure you didn't call res.end() (or a similar method) before you tried to set the headers.