Google sheets Exception : Invalid Argument - json

I am trying to access the number of posts and followers using graph API . Everything went on well untill I tried getting the results into google sheets using importjson. I got an error claiming **invalid argument **. Here is the code :
ImportJSON("https://graph.facebook.com/v15.0/135341411526765381?fields=business_discovery.username(mugisha1){followers_count,media_count,media}&access_token="&Access_Token) . NB: The page ID is fake for protection purposes.
I am expecting something like this in my excell google docs :
{
"business_discovery": {
"followers_count": 164,
"media_count": 331,
"id": "1782599754053691"
},
"id": "17841436556633433"
}

Related

Azure Data Factory - REST API Call Pagination

I'm making a call for data in Data Factory and struggling to call the url in the "next_page" item.
This is an example of what the first API call returns:
{
"items": [
{
"title_one": "TTL-55924",
"id": "CPT-TTL-64577_TTL-55924",
"title_id": "TTL-64577"
},
{
"title_one": "TTL-69015",
"id": "CPT-TTL-79755_TTL-69015",
"title_id": "TTL-79755"
}
],
"next_page": "http://api.com/api/info?offset=5000&key=XXXxxxXXXxxx"
}
I'm not sure which options to use in the Pagination Rules of my Copy activity.
Currently I'm trying the option "AbsoluteURL" with the value "$['next_page']" but this just returns an error.
If your API response contains the next page URL property, then the “AbsoluteUrl“ pagination rule is the correct option to load the next page in the Azure data factory.
The supported values for pagination rules are mentioned in this MS document.
As mentioned in the example from the above document, Facebook Graph API returns the response as,
{
"data": [
…
…
],
"paging": {
…
…
},
"previous": "https://graph.facebook.com/me/albums?limit=25&before=NDMyNzQyODI3OTQw",
"next": "https://graph.facebook.com/me/albums?limit=25&after=MTAxNTExOTQ1MjAwNzI5NDE="
}
}
Note: Pagination value of a JSON path expression starts with “$”.
Your pagination in REST copy activity looks like this:
In your API, the pagination should look like
I have a similar issue. I am trying to copy shopify data from the rest API and was able to get the 1st page of data, however i cannot figure out how to set the pagination. THe pagination is coming in the header response like this:
I have it set to this but this returns an error:
ADF ERROR:
Failure happened on 'Source' side. ErrorCode=RestSourceCallFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The HttpStatusCode 404 indicates failure.
Request URL: https://joyfolie.myshopify.com/admin/api/2021-07/%3Chttps://joyfolie.myshopify.com/admin/api/2021-07/products.json?limit=50&page_info=eyJsYXN0X2lkIjo0NjI0ODcyMjEwNDkwLCJsYXN0X3ZhbHVlIjoiKk5FVyogQmFlIFNraXJ0IGluIE9jaHJlIiwiZGlyZWN0aW9uIjoibmV4dCJ9%3E;%20rel=%22next%22
Response payload:{"errors":"Not Found"},Source=Microsoft.DataTransfer.ClientLibrary,'
Source
Pipeline
Copy Shopify Products
THis is how the link looks in the response header
https://joyfolie.myshopify.com/admin/api/2022-01/products.json?limit=50&page_info=eyJsYXN0X2lkIjo0NjI0ODcyMjEwNDkwLCJsYXN0X3ZhbHVlIjoiKk5FVyogQmFlIFNraXJ0IGluIE9jaHJlIiwiZGlyZWN0aW9uIjoibmV4dCJ9; rel="next"

Why is Google Apps Script giving me this UrlFetchApp script code 429?

I have been having a strange error that I have been going in circles trying to figure out.
I decided to learn some JavaScript/google apps script to parse some information from an api of a game I play. I followed a bunch of tutorials and searched google and Stack Overflow for solutions but none have worked. I think I've narrowed it down to one particular Method: the "UrlFetchApp."
Right now I'm simply trying to grab some JSON data from the API and display it in the log window.
I keep getting this:
[21-09-13 09:01:40:770 EDT] Exception: Request failed for https://api.guildwars2.com returned code 429. Truncated server response: {"text":"too many requests"} (use muteHttpExceptions option to examine full response)
at getRequest(Untitled:4:30)
Now here's the strange part, I ran the script from my phone at work to test some theories out and got this:
[21-09-13 09:02:20:943 EDT] {
"name": "Abomination Hammer",
"type": "Weapon",
"level": 0,
"rarity": "Fine",
"vendor_value": 0,
"default_skin": 5014,
"game_types": [
"Activity",
"Wvw",
"Dungeon",
"Pve"
],
"flags": [
"NoSell",
"SoulbindOnAcquire",
"SoulBindOnUse"
],
"restrictions": [],
"id": 15,
"chat_link": "[&AgEPAAAA]",
"icon": "https://render.guildwars2.com/file/E8507FFB6CF3C9094A69956344CEDBD9B47D95B6/434872.png",
"details": {
"type": "Hammer",
"damage_type": "Physical",
"min_power": 146,
"max_power": 165,
"defense": 0,
"infusion_slots": [],
"attribute_adjustment": 20.736,
"infix_upgrade": {
"id": 112,
"attributes": []
},
"secondary_suffix_item_id": ""
}
}
I doubt it's the code now.
That is what was supposed to be returned. It's the same code unedited and ran multiple times on both my phone and computer and the results are always the same.
Here's the line of code I wrote:
function getRequest() {
var response = UrlFetchApp.fetch('https://api.guildwars2.com/v2/items/15');
Logger.log(response)
}
Can anyone help? I'm really frustrated now.
Response status code 429 shows when a user sent too many requests in a given amount of time. Based on the documentation of Rate Limiting in Guild Wars the rate limit is tracked per-IP and the maximum request per minute is 600.
In your script, you can confirm the rate limit by printing the header by using response.getAllHeaders() or response.getHeaders() and you will see x-rate-limit-limit=600.
X-Rate-Limit-Limit is the maximum number of requests that may be
issued within a minute. This is a static value doesn’t contain count
for requests you have already sent.
Usually, 429 status code includes Retry-After header. This indicates how long a user must wait before making a new request. You can also view this by printing the header.
If the Retry-After is not included in the headers, you can follow Elchanan shuky Shukrun comment above to use VPN since the rate limit is tracked per IP. You can also use the Guild Wars forum and create a post for a possible bug.
Reference:
429 Too Many Requests
Retry-Limit

ADF V2 - Web POST method using Dynamic Content and Variable

Very short version
How do I include an ADF Variable inside a JSON POST request, in a Web Activity within ADF?
I feel like this should be a very simple string concatenation, but i can't get it to work
Detail
We have a requirement to run a query / SProc from within ADF, which will return a string containing an error message. That string is to then be passed via the Web Activity in ADF to a Logic App, in order to fire off an email, containing the error.
The setup of the logic app is copied from here:
https://www.mssqltips.com/sqlservertip/5718/azure-data-factory-pipeline-email-notification--part-1/
and then here (part 2)
https://www.mssqltips.com/sqlservertip/5962/send-notifications-from-an-azure-data-factory-pipeline--part-2/
In ADF, I used the Lookup activity, to run a query, which brings back the error (appears to work, the preview returns the correct string)
Then I use the Set Variable activity, to take the output of the lookup and store it in a variable.
Last Step is to fire off the POST using the Web Activity.
With this code (tweaked slightly to remove personal details) in my Web Activity, everything works fine and I receive an email
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "Pipeline finished!",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
But any attempt to put the contents of the Variable into the Subject part has failed.
This (for example) sends me an email with the subject literally being #variables('EmailSubject')
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#variables('EmailSubject')",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
But I've also attempted various other solutions that result in errors or the email subject just containing the literal thing that I put in there (e.g. + #variables('EmailSubject') +).
I also tried storing the entire JSON in the Variable, and then having the Web activity use only the variable, that returned no errors, but also did not send an email.
This attempt:
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#{variables('EmailSubject')}",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
Resulted in this input into the web activity - which actually includes the text of the error, which is a bonus ... (text = Job Duration Warning):
{
"url": "https://azureLogicAppsSiteHere",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": "{\n \"DataFactoryName\": \"DFNAMEHERE\",\n \"PipelineName\": \"pipeline1\",\n \"Subject\": \"{\"firstRow\":{\"\":\"Job Duration Warning\"},\"effectiveIntegrationRuntime\":\"DefaultIntegrationRuntime (West Europe)\",\"billingReference\":{\"activityType\":\"PipelineActivity\",\"billableDuration\":[{\"meterType\":\"AzureIR\",\"duration\":0.016666666666666666,\"unit\":\"DIUHours\"}]},\"durationInQueue\":{\"integrationRuntimeQueue\":0}}\",\n \"ErrorMessage\": \"Everything is okey-dokey!\",\n \"EmailTo\": \"me#myEmail.com\"\n}\t"
}
But then resulted in this error:
{
"errorCode": "2108",
"message": "{\"error\":{\"code\":\"InvalidRequestContent\",\"message\":\"The request content is not valid and could not be deserialized: 'After parsing a value an unexpected character was encountered: f. Path 'Subject', line 4, position 17.'.\"}}",
"failureType": "UserError",
"target": "Web1",
"details": []
}
[Edit] The PREVIEW from the Lookup Activity is the text: Job Duration Warning BUT when I debug the pipeline, it lets me see the actual Output, which is this:
{
"count": 1,
"value": [
{
"": "Job Duration Warning"
}
],
"effectiveIntegrationRuntime": "DefaultIntegrationRuntime (West Europe)",
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "DIUHours"
}
]
},
"durationInQueue": {
"integrationRuntimeQueue": 0
}
}
So it appears that the problem is that the Lookup Output isn't what I thought it was, so the variable can't be used in the Web Activity, as it contains unsupported characters or something along those lines.
I just tested this and it worked ok:
Create a String Parameter with the value Job Duration Warning
Set the Variable value to be #pipeline().parameters.ParamSubject
Include the variable in the web activity with an # in front of it
I then receive my expected email with the right subject. I just don't know how to get the string output of my query, into a variable / parameter, so that i can use it in the web activity.
I don't know how well this applies to other people's issues, but I found a solution that has worked for me.
In the SELECT query within the Lookup Activity - name the output (in my case, I called that column 'Subject'- i.e. SELECT xyz AS Subject
In the Lookup Activity, turn on the setting 'First Row Only'
In the Set Variable Activity, use the code: #activity('Lookup1').output.firstRow.subject
(where 'Lookup1' is the name of your Lookup Activity and Subject is the name of the column you are outputting)
In the Web Activity, reference the variable as follows:
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#{variables('EmailSubject')}",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}

Update autoscaler api call returns 404

I am trying to update my Google Compute Engine instance group using API explorer here: https://cloud.google.com/compute/docs/reference/latest/autoscalers/update?authuser=2
I want to update min and max num of replicas using this API. The body part has
{
"autoscalingPolicy": {
"minNumReplicas": 2,
"maxNumReplicas": 5,
"coolDownPeriodSec": 60,
"cpuUtilization": {
"utilizationTarget": 1.5
}
}
}
This gives error below:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "The resource 'projects/<my-proj-name>/zones/us-central1-a/autoscalers' was not found"
}
],
"code": 404,
"message": "The resource 'projects/<my-proj-name>/zones/us-central1-a/autoscalers' was not found"
}
}
I confirmed the autoscaler configuration for the managed instance group by clicking the tiny "Equivalent REST" link at bottom of instance group landing page.
Is there I am missing to get it working on API explorer?
Got this sorted by trying different parameters in body part.
Looks like "name" and "target" are mandatory fields to be provided under autoscaling policy. Without these, the api could not process the request and returns error.
working body formation for me:
{
"autoscalingPolicy": {
"coolDownPeriodSec": 60,
"maxNumReplicas": 2,
"minNumReplicas": 1
},
"name": "<my-autoscaler-name>",
"target": "https://www.googleapis.com/compute/v1/projects/<my-project-name>/zones/us-central1-a/instanceGroupManagers/<my-instancegroup-name>"
}
Note: that the target and name values are picked from the page that shows up by clicking the tiny "Equivalent REST" link at bottom of instance group landing page. As an observation, both strings are same for new instance groups in my case.

ChatFuel - Google Drive - Get file content using GET method via URL

I am developing a Fuel chatbot that gets file's content from Google drive to build gallery.
I am using JSON API (Fuel chatbot) to get the JSON response.
My file in drive: https://drive.google.com/file/d/0Bx79Tkj95Q3iNmVHOFN0Q3BITE0/view
I want to get JSON response like:
{
"messages": [
{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Classic White T-Shirt",
"image_url":"http://petersapparel.parseapp.com/img/item100-thumb.png",
"subtitle":"Soft white cotton t-shirt is back in style",
"buttons":[
{
"type":"web_url",
"url":"https://petersapparel.parseapp.com/view_item?item_id=100",
"title":"View Item"
},
{
"type":"web_url",
"url":"https://petersapparel.parseapp.com/buy_item?item_id=100",
"title":"Buy Item"
}
]
},
{
"title":"Classic Grey T-Shirt",
"image_url":"http://petersapparel.parseapp.com/img/item101-thumb.png",
"subtitle":"Soft gray cotton t-shirt is back in style",
"buttons":[
{
"type":"web_url",
"url":"https://petersapparel.parseapp.com/view_item?item_id=101",
"title":"View Item"
},
{
"type":"web_url",
"url":"https://petersapparel.parseapp.com/buy_item?item_id=101",
"title":"Buy Item"
}
]
}
]
}
}
}
]
}
I tried to get the content of the file by URL:
https://www.googleapis.com/drive/v3/files/0Bx79Tkj95Q3iNmVHOFN0Q3BITE0/export?mimeType=application/vnd.google-apps.file
But I got the response
Do you have any suggestion to get the JSON response ?
Consider this documentation and test again.
Your error is:
403: Daily Limit Exceeded
The Courtesy API limit for your project has been reached.
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceeded",
"message": "Daily Limit Exceeded"
}
],
"code": 403,
"message": "Daily Limit Exceeded"
}
}
Suggested action: Request additional quota.
Based from the SO post, you may do the following to get rid of your error.
Create a Google APIs Console project
On the Services pane, enable all of the APIs that your project requires.
On the API Access pane, click Create an OAuth 2.0 client ID. A dialog opens. Fill in your project's information. Click
Next
Choose the appropriate application type. Based on the tags you used for this post, I am guessing this is an iOS project so select
Installed application.
Enter your bundle ID. You don't need to enter an App Store ID until your app is listed there.
Click Create Client ID.
You will see the client ID and client secret values. You will use
these values to enable communication with your project and the Google
APIs.
If you aren't already using it, see the Google+ iOS SDK and
documentation for a full walk through. The task called "write
moments" is similar in implementation and demonstrates how to connect
to and use the Google+ REST APIs from within an iOS project that uses
the SDK.
You'll need to specify the scope of plus.me to get the profile
information.
Hope this helps.