Sanity.io webhook with body params - sanity

I added a webhook to Sanity and it works as expected, but I would like to pass a parameter in the body for {branch:"develop"} and I do not see an input field.
I have tried appending ?branch=develop to the url, but that does not work.
Any ideas on how to include this parameter?

Would it work to add this into your projection? Something like the following would return everything, plus 'branch': 'develop':
{
...,
'branch': 'develop',
}

Related

Generate aurelia route with parameters and open in new browser tab

I need to open a page in new tab with defined parameters.
Before I used only one parameters and it works fine:
window.open(this.theRouter.generate('transactionDetails', { id: id }), '_blank');
But now I need to add two more parameters.
I tried the following:
window.open(this.theRouter.generate('transactionDetails', { id: id, localtimezone: this.localTimeZone, reporttimezone: this.reportTimeZone }), '_blank');
But as result I can see in URL this:
http://localhost:54072/index.html#/transactionDetails/28789?localtimezone=3&reporttimezone=0
What I do wrong? How I can generate url with some parameters?
Thanks in advance.
You have to decide how to pass parameters.
The way your example looks it seems your route declares the "id" parameter.
If you declare parameters, the most consistent way is to declare every parameter in an analogous way:
route: "transactionDetails/:id/:localtimezone/:reporttimezone",
this way you get something like this:
#/transactionDetails/123/1608260750758/1608260750758
another way is to use query string and not use router params:
route: "transactionDetails",
this way, you get the url: #/transactionDetails?id=123&localtimezone=1608260810884&reporttimezone=1608260810884
a working example is available at
https://codesandbox.io/s/aurelia-router-demo-forked-wyszo?file=/src/app.js:356-384
Regards.
Cristian

Cypress Assertion

I have a question regarding Cypress assertions, just recently start playing with this testing platform, but got stuck when the URL returns a random number as shown below.
/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=SK42f-DZ_iCk2oWE8DVNnr6gAArG277W3X0kGJL1gTZ7W5oQAAV9iC4Zng4mf0BlulglN-10NK&dojo.preventCache=1575947662312
As you can see token is random and dojo.preventCache is also a random string. I want to detect this url and check if deep=true regardless the token number, but I don't know how to achieve this.
cy.location('origin', {timeout: 20000}).should('contain', '/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=**&dojo.preventCache=**');
Anyone any idea?
You can check both the path and query like this (note that cy.location('origin') doesn't yield neither pathname nor query from your original question, so I'm using cy.url()):
cy.url()
.should('contain', '/Geocortex/Essentials/REST/sites/SITE')
.should('contain', 'deep=true');
or check each separately:
cy.location('pathname').should('contain', '/Geocortex/Essentials/REST/sites/SITE');
cy.location('search').should('contain', 'deep=true');
or, use a custom callback in which you do and assert whatever you want:
cy.url().should( url => {
expect(/* do something with url, such as parse it, and access the `deep` prop */)
.to.be.true;
});

Error 400 Your request is invalid in yii if i am creating link

I'm pretty new to Yii, so this might be a silly question. I must be missing something somewhere. Plz help me out.
I have just written a simple code while I'm learning Yii.
I have a spark controller which has an action that looks like this:
public function actionDownload($name){
$filecontent=file_get_contents('images/spark/'.$name);
header("Content-Type: text/plain");
header("Content-disposition: attachment; filename=$name");
header("Pragma: no-cache");
echo $filecontent;
exit;
}
Now I have enabled SEO friendly URLs and echo statement in the view file to display the returned download file name.
But when I go to the URL,
SITE_NAME/index.php/spark/download/db5250efc9a9684ceaa25cacedef81cd.pdf
I get error 400 - your request is invalid.
Plz let me know if I am missing something here.
Yii keeps an eye on the params you pass into an action function. Any params you pass must match what's in $_GET.
So if you're passing $name then you need to make sure there's $_GET['name'] available.
So check your URL manager in /config/main.php, and make sure you're declaring a GET var:
'spark/download/<name:[a-z0-9]+>' => 'site/download', // Setting up $_GET['name']
Otherwise change your function to the correct param variable:
public function actionDownload($anotherName){
}
Did you create the URL correct? You should do it best with
Yii::app()->createUrl('/spark/download',array('name'=>$filename));
Make sure if you are properly supplying the parameter name ($name) in your request.
Use
SITE_NAME/index.php/spark/download/name/db5250efc9a9684ceaa25cacedef81cd.pdf
or
SITE_NAME/index.php/spark/download?name=db5250efc9a9684ceaa25cacedef81cd.pdf
instead of just SITE_NAME/index.php/spark/download/db5250efc9a9684ceaa25cacedef81cd.pdf

How can I access query string parameters for requests I've manually dispatched in Laravel 4?

I'm writing a simple API, and building a simple web application on top of this API.
Because I want to "consume my own API" directly, I first Googled and found this answer on StackOverflow which answers my initial question perfectly: Consuming my own Laravel API
Now, this works great, I'm able to access my API by doing something like:
$request = Request::create('/api/cars/'.$id, 'GET');
$instance = json_decode(Route::dispatch($request)->getContent());
This is great! But, my API also allows you to add an optional fields parameter to the GET query string to specify specific attributes that should be returned, such as this:
http://cars.com/api/cars/1?fields=id,color
Now the way I actually handle this in the API is something along the lines of this:
public function show(Car $car)
{
if(Input::has('fields'))
{
//Here I do some logic and basically return only fields requested
....
...
}
I would assume that I could do something similar as I did with the query string parameter-less approach before, something like this:
$request = Request::create('/api/cars/' . $id . '?fields=id,color', 'GET');
$instance = json_decode(Route::dispatch($request)->getContent());
BUT, it doesn't seem so. Long story short, after stepping through the code it seems that the Request object is correctly created (and it correctly pulls out the fields parameter and assigns id,color to it), and the Route seems to be dispatched OK, but within my API controller itself I do not know how to access the field parameter. Using Input::get('fields') (which is what I use for "normal" requests) returns nothing, and I'm fairly certain that's because the static Input is referencing or scoping to the initial request the came in, NOT the new request I dispatched "manually" from within the app itself.
So, my question is really how should I be doing this? Am I doing something wrong? Ideally I'd like to avoid doing anything ugly or special in my API controller, I'd like to be able to use Input::get for the internally dispatched requests and not have to make a second check , etc.
You are correct in that using Input is actually referencing the current request and not your newly created request. Your input will be available on the request instance itself that you instantiate with Request::create().
If you were using (as you should be) Illuminate\Http\Request to instantiate your request then you can use $request->input('key') or $request->query('key') to get parameters from the query string.
Now, the problem here is that you might not have your Illuminate\Http\Request instance available to you in the route. A solution here (so that you can continue using the Input facade) is to physically replace the input on the current request, then switch it back.
// Store the original input of the request and then replace the input with your request instances input.
$originalInput = Request::input();
Request::replace($request->input());
// Dispatch your request instance with the router.
$response = Route::dispatch($request);
// Replace the input again with the original request input.
Request::replace($originalInput);
This should work (in theory) and you should still be able to use your original request input before and after your internal API request is made.
I was also just facing this issue and thanks to Jason's great answers I was able to make it work.
Just wanted to add that I found out that the Route also needs to be replaced. Otherwise Route::currentRouteName() will return the dispatched route later in the script.
More details to this can be found on my blog post.
I also did some tests for the stacking issue and called internal API methods repeatedly from within each other with this approach. It worked out just fine! All requests and routes have been set correctly.
If you want to invoke an internal API and pass parameters via an array (instead of query string), you can do like this:
$request = Request::create("/api/cars", "GET", array(
"id" => $id,
"fields" => array("id","color")
));
$originalInput = Request::input();//backup original input
Request::replace($request->input());
$car = json_decode(Route::dispatch($request)->getContent());//invoke API
Request::replace($originalInput);//restore orginal input
Ref: Laravel : calling your own API

Passing variables into JavaScript in ExpressJS/PassportJS/Jade app

This is essentially a continuation of the question here: Nodejs Passport display username.
app.get('/hello', function(req, res) {
res.render('index.jade', { name: req.user.username });
});
So users log in via PassportJS, and goes to index.jade, which contains #{name} in the body, which will be replaced by the value of req.user.username.
Question: Is it possible to use the value of req.user.username in index.jade's JavaScript? I tried assigning its value to a variable but it doesn't work.
I have been using the trick of having a hidden input with #{name} as value:
input(type='hidden', id='variableName', value='#{name}')
Then JavaScript can access this value using:
$("#variableName").val()
This works. But does it have any potential downside like security issues? What is the right way to do this?
You have a few options. One of them is what you did and put the value inside you html. You can also solve it by doing:
script
window.name = #{name};
This will create an inline script that sets the variable. The other option you have is using ajax. That means you probably need to make an extra route to reply to that request.