1

I've been trying to make my first successful API call but I get a login screen on my HTTP client. I created a client and used the grant_type: client_credentials to successfully get a token.

I then added the token to my headers before sending the request but I still get redirected to the login screen.

I am very new to APIATO, am I doing anything wrong? Thanks in advance

Limitless Claver
  • 479
  • 5
  • 17

2 Answers2

2

If it is first party client, it is seamless to login using the built in web client proxy at ...v1/clients/web/login. Using a proxy is actually preferred since your oauth keys won't be exposed to the app.

Assuming you have passport installed and have run all database migrations, you can do the following.

  1. First, if not yet done, create a passport client by php artisan passport:install

  2. Add your keys to your .env file

CLIENT_WEB_ID={id-here}
CLIENT_WEB_SECRET={secret-key-here}
  1. Update your config cache so new envs above are picked up by running php artisan config:cache.

  2. Create a user. verification_url is required if you have enabled registration email verification require_email_verification=> true. This url is the same as your .env APP_URL.

POST: {{api-endpoint}}/v1/register
Headers: Accept: application/json
Body
{
    "name": "First Last",
    "gender": "male",
    "birth": "2015-10-15",
    "email": "email@email.com",
    "password": "Password1!",
    "verification_url": "http://{your-domain}/email/verify"
}
  1. After a successful verification. You can now login via the built-in web-client proxy.
POST: {{api-endpoint}}/v1/clients/web/login
Headers: Accept: application/json
Body
{
    "email": "email@email.com",
    "password": "Password1!"
}
Sumatan
  • 106
  • 1
  • 7
0

One thing that I've faced on was apiato doesnt work with php artisan webserver. So, it wont work if you don't have a virtual host installed via nginx or apache. there's a config for api and web routes located in .env

for example :

APP_URL=http://apiato.test
API_URL=http://api.apiato.test

In your webserver config(apache or nginx) create a virtual host for these urls.

Heres a configuration example of setting up a virtual host in nginx:

Setting up a virtual host on nginx

Note: Remember to enable fpm extenstion in your webserver config to run php.

Hope that works.

saeed mzr
  • 101
  • 5