excel webservice http header - excel

I am wondering if there is a way to include http header in excel WEBSERVICE function.
I am trying to use an API witch need a Authorization: Bearer ACCESS_TOKEN :
curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer ac004670-8f66-340a-b4d0-312b585d8cb3' 'https://api.insee.fr/metadonnees/V1/codes/nafr2/sousClasse/84.11Z'

Related

API gateway POST passing fields and throwing error

I have an API Gateway for a POST request which calls a lambda function.
When I test the Lambda function, it works
When I test the endpoint in the API Gateway, it works.
However, When I call the function via a CURL request or via a website, I get the following error:
{"message": "Could not parse request body into json: Could not parse payload into json: Unrecognized token \'eyJtZXNzYWdlIjoiSSBsaWtlIGdpcmxzIGJ1dCBoYXZlIGEgd2lmZSBzbyBuZWVkIHRvIGJlIGRpc2NyZWV0LiBwcy4gSSBoYXZlIGEgYmlnIGNvY2sgOnAifQ\':
was expecting (JSON String, Number, Array, Object or token \'null\', \'true\' or \'false\')\n at [Source: (byte[])\"eyJtZXNzYWdlIjoiSSBsaWtlIGdpcmxzIGJ1dCBoYXZlIGEgd2lmZSBzbyBuZWVkIHRvIGJlIGRpc2NyZWV0LiBwcy4gSSBoYXZlIGEgYmlnIGNvY2sgOnAifQ==\"; line: 1, column: 124]"}%
When receiving that error, the call never makes it to my lambda function. So something in the API Gateway is blocking my request.
My CURL request looks like
curl -i --location --request POST 'https://example.com/staging/transform' 'Content-Type: application/json' --data-raw '{"message":"test"}'
What could be the culprit here?
You need to specify 'Content-Type: application/json' as header with -H option.
curl -i --location -H 'Content-Type: application/json' --request POST 'https://example.com/staging/transform' --data-raw '{"message":"test"}'

How to use azure translator with authorization token?

I want to use azure translator service with the Authorization token. There are plenty of resources explaining how to do it with subscription key but I could not found any resource explaining the use of authorization token. I can get the authorization token but when I send a request with it, the response status code is 401.
This is how I send the request:
curl POST 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer token' \
--data-raw '[{'\''Text'\'':'\''Hello World!'\''}]'
If you want to call Text Translation API with authentication token, please refer to the following steps
Get a token. If your service is global, the endpoint is https://api.cognitive.microsoft.com/sts/v1.0/issueToken
curl -v -X POST \
"https://YOUR-REGION.api.cognitive.microsoft.com/sts/v1.0/issueToken" \
-H "Content-type: application/x-www-form-urlencoded" \
-H "Content-length: 0" \
-H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY"
Besides, please note that an authentication token is valid for 10 minutes. The token should be reused when making multiple calls to the Translator. However, if your program makes requests to the Translator over an extended period of time, then your program must request a new access token at regular intervals (for example, every 8 minutes).
Call API
curl -X POST 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=de' \
-H 'Authorization: Bearer YOUR_AUTH_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '[{ "text": "How much for the cup of coffee?" }]' | json_pp
For more details, please refer to here and here.

Azure API retrieving SAS policy, error InvalidHostName

I am trying to create an Event Hub in Azure using the REST APi ( with Postman ) but I am getting an error in the process of generating the SAS token.
curl --location --request POST 'https://login.microsoftonline.com/0e3603bd-2f0b-43e2-b9b5-5d456791cf33/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=myclientid' \
--data-urlencode 'client_secret=myclientsecret' \
--data-urlencode 'resource=https://management.azure.com/'
I store the bearer token and use it to authentificate on the following requeste:
First create the Event Hub namespace :
'''
curl --location --request PUT 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi?api-version=2017-04-01' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer mybearertoken' \
--data-raw '{"location":"francecentral"}'
'''
Now in order to create the Event Hub, I need to build a SAS token,therefore I need to retrieve the SAS policy first:
The creation of the Namespace generate a SAS policy named RootManageSharedAccessKey, I can list all the policy using this call :
curl --location --request GET 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi/AuthorizationRules?api-version=2017-04-01' \
--header 'Authorization: Bearer mybearertoken'
Lastly, I am trying to retrieve the RootManageSharedAccessKey policy but I am getting an error
{
"error": {
"code": "InvalidHostName",
"message": "The provided host name 'easypeasybi.servicebus.windows.net' is not whitelisted. "
}
}
The code I am using is the following
curl --location --request POST 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi/AuthorizationRules/RootManageSharedAccessKey/listKeys?api-version=2017-04-01' \
--header 'Content-Type: application/atom+xml;type=entry;charset=utf-8' \
--header 'Host: easypeasybi.servicebus.windows.net' \
--header 'Authorization: Bearer mybearertoken' \
--data-raw '<entry xmlns='\''http://www.w3.org/2005/Atom'\''>
<content type='\''application/xml'\''>
<EventHubDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
</EventHubDescription>
</content>
</entry> '
In the header, the Host should be management.azure.com.
So in you command, change this line of code
--header 'Host: easypeasybi.servicebus.windows.net' \
to
--header 'Host: management.azure.com' \

Value of resource when subscribing to webhook notifications using graph api

I am trying to subscribe to the Microsoft Graph API for webhook notifications to track changes in a folder in a SharePoint Document library. I have app only access to this SharePoint site and am able to see and download all the content within the drive associate with the document library. I can also upload new files using API.
When I make the call to the subscription endpoint I receive an internal server error.
Here is the request I make
curl -X POST \
https://graph.microsoft.com/v1.0/drive/root/subscriptions \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Bearer TOKEN' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 303' \
-H 'Content-Type: application/json' \
-H 'Host: graph.microsoft.com' \
-d '{
"changeType": "updated",
"notificationUrl": "https://c.ngrok.io/sp-hook",
"resource": "drives/{{DRIVE-ID}}/root",
"expirationDateTime": "2019-09-18T11:23:00.000",
"clientState": "test"
}'
Here is the response I get
{
"error": {
"code": "InternalServerError",
"message": "Unable to find target address",
"innerError": {
"request-id": "c8e66e50-5b94-4593-88d5-3111e5c5c6c7",
"date": "2019-09-13T09:50:12"
}
}
}
I believe this could be due to a wrong resource value, but I could not locate documentation about what the value of resource should be. I have gone over: https://learn.microsoft.com/en-us/graph/webhooks and https://learn.microsoft.com/en-us/graph/api/resources/webhooks?view=graph-rest-1.0. All the documentation seems to point to a resource value of "me/drives/root", however with app only access a my site is not defined and so the call fails.
These are the different values for resource that I have tried within the request json body
drives('DRIVE-ID')/root
drives/DRIVE-ID/root
DRIVE-ID
drive/DRIVE-ID
drive/DRIVE-ID/root
me/drive("DRIVE-ID")/root
DRIVE-ITEM-ID-FOR-ROOT
Different documentation seems to point to different subscription endpoints. These are the different endpoints I have tried
https://graph.microsoft.com/v1.0/subscriptions
https://graph.microsoft.com/v1.0/drive/root/subscriptions
https://graph.microsoft.com/beta/drives/{{drive-id}}/root/subscriptions
The error also made me suspect that during subscription registration, it was not able to find my webhook. However having tested the endpoint I am sure it is accessible.
Additional information
I use the following call to get the drive id for a sharepoint site
curl -X GET \
'https://graph.microsoft.com/v1.0/sites/SITE-ID/drive' \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Bearer TOKEN' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Host: graph.microsoft.com' \
I see you are performing POST on https://graph.microsoft.com/v1.0/drive/root/subscriptions endpoint
Expected subscriptions endpoint is https://graph.microsoft.com/v1.0/subscriptions
Please note there is no '/drive/root' in the URL path.

Not receiving push notification with encrypted payload

I've been following the document over in this resource to get Push-Notifications sending to a browser with a payload. (Chrome 53.0.2785.116 m).
I'm using the Nodejs Crypto library to generate the keys and they all pass the verification test created by the folks at Google.
I can send and receive a Push-Notification when I do not include the encrypted payload. As soon as I attach the 'raw_data' tag with the encrypted payload the browser no longer receives the Push-Notification (although Curl still comes back with a 'success(1)' response)
Below is the Curl message with and without the payload.
Without Payload -
curl --header "TTL:86400"
--header "Authorization: key=API_KEY"
--header "Encryption: salt=E2oUmcFWbb41wk5DuTbuoA"
--header "Crypto-Key: dh=SERVER_PUBLIC_KEY"
--header "Content-Encoding: aesgcm"
--header "Content-Type: application/json"
https://android.googleapis.com/gcm/send -d
"{\"registration_ids\":[\"CLIENT_KEY\"],\"content_available\":true}"
--insecure
With Payload -
curl --header "TTL:86400"
--header "Authorization: key=API_KEY"
--header "Encryption: salt=E2oUmcFWbb41wk5DuTbuoA"
--header "Crypto-Key: dh=SERVER_PUBLIC_KEY"
--header "Content-Encoding: aesgcm"
--header "Content-Type: application/json"
https://android.googleapis.com/gcm/send -d
"{\"registration_ids\":[\"CLIENT_KEY\"],\"raw_data\":\"UnGSxqxfy9yDwPgCVeXJibQyPX8Hz28\",\"content_available\":true}"
--insecure
Both return a success message
{"multicast_id":9197002368280649941,
"success":1,"failure":0,
"canonical_ids":0,
"results":[{"message_id":"0:1474618927798802%bc86b90cf9fd7ecd"}]}
but the latter is not received by the browser.
We're now into the fourth day of head scratching. Any help would be great.

Resources