How to add Supabase Order by in get request using Postman - supabase

I need to add order in supabase result while calling the supabase bash in postman.
I am doing same in flutter like below
Future getPropertiesFromBirmingham() async {
var response = await client
.from('properties')
.limit(10)
.order('created_at', ascending: false);
return response;
}
Need to use same in postman but not getting anything on this.
I didn't find much on this topic, Tried using order in params but it didn't work.

You can get examples of cURL requests directly in Supabase API docs.
You can also check for more documentation directly in the PostgREST website.
curl 'https://supabase_project_ref.supabase.co/rest/v1/properties?limit=10&order=created_at.desc' \
-H "apikey: SUPABASE_KEY" \
-H "Authorization: Bearer SUPABASE_KEY"
You can also control where the NULLs will be (if any) by adding either of the following:
nullslast
nullsfirst
curl 'https://supabase_project_ref.supabase.co/rest/v1/properties?order=created_at.desc.nullslast' \
-H "apikey: SUPABASE_KEY" \
-H "Authorization: Bearer SUPABASE_KEY"

Related

Laravel 9 Request Always Blank When Update Data

I am using laravel 9 and Passport, I can't update data neither PUT nor PATCH method is working.
Here is my route api.php
Route::group(['middleware' => 'auth:api'], function() {
Route::get('logout', [AuthController::class,'logout']);
Route::resource('user',UserController::class);
Route::resource('/admin/post', PostController::class);
});
all another protected routes is ok, but when i Put or patch to localhost:8000 the request is always blank even the id is correct, for example in localhost:8000/api/admin/post/1 and in PostController update(Request $request,$id) when i dd($request, $id) will be "null",5
my request
curl --request PATCH \
--url http://localhost:8000/api/admin/post/5 \
--header 'Accept: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiZDU3MjhjZjZlMGVjMTVmMmQ1ZTJhYzFkMDU3MGQ0YzdhMDBlZmFhMDBjNWY2NDI1Yjk5MjY5YTFiZDNjNDE3Y2MxMmJmMjcwY2FkMjI0ZWUiLCJpYXQiOjE2NjA1MDMxNzYuNTUxMDk2LCJuYmYiOjE2NjA1MDMxNzYuNTUxMDk5LCJleHAiOjE2OTIwMzkxNzYuNTI5MTI0LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.VvYis4iH3pUNLp1Zz4UOC9lQ6h4Gpi4xA44BA4rd7iQe-Z5IowjEwMkkYceuq8sZJAnbp9xh-li_zYXq-tEFakN9gKm3-hxr6gE8sqRj4WCSnVOu_KoqSKWX_FVlDW_IEhIfzGQdeIIRDgXuyz5E6dXxpqqtEsOiRY0KNKxjKRIG7gz0D0CO4lzTRkbly8nCG-CeBBYYS_jXonG4comxPk6eWnbDkw4yNBtdHQ9HK-E92PixbeMW13JPZ5Iiu-JmhLfOSSLrUqa_bJNW7WmbPTsBiyNZyRZ8kEYVbeVvKpMl37HoIDvJnvS9iydLW20Zb7KQkFEoI7bFS7jJdySXXPWIHqnqnFv4u0P6ko1rlLt5PCzyitIX_TdxvXYSaxfUQJMf9SPCG2P0Juxhhcsym8ob70VskVIwSCIGgvbi96JNKBhIhR9bJUX6eEhEOWeWB7jBRaquevTtpTBAm2qbGJPv4Crx2DksFHIuBOxCD33F-MFOSxvK5K2t-NTOofic2cOziYLSgVSrPYy2HHdnriWoAvZynUM2hDYKntzG8x3VYqswYkXwONtyQZpGAGBnDcZq9Fa2YDV6Poqwy_RdeCY6wlyF_1RI6unOgpDYm6GtTE4n51jijNx_kTm9s7F48CHva4aGNATQPoRYuVSWdOZo5VcgkKMfI04np4fQTeY' \
--header 'Content-Type: multipart/form-data' \
--form 'title=mau diganti' \
--form 'description=Sebuah tutorial untuk membunuh polisi' \
--form 'content=hehe' \
--form 'tags=[1,2]' \
--form 'categories=[1]' \
--form 'thumbnail=#C:\Users\Bloop\Pictures\anak kak risti.jpg' \
what is wrong?
Add _method=PUT or _method=PATCH in your body, and use curl --request POST instead.
The PUT and PATCH methods aren't allowed in HTML forms, so Laravel uses this workaround instead.
From the Laravel Docs:
HTML forms do not support PUT, PATCH, or DELETE actions. So, when defining PUT, PATCH, or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form. The value sent with the _method field will be used as the HTTP request method
Chose POST method and add PUT or Patch to your request body

Laravel API: validate doesn't access the PUT request data in my API

Context
I am implementing a user information update using a PUT request in Laravel 8. I use Postman to send the request and see the results.
Expected behavior
My PUT request reaches the controller's function that is censed to update the authenticated user. The latter is updated successfully. So the validate call is executed succesfully and finds the data in the request.
Actual behavior
My PUT request reaches the controller's function that is censed to update the authenticated user. The latter is not updated successfully. In fact, the validate call is executed succesfully but doesn't find the data in the request.
Instead, data validation says:
{
"message": "The given data was invalid.",
"errors": {
"email": [
"The email field is required."
],
"name": [
"The name field is required."
]
}
}
The route & The request
Postman request
curl --location --request PUT 'https://XYZ/api/set_user_data' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 12|leRLA5yopCLIxe0oN9MMThctqD78iJDjZdZQkcgs' \
--data-urlencode 'email=XYZ#XYZ.FR' \
--data-urlencode 'name=test2'
It means in Postman terminology that no "Params" are sent, an Authorization Bearer token is sent, some Headers are sent and some Body's x-www-form-urlencoded data are sent.
API Route
In routes/api.php:
Route::put('/set_user_data', [UserController::class, 'setUserData'])->name('set_user_data');
UserController::setUserData:
public function setUserData(Request $request) {
if(!Auth::check()) {
return 'unauthenticated.';
}
$request->validate([
'email' => 'required|email',
'name' => 'required|string'
]);
// ... update user here but out of topic
}
What I tried to do... or to not do
Some Stackoverflow answers are: send a POST request and send in the body _method=PUT. I don't want to do this. I really prefer to send a PUT request. Because I am developing an API. It totally justifies the fact that I must use a PUT request and not a PUT one.
Some Stackoverflow answers are: use x-www-form-urlencoded not a simple form. It doesn't fix the problem; moreover it's already the case. Maybe it could help with images sending. (notice I don't want to send any image here).
Question
Why Laravel's validate don't find the data of my request and how to fix it?
You are sending the request as "Content-type: application/json", but you are not sending the body as valid JSON.
You are sending this:email=XYZ#XYZ.FR&name=test2
You should send this:
{"email":"XYZ#XYZ.FR", "name": "test2"}
a valid JSON object

Static webpage in s3 bucket and making ajax request inside the page to call lambda function

I have uploaded a html page in s3 bucket and that html page makes an ajax post request to the api gateway url to send an email.
The problem is that the same api gateway url if I use postman to make a post request to it the email is sent but with the html page in s3 having ajax code doesn't work.
Any idea, or help will be helpful for me. Thanks
----Ajax code
$.ajax("https://apigateway-url/email_sending", {
"type": "POST",
"data": JSON.stringify(formData),
"contentType": "application/json"
}).done(function () {
console.log("Done")
}).fail(function () {
console.log("Failed");
// console.log(data);
});
I have tried so many help from net like edit cors configuration in s3 or enable cors in api gateway, but none worked for me.
NodeJs code for send Email
var sendemail = require('./sendemail')
app.post('/email_sending',function(req,res){
console.log("Request received For sending mail")
sendemail.send(req.body,function(err, data){
// res.setHeader('Access-Control-Allow-Origin', '*');
res.end("Success");
})
})
sendemail module snippet is :
ses.sendemail(data, done)
I considered this website but didn't get the solution : https://codehabitude.com/2016/04/05/forms-to-emails-using-aws-lambda-api-gateway/
Its very likely you aren't setting up the CORS headers correctly in apigateway. The apigateway documentation http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html clearly describes the process.
Once you've setup CORS and deployed the changes, you can verify the CORS preflight request using the below curl command
curl -H "Origin: http://example.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: X-Requested-With" \
-X OPTIONS --verbose \
https://apigateway-url/email_sending
Also, note that you need to deploy the changes after you setup CORS (Big blue Deploy API button - http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-deploy-api-with-console.html) before the change is reflected in your API

Getting Error for jersey client request headers?

I need to set these headers for a REST call via jersey client.
clickatell message send rest call
curl -i \
-X POST \
-H "X-Version: 1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Your Authorization Token" \
-H "Accept: application/json" \
My code is:
Client client = Client.create();
WebResource webResource = client.resource("https://api.clickatell.com/rest/message");
ClientResponse response = webResource
.header("Authorization", "Bearer clickATellAuthKey")
.header("X-Version", "1")
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.post(ClientResponse.class, input);
I am getting this error:
{"error":{"code":"001","description":"Authentication
failed","documentation":"http://www.clickatell.com/help/apidocs/error/001.htm"}}
the document says the auth header is not specified. The request is working fine in Postman ( chrome restful client extension) with same headers
Need help.
1) Your headers seem to be going through. If they were not, you would get an error about not setting a version header.
2) The 001 error means your auth token was either not specified, or is incorrect.
3) I suggest that you copy and paste your entire auth token and try again. Watch out for _ or . characters as they are part of the token.
Thanks #whatever_sa there are some improvements required as well in code and also there was an issue with auth key your answer at least make me check the auth key once more. here is the working code
ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)
.header(MessageServices.API_AUTH_HEADER, MessageServices.AUTH_KEY)
.header(MessageServices.API_VERSION_HEADER, MessageServices.API_VERSION)
.post(ClientResponse.class, input);

Parse Cloud - make a GET endpoint

I have made simple cloud function:
Parse.Cloud.define("clientsnames", function(request, response) {
var query = new Parse.Query("Clients");
query.select('name')
query.find({
success: function(results) {
response.success(results)
},
error: function() {
response.error("Failed");
}
})
});
But to call it I always must use POST
curl -s -X POST \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-REST-API-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d "{}" \
https://api.parse.com/1/functions/clients
Which is, of course, a bad idea, and the request itself is obviously should be GET. But when I use GET with this request, I just get 404 (Document not found).
Is it possible to define a GET endpoint using Parse Cloud?
You can use Express js hosted on Parse CloudCode to setup custom endpoints
That way you can configure GET, POST without even using the Parse keys in the headers.
Head over to
https://www.parse.com/docs/cloud_code_guide#webhooks for detailed example

Resources