How supply default values in calling a remote endpoint - bixby

I am an amateur programmer and cannot figure this out based on the documentation and examples provided.
Based on their sample capsule on https://bixbydevelopers.com/dev/docs/sample-capsules/samples/http, they directly called
var response = http.getUrl(config.get('remote.url') + '/shoes', options);
They do have documentation on what http.getUrl parameters are but no examples on how it should be formatted syntax-wise.
I also don't know what would be the point of creating an endpoints.bxb for API calls file if they don't use it and just call it manually in the .js file.
Any help is greatly appreciated!

The base method signature for http.getUrl is http.getUrl(url, options) where the url variable is a String and the options variable is a JSON object containing any or all of the following keys:
format: Output format.
query: Object containing unencoded keys and values for URL query string.
cacheTime: Cache time in milliseconds.
basicAuth: Basic Authentication; value must be an object with username and password.
You can learn more by exploring the documentation's http section here.
Regarding the http sample you referenced: It shows multiple ways to reach the same outcome. The endpoints.bxb file has the two following action-endpoints:
A local endpoint where the GET is handled by the Javascript file:
action-endpoint (FindShoe) {
accepted-inputs ()
local-endpoint (FindShoe.js)
}
A remote endpoint where the GET is defined within the endopoints.bxb file itself and doesn't require a Javascript file.
action-endpoint (FindShoeRemoteEndpoint) {
accepted-inputs ()
remote-endpoint ("{remote.url}/shoes") {
method (GET)
}
}

Related

What is this structure coming from a fetch that returns a octet-stream?

I'm tring to retrieve a list of files from an API using axios, in Node.js. What I get is what I assume is an ArrayBuffer string. I'm using the following code:
axios.get('http://api.com/filesList').then(response => {
console.log(response.data);
});
This is what I get (changed numbers and letters a bit to hide potential priv info):
$97cceb28↕$sad28sdj-askd-3294-3jh9→--Account_123456789 �����0*$97cceb282¶2022-11-30.csv"�☺
$97cceb28↕$sad28sdj-askd-3294-3jh9→--Account_123456789 ���0*$97cceb282¶2022-11-26.csv"�☺
$97cceb28↕$sad28sdj-askd-3294-3jh9→--Account_123456789 �໑�0*$97cceb282¶2022-11-19.csv"�☺
I know for a fact that I'm supposed to receive certain information for each file of this list, at least which account is associated to them and their name. I did a little digging and added responseType: 'arraybuffer' to the function and then it output a <Buffer 22 be 01...> kind of response. I then tried a method to convert it to a string but I end up getting the result I had without setting the response type.
So, what kind of string data is this and how do I convert it to an object/JSON? Is there a way to decode this structure?
Thank you all in advance.

Body is not getting parsed in GET method

I am using mockoon for API simulation. I created 2 routes there with method GET and its body contains(responds with) JSON object. I noticed that my express app is not able to parse one of the routes. But the route that has JSON object in body which contains ARRAY is getting parsed. I tested both routes with Express(by console.log) and in chrome browser(I have JSON formatter extension) and it is behaving the same meaning response that does not contain ARRAY is not getting parsed but the response with array is getting parsed(behaving normally). Let me show the screenshots:
Express(by console.log):
With array:
Without array:
Chrome(JSON Formatter extension):
With array(extension is able to parse):
Without array(extension is not able to parse):
I tried adding Header(Content-Type: application/json) to the route in mockoon. But still, I am not aware of what is going on here. Someone please explain
The express code:
const iabs_client = await axios.get(
"http://localhost:3001/iabs-client
);
Here is the route created in Mockoon(without array inside JSON):
P.S mockoon is a program that creates endpoints in localhost, useful for API simulation when developing front-end without having backend yet
The trailing comma after "something" is not valid JSON. Edit your Mockoon body to remove the comma and it should work.

DocuSign API Javascript SDK - getDocument returns string

I am trying to call the api endpoint getDocument via Node, and am expecting a Buffer to be returned, however, it is returning a string. Even when I pass in different values for the encoding optional parameter, the data returned is always the same.
When I tested the same endpoint in C#, a MemoryStream is returned which is expected.
My code is as follows:
const document = await envelopesApi.getDocument(accountId, envelopeId, '1')
Where 1 is the documentId (page 1).
The contents of document looks like %PDF-1.5\n%ûüýþ\n%Writing objects... and so on
I am then trying to save this to a file:
fs.writeFileSync('test.pdf', Buffer.from(documentContent))
With no success. How do I get the api response and save it to a file for viewing?
Yes, this is correct, you will have to use the correct mime type for PDF (in this case) in order to show this file in the browser.
You can find a node.JS code example that shows you how to do this.
But the most important part in your case would be this line:
mimetype = "application/pdf";

tsoa-swagger: file parameter is always undefined in upload

I have a problem with Tsoa nodejs File upload
I wrote the method based on the tsoa documentation but the output varible is always undefined
This is my method
#Post('/uploadNewExporterTemplate')
public async uploadNewExporterTemplate(
#Query() templateName: string,
#Query() unit: string,
#Query() testWith: string,
#UploadedFile() file: Express.Multer.File,
) {
const mul = multer()
console.log(file,unit,testWith);
return {stat:"Ok",ss:templateName}
}
And this is the swagger result
and finally this the debug result
I'm not sure why but according to provided screenshot of Swagger UI, your file field is in Request body section, but the rest of the fields are in Parameters section. As far as I know, all fields should be in one section called Request body or Parameters.
I suggest you try changing Query() to FormField() accordingly to tsoa docs.
If above does not help, I have a few suggestions:
Check what's inside generated routes file. There should be some multer logic added by tsoa.
Compare your generated swagger.json with the one provided in the Swagger example.
Try running the request outside Swagger UI (e.g.: Postman) or use DevTools to check what is Swagger UI does under the hood (Network tab, check the requests).

Podio file attached to item cannot be downloaded

I have an issue trying to download files attached to Podio items:
podio.request('get', '/file/{file_id}/raw').then(console.log);
The above program displays:
{}
This is a JSON stringified empty object (instead of raw file content).
Details:
The above file can be accessed with its URL when logged in
The above code is run after proper authentication
It actually works when using a file_id from an image field of the item, but not from a file attachment (pdf files in my case).
When using API endpoint /item/app/{app_id}/filter to get a list of items, the property file_count is set, but not files. I have to request /item/{item_id} individually to get the files property included in the response, not sure why.
Question: Do you know what is the issue, and how I can download raw attached files?
EDIT: aditionnal info
If I request a single file metadata using the folowing command:
podio.request('get', '/file/1234').then(console.log);
I get a file JSON object which includes many fields, but not the file content :
{
...
link: 'https://files.podio.com/1234',
file_id: 1234,
...
}
As stated in my comment to #stengaard, if I try to request the API for the above link, here is the response :
{ [PodioNotFoundError: [object Object]]
message:
{ error_parameters: {},
error_detail: null,
error_propagate: false,
request:
{ url: 'http://api.podio.com/1234',
query_string: '',
method: 'GET' },
error_description: 'No matching operation could be found. The path \'/1234\' was not found..',
error: 'not_found' },
status: 404,
url: 'https://api.podio.com:443/1234',
name: 'PodioNotFoundError' }
To use the GET /file/{file_id}/raw endpoint you need an API key with elevated trust levels.
Instead use GET /file/{file_id} endpoint. That contains a link attribute (a URL) you should follow to get the file content.
The link attribute will look like: https://files.podio.com/{file_id}. To fetch the file do https://files.podio.com/{file_id}?oauth_token={oauth_token}. Where the OAuth token is the same as the one used to GET /file/{file_id}. If you know the file ID (e.g. from a GET /item/{item_id} you can skip the GET /file/{file_id} and contact files.podio.com directly. (Note: You can also set the Authorization: OAuth2 {oauth_token} header in your HTTP request if you don't like passing the auth token in a URL paramter.)
For an example on how to use it see https://github.com/podio/podio-js/blob/master/lib/general.js#L11
Typically in the JS client, if you use podio as your Podio API object, the OAuth token would be located there:
podio.authObject.accessToken
So to get the raw content of the file in nodejs:
var url = 'https://files.podio.com/'+file_id+'?oauth_token='+podio.authObject.accessToken;
request(url, function (err, fileContent) {
// use fileContent here, write to a file, etc...
});
It seems your request has an error.
please try the below method and get raw file content from its response.
podio.request('get', '/file/{file_id}').then(console.log);
FYI, we couldn't get the files by filtering the items. we need to request /item/{item_id} individually to get the files property as you said.

Resources