I've got this great API for filling pdfs that's called pdfotter, I'm looking for someone who used this API before and maybe found a way to fill in a signature in the form.
The signature part is very important and can not be replaced with a simple string for legal reasons.
My request looks like this:
let form = {
signature: fs.createReadStream('1.png'),
date: new Date().toLocaleDateString('en-gb'), // default
};
request
.post('https://www.pdfotter.com/api/v1/pdf_templates/.../fill')
.form({
data: {
...form
},
})
.auth('...', '')
.pipe(fs.createWriteStream('result.pdf'));
The result in the signature looks like this:
#ActionController::Paramet ers:0x0000000674cf60>
Any suggestions are welcome!
I am not familiar with this PDFotter service, but anyway I see that your request is formed incorrectly: form.signature field is not filled with a suitable value, because you set a stream there.
signature: fs.createReadStream('1.png') <- this will not work in any way.
Try to replace signature with some valid value, for example a string Michael Ionov.
let form = {
signature: `Michael Ionov`,
date: new Date().toLocaleDateString('en-gb'), // default
};
I understand that you probably need to paste an image there, but firstly check if it works with 100% valid value.
There is no information on pdfotter web site about sending images, but if you are sure they support it - you will need to try pass to signature raw image data using for example fs.readFileSync('img.png'), or Base64 encoded image:
signature: new Buffer(fs.readFileSync('img.png').toString('base64');
So the API providers answered me and there is actually a nice way to do it but is not yet documented, all I needed to do is to prepend 'image:' to the signature field and also prepend it on the form itself in their, and send the image as a base64 string.
'image:signature': fs.readFileSync('signature.png').toString('base64')
Happy hacking!
Related
I am very new to javascript .. and my teacher provided us with this piece of code along with html and css file which on any date you enter gives you images of mars taken from ISS..
Would anyone care to explain what is happening inside the data: {} and how to get such API URL'S? I mean from where do we get that?
var input_box=$('#div-date input');
var button=$('#div-button button');
var container2=$('#container2');
button.click(function()
{
$.ajax({
method: "GET",
url: "https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos",
data:
{
earth_date:parseInt(input_box.val().split('/')[2]).toString()+"-
"+parseInt(input_box.val().split('/')[1]).toString()+"-
"+parseInt(input_box.val().split('/')[0]).toString(),
api_key:"zrVafsMHD8r1SC8mHyg91mnNguuzdIoPRXGD1BvS"
},
The ajax method is a call to NASA endpoint where you are doing a GET call to the URL. I thinks this is clear.
Now, what does data?
earth_date is a value with the actual date parsed to a specific format. It get the date from the input_box with format 00/00/0000 and parse to format 0000-00-00
api_key is the key you need to authenticate and get the data.
And data itself is the way to send variables into URL. So, your url looks like this:
https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?earth_date=YOUR_DATE&api_key=YOUR_API_KEY
Note that is compound by:
url+ ?earth_date + api_key.
Updated to answer the question:
The API key is a way to secure the API.
An API key is a way to identify who is calling the endpoint. So only calls that have the API key will be able to reach the endpoint (or whatever the developer want).
Is an string generated by the owner so the only way to get the API key is NASA to give it to you. I suppose NASA give free API keys, but is not a "general string" or something like that. Every organization will secure their apis in a way, NASA provide api keys to reach his 'free' endpoints.
The code in the data transform the date format '30/12/2019' to '2019-12-30' since only the later format is valid for the request.
I've created a SAPUI5 table widget and made sure that it works. Now, when clicking on a row, the detail view is loaded, but no data is present. The server exposes an entity Site with a primary key which is of type "string".
The client-side code is as follows (assume that oModel is ODataModel, sSiteCode is a string that may contain Cyrillic characters):
// sSiteCode may contain Cyrillic characters
var oKey = {
SiteCode: sSiteCode
};
var sPath = "/" + oModel.createKey("Sites", oKey);
this.getView().bindElement({path: sPath});
It turns out that, if sSiteCode = 'б' (i.e., contains Cyrillic characters), then a GET request will be sent (via batching) to the following URI:
http://<server>:<port>/odata/Sites('б')
However, the server is unable to parse this URI (and subsequently replies with a 404), as it doesn't know what encoding to use. I patched the method ODataModel.prototype._createRequestUrl as follows:
sNormalizedPath = this._normalizePath(sPath, oContext);
sNormalizedPath = encodeURI(sNormalizedPath); // my addition
Then it seems to work, for this particular case. I'm wondering if this is a bug or a feature, and what should I do next?
FYI, I'm using OpenUI5 1.32.11.
Instead of sending
http://<server>:<port>/odata/Sites('б')
The actual string sending to the server should be
http://<server>:<port>/odata/Sites(%27б%27)
Which is the result of the encodeURI() call. Since UI5 allows you to freely define the Models URL and its parameters you have to take care on the correct URI encoding (and all parameters).
So in my opinion this is not a bug but the down part of the possibility to configure the URI without "black-box" behaviour of UI5.
I'm working on a school project where I'm trying to make a search function for The New York Times Article Search API.
I have a problem with one of their search filters as when I run the function I get error 400 as for some reason it can't read the url encoding. The fun thing is if I replace all the %3D's with = and the %26's with & in my own URL it works and I can see the API responds correctly.
if($('#date1').is(':checked')) {date="day_of_week&begin_date=18500101&end_date=19000101";}
if($('#date2').is(':checked')) {date="day_of_week&begin_date=19000101&end_date=19500101";}
if($('#date3').is(':checked')) {date="day_of_week&begin_date=19500101&end_date=20000101";}
if($('#date4').is(':checked')) {date="day_of_week&begin_date=20000101&end_date=20150101";}
$.getJSON('http://api.nytimes.com/svc/search/v2/articlesearch.json',
{'api-key': 'XXXXXXXXXXXXXXXXXXXXXXX',
'fq': 'headline:("'+sogestreng.toLowerCase()+'")'+" AND "+finalSections,
'facet_field': date},
This code returns "http://api.nytimes.com/svc/search/v2/articlesearch.json?api-key=XXXXXXXXXXXXXXXXXXXXXXX&fq=headline%3A(%22dubai%22)+AND+section_name.contains%3A(%22Sports%2C+%22)&facet_field=day_of_week%26begin_date%3D20000101%26end_date%3D20150101"
While if I manually replace the last part of the url encoding and open it in my browser I get the result I'm looking for.
I do this by changing:
"&facet_field=day_of_week%26begin_date%3D20000101%26end_date%3D20150101"
to
"&facet_field=day_of_week&begin_date=20000101&end_date=20150101"
Also to clarify, the "fq" criteria works perfectly fine, it's just the facet_field.
How can this be? And is there any fix for it?
You're shoving the description of several fields into one field's value. To get the results you want, try:
var begin_date, end_date;
if($('#date1').is(':checked')) {
begin_date = 18500101;
end_date = 19000101;
}
else if($('#date2').is(':checked')) {
// etc.
}
$.getJSON('http://api.nytimes.com/svc/search/v2/articlesearch.json',
{
'api-key': 'XXXXXXXXXXXXXXXXXXXXXXX',
'fq': 'headline:("'+sogestreng.toLowerCase()+'")'+" AND "+finalSections,
'facet_field': 'day_of_week',
'begin_date': begin_date,
'end_date': end_date
},
// ...
I am using django-jsignature in my django project. After making the post request, the form returns "type 'instance'". I'm trying to save this as an image, but I get the above error.
Even better would be to save the form data as a vector image as suggested in the docs.
My function:
def signature(request):
form = SignatureForm(request.POST or None)
if form.is_valid():
signature = form.cleaned_data.get('signature')
if signature:
# as an image
signature_picture = draw_signature(signature)
signature_file_path = draw_signature(signature, as_file=True)
with open(signature_file_path), 'wb') as f:
f.write(signature_picture)
(signature_file_path == '/tmp/tmpB71Wft.PNG')
I think the docs are a bit unclear, but you should be using either draw_signature(data, as_file=False) (default) OR draw_signature(data, as_file=True), no need for both.
Passing a True value to as_file makes the package dump the image content to a file, while False makes it return the PIL.Image instance.
The raw data is still available in your signature variable (as JSON string or list, so you could also use that vector directly.
Can draw_signature() take one or two arguments? Your code has it taking one argument in one location, and a two arguments in a second location.
I found several sources discussing this problem, (this one seems the simplest but it is for PHP). I will be using an existing search form and I created AutocompleteResponse handler to handle the request. I don't understand from the documentation if it is required that the data sent will be in json format or an array of string is ok. I am not sure about what information to send either. I created a new model with search history
class Search(db.Model):
owner = db.UserProperty()
date= db.DateTimeProperty(auto_now_add=True)
query = db.StringListProperty()
and I want to send the relevant query suggestions to autocomplete. Any help to examples whether in documentation or otherwise is welcome. Thanks.
Update
I put this just before the closing </body>
<script>
$('#search_form').autocomplete({
source: "http://ting-1.appspot.com/autocomp",
minLength: 2});
</script>
in my Autocomp handler I put
data = json.dumps("abc, def")
I naively think that data will be passed to jquery autocomplete plug in. But nothing is happenning. What am I doing wrong?
Just tried this and it worked:
data = ['cat','dog','bird', 'wolf']
data = json.dumps(data)
self.response.out.write(data)