I am currently in the process of learning how to buid my own REST API using the Slim Framework v3 for PHP. I found several tutorials and was able to build multiple routes to send GET and POST requests to my MySQL database.
Next up for me is a delete request, but it doesn’t work.
This is my code:
$app->delete('/usuario/[{correo}]', function ($request, $response, $args) {
$sth = $this->db->prepare("DELETE FROM usuarios WHERE email=:correo");
$sth->bindParam("correo", $args['correo']);
$sth->execute();
$todos = $sth->fetchAll();
return $this->response->withJson($todos);
});
I’m testing it in Postman and I always have the same problem: 404 Not found.
I can’t understand it because I think the url is correct (http://localhost:8080/usuario/bbb#bbb.es).
Postman view
Can anyone help me?
I think the problem was in the parameter you sent to the route
You can not send dots as a character in your route URL
IF you test
I guess if you test http://localhost:8080/usuario/bbb#bbbdotes
It will work fine
You can send the email address in the body not in the url
{"email":"bbb#bbbdotes"}
And then you can deal with it like POST route to fetch the email address
Related
I am new to vtiger and recently I tried working with third party API integration of vtiger where we can have a query webservice. I tried following API in Postman
http://myurl/webservice.php?operation=query&sessionName=63c67873606f00c2d94fa&query=select count(*) from Leads where Leadid = 1
which is giving 403 error. Also please let me know where to create a webservice in vtiger.
You have to authenticate:
First, get a challenge token:
GET /webservice.php?operation=getchallenge&username=<USERNAME> HTTP/1.1
Then use that token, together with a username and the accesskey of that user (not to be confused with the user's password) to login:
POST /webservice.php HTTP/1.1
operation=login
username=<USERNAME>
accessKey=md5(TOKENSTRING + <ACCESSKEY>) // Note: accessKey= K here is capitalized.
Notice that the concatenation of TOKENSTRING and ACCESSKEY need to be encoded using the md5 function. I recommend using php to do that operation because I've had problems using online encoders.
About the second question, take a look at the folder include/Webservices. Many of the files under that folder are ws functions and you have to create something similar. After created, you have to register
the function by calling vtws_addWebserviceOperation() and
each parameter of the function by calling vtws_addWebserviceOperationParam.
Both of the above functions are defined under /include/Webservices/Utils.php
source: https://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html
I am trying to set up Oauth with the YouTube Data API. I had a Laravel app which has Socialite set up. Out of the box YouTube isn't set up with this but I saw that there is a provider for YouTube here:
https://socialiteproviders.netlify.app/providers/you-tube.html
I have done all of the steps outlined on the page along with all routes that I need. I have also done the Oauth set up on Google Developer Console and got the client ID/secret key and set the callback.
When I use the login URL it works where I'm redirected for login with Google. The problem comes when the callback URL is reached. I get the error:
ErrorException
Undefined index: items
This occurs on the provider callback function which has the code:
$user = Socialite::driver('youtube')->user();
I have tried using stateless:
$user = Socialite::driver('youtube')->stateless()->user();
But get the same error. All caches have been cleared. I am pretty sure that the setup was done correctly as I'm also using the Twitch provider from https://socialiteproviders.netlify.app/providers/twitch.html which the setup was similar and it works correctly.
Please can anyone advise? Thanks.
Try selecting the fields you want to access first:
$user = Socialite::driver('youtube')->fields([
'items'
])->user();
I'm facing the same issue. Is it possible that the API has changed? If I take a look at the raw response there
I also stumbled onto this issue:
When I tested it, I did not got the error, but my colleague did so I figured it had something to do with the account that tried to connect.
I changed my approach from:
$user = Socialite::driver('youtube')->stateless()->user();
And just received tokens by doing this:
$socialite = Socialite::driver('youtube');
$code = $request->input('code');
$response = $socialite->getAccessTokenResponse($code);
$response will contain an array of tokens. I used these tokens to connect it to an existing user in my database.
I don't know if this is the solution for your workflow, but it is a way to get around the mysterious error.
The issue is due to YouTube no longer automatically creating a channel for your google/gmail account like it did in the past. This results in responses completely missing an items array.
if you dd($response->getBody()->getContents()) the response for an account that throws an error you'll see this.
I've made a pull request for this here. https://github.com/SocialiteProviders/YouTube/pull/8
I am building restful api for android app using postman, but in postman only get method is working
complete code is here https://github.com/arvindsinghs/GT/blob/master/apicontroller
this method work if i sent parameters
$atts = \Yii::$app->request->get();
but if it changed it to post method and try to send paramerts in body it is not working
$atts = \Yii::$app->request->post();
Any help is appreciated.
This is not a duplication of my previous question here.
Am using botman to create a bot for my slack app.
Using the slack api, i have created a bot that i want to connect to botman on my laravel app. Am using ngrok to tunnel localhost. I have to get my url verified first in order to use it for the bot. Well i try to verify the url but i keep getting this error.
Your request URL didn’t respond with the correct challenge value. Update your URL to receive a new request and value.
Checking the ngrok terminal shows that the request from slack is being received and the status is 200. If i reproduce the request using postman, the value of the challenge parameter is returned, on slack i still get the erorr. I use this code to load the slack driver on my routes file.
<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\Drivers\Slack\SlackDriver;
use BotMan\BotMan\Drivers\DriverManager;
Route::match(['get', 'post'],'botman', function () {
DriverManager::loadDriver(SlackDriver::class);
// Create BotMan instance
$config = [
'slack' => [
'token' => '***slack Token***' //slack token
]
];
$botman = BotManFactory::create($config);
// give the bot something to listen for.
$botman->hears('hello', function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
// start listening
$botman->listen();
});
I went a head to try force the response with the challenge parameter in the url like so on my routes file.
$payload = $request->json();
if ($payload->get('type') === 'url_verification') {
return $payload->get('challenge');
}
SlackBot::hears('keyword', function (Bot $bot) {
$bot->respond('lets begin');
});
This still does not work, i still get the URL didn’t respond with the correct challenge value... error.
What am i missing? or how should i use the slack driver to have it respond with the right parameters? The web driver works perfectly.
I noticed that the slack api expects the challenge value in json format.
simply doing return $payload->get('challenge'); . does not do the trick. I changed this to return response->json( return $payload->get('challenge'));. This got my url verified.
Am not sure whether this is an issue with the whole botman slack-driver , I didn't find anyone else with the same issue.
I am trying to setup a webhook for the Facebook Messenger Bot Platform and i am receiving this error:
The URL couldn't be validated. Response does not match challenge, expected value = '892694233', received='892694233<link rel...'
I am using a heroku host for testing and a callback URL with SSL, the project is on Laravel 5.2 and this is the code that processs the webhook setup
if ($request->get('hub_verify_token') == config('services.bot.verification_token')) {
return (new Response())->setContent($request->get('hub_challenge'));
}
return (new Response())->setContent('Error: token mismatch');
Sorry for the late answer to my post, the problem was the APP_DEBUG (in .env file) in my Laravel applications is set to TRUE and the request get the code from a debug bar
I'm not familiarized with Lavarel, but looks like the way you are extracting the value of the parameter hub.challenge is giving you a wrong value: '892694233
If you return just the number in the response ('892694233') it should work. Maybe you can clean up the result of calling $request->get('hub_challenge') in order to remove the text at the end?
You have to do like this
if (Request::input('hub_verify_token') === $hubVerifyToken) {
echo Request::input('hub_challenge');
exit;
}