Getting Message "Failed to generate sample value: generated sample is too big" when clicked on Test tab of the API on Azure APIM Portal - azure-api-management

When we visit azure portal->APIM, and browse an API and then try to use the Test tab where we can test various operations under the API, the sample request is not generated and instead we get Failed to generate sample value: generated sample is too big. This is happening for some APIs. Not sure what is the limit or which limit it is breaking.
This also replicates when tried from Developer Portal.
Browse Azure Portal
Go to API Management Service
Select APIs section
Select an API
Select Test tab
Click on the Operation
Expectation was to see Request body with valid sample request
But we get "Failed to generate sample value: generated sample is too big." in the Request body. This is happening only for selected APIs not for all.
Need to understand what is the limit? I have validated that its not an UI client issue i.e. this message comes from server itself when providing the operation details.

The APIM service has a maximum Sample size limit and it is 200kb, and if the sample is larger than this limit, the APIM service will return this error. "Failed to generate sample value: generated sample is too big" in this case you would need to create sample by your own.

Related

Google Data Studio Community Connector: Passing Token Through Embed URL Not Working

I'm struggling to get a community connector to work for a web-app I'm building.
I wrote a very basic connector in App Script to do row level filtering on an embedded dashboard, using these docs Google provides: https://developers.google.com/datastudio/solution/viewers-cred-with-3p-credentials
My connector uses getConfig() and getData() to pass a token into an API endpoint, and that API endpoint returns data specific to that user.
The connector works perfectly when I pass in a token in the GUI by modifying the configuration, but doesn't work when I try to pass in the token using the embedded url.
Example 1
User Token = 5wKu4QLvc9PC7tkPyg
Steps:
Click "Edit connection"
Enter token in input field [which is generated by getConfig() in app script]
Click "Reconnect"
Click "Apply" on dialogue box that comes up
Google Data Studio correctly retrieves 3 rows of data for this token
Example 2
User Token = z6ps6Vhb9hzB333gG4
Steps:
Click "Edit connection"
Enter token in input field [which is generated by getConfig() in app script]
Click "Reconnect"
Click "Apply" on dialogue box that comes up
Google Data Studio correctly retrieves 1 row of data for this token
The primary issue
When I use the embed URL for the dashboard, I noticed the App Script execution logs aren't showing that getConfig or getData operations are being run.
The end result is the token doesn't appear to be passed into the embed URL at all. The data remains the same as in the GUI-based report.
However I can tell the embed URL is being invoked, because it does call getAuthType in the App Script execution logs, see image below. (I made the change in the GUI at 9:50:59 PM, and then the subsequent timestamps are me attempting to hit the embed URL)
Sample
Here's the sample of the actual embed URL I'm using:
https://datastudio.google.com/embed/reporting/9dea8b8a-5b51-4add-adb2-afda3861b241/page/VXkvC?config=%22%7B%5C%22token%5C%22:%20%5C%22z6ps6Vhb9hzB333gG4%5C%E2%80%9D%7D%E2%80%9D
Per the Example 2 above, the token being used in this embed URL should only return 1 row of data, but it's returning all 3.
I followed the Google docs, which suggest this is the format to use: https://datastudio.google.com/embed/reporting/[report_id_here]/page/[page_id_here]?config="{\"token\": \"[token_here]\”}”
I'm wondering if it's possible the Google docs are incorrect (or) out of date and my embed url is malformed? I can't get my head around this issue.
Resolution
Despite being part of the getConfig(), apparently you also have to "Add a Parameter" for the token to your Data Source on the report. This will result in the parameter being visible under all fields.
Next, go to Resource > "Manage report url parameters" and check the box for "Allow to be modified in report URL". Take note of the "Name" field. Mine was ds0.token
Finally, use this URL syntax: https://datastudio.google.com/embed/reporting/[report_id_here]/page/[page_id_here]?params=%7B"[name_from_step_2]":"[value]"%7D
Which for me translated into:
https://datastudio.google.com/embed/reporting/9dea8b8a-5b51-4add-adb2-afda3861b241/page/VXkvC?params=%7B"ds0.token":"12345"%7D
Which in raw URL format looks like:
https://datastudio.google.com/embed/reporting/9dea8b8a-5b51-4add-adb2-afda3861b241/page/VXkvC?params=%7B"ds0.token":"12345"%7D
One additional observation. I was watching the logs on my API endpoint, and I noticed Google caches any data it brings back from the endpoint. So don't be surprised if you don't see a getData() call in your App Script execution logs for any tokens you've already passed. Just make up a new token to see a new getData execution log.

Azure APIM URL without API and Operation

I want to serve a request by APIM policy only, is it required to have API and operation for the same ?
for example
https://myapim/myapi/myoperation
I will serve this request from policy itself by calling few external APIs, do i need to create myapi API and myopration as blank operation ? or is there anyway to handle this ? currently i am getting 404 from APIM before reaching to policy code.
When you create api in APIM, it will ask you to input your backend url like below screenshot.
And then when you create operation, if you input /myoperation/ into the "URL" box like below:
It will request https://your-backend-url/myoperation in the backend, but your backend url is https://your-backend-url. So you may get 404 error. To solve this problem, you can just input / into the "URL" box when you create operation.
I had to create a dummy operation in my API by this my policy is getting executed and serving the request.

How to upload application to Cloud Foundry using API (not CLI)?

I'm trying to develop a simple NodeJS web app that can more or less replace the Cloud Foundry (CF) CLI. I'm following the API documentation to send the application.zip to the CF Service, however I get an error response Unsupported Media Type.
For the application part of the body I'm sending the application.zip file that is uploaded from the browser.
For the resources part of the body I'm sending an empty Json array. My understanding is that as there is nothing uploaded initially there are no pre-uploaded resources that I want to specify, hence the array is empty.
With the Unsupported Media Type response, I suspect you send invalid request headers to the API. There is a CloudFoundry API client written in node.js and you may read the source code to see how they upload the app code.
If that does not help you, please refine your question and add some code that you have.

gmail API : Cannot access the list of messages I requested

So what I'm trying to do is to fetch data from gmail API using unix's shell (curl).
I simply copied this from the json generator to be able to play with the json when I used with curl.
GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages?
maxResults=5&includeSpamTrash=false&key={YOUR_API_KEY}
Then I changed the API_KEY by what I was able to generate in my developer console. However, I cannot get the desired json when I put the link in my browser, or curl it in my shell. How do I generate the right key? Because I already generated from all of the choices in the Credentials.
Thanks!
What you generate in the Console is the Client ID and Client secret, which are used when you redirect your users to Google. Upon accepting, Google then redirects the user to the url you specify in the console with a code. This code is then finally used to retrieve the Access Token which you should use as {YOUR_API_KEY}.
Go to Google OAuth 2.0 Playground, and use the Gmail API v1 scopes, and retrieve the access token and use it in your shell.

Access data from an actual API service in protractor tests

I am writing end-to-end tests using Protractor for an Angular application. The application uses an API service to retrieve data from the back-end and this data is then used to populate pages in the Angular application.
I would like to utilize this API to get data to use in my jasmine tests, the tests will confirm that the back-end data is correctly and completely populated on applicable pages in the UI. I definitely DO NOT want to mock the server, I want to hit the actual server and work with the actual data from the JSON response.
My question is 2 sided; how to call the API service from my protractor tests and secondly, how to retrieve data from the JSON response from this API.
Any (detailed) information, examples you can provide as to how this can be done would be appreciated
Thanks in advance.
Protractor is used to test the ui of an application. What it does is click buttons and enter text in text boxes and wait for responses. For example if I have a login form and want to test the scenario when a user enters an email address wrong and an error message pops up. Protractor would navigate to the email field, enter an incorrect email address and then find the element that contains the error and verify the error showed up.
So as long as you have an environment setup that has a ui connected to an API service, the API service will be called as normal. Protractor will click buttons and if a button click triggers a call to the API service it will go straight to that service.
As for the JSON response access, this is probably not a good use for protractor. Protractor is used to click events and wait for responses. So if you are displaying that JSON response in some form or way protractor could verify it is displayed. For example, if you are displaying some data from the server in a table on a button click, you could have protractor click that button and verify the table has the correct values. But you would not want to verify the JSON object is as expected. That would be unit-tests on the API itself.
Hope this helps.
We have two options
Make a request by require(...) and using a request library.
This allows you to make direct HTTP Service calls, as discussed in this Stack Overflow post
Use some data from a .json file by require(...) it directly:
https://github.com/angular/protractor/issues/978#issuecomment-47250364