insert row in Azuresqldatabase by using Azure Logic Apps - azure

I am having Azure SQL database and I want to perform Insert,Update,Delete Operations by using Logic Apps
and is it necessary to have a gateway while Connecting to Azure SQL DB to Sqlserver Connector in Logic -app I have Three properties 1)Id 2)Name 3)Department in Azure SqlDB
**When HTTP Request is Received Code:**
{
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"properties": {
"Department": {
"type": "string"
},
"Name": {
"type": "string"
},
"id": {
"type": "integer"
}
},
"type": "object"
}
Http Request is Received
In sql Connector it showing Bad request:
Insert -row Connector
The Body element of properties are null
{ "Department": null, "Name": null, "id": null }
The Output of Insert Row Connector
{
"statusCode": 400,
"headers": {
"Pragma": "no-cache",
"x-ms-request-id": "3332d425-3e10-4f04-b618-63f359168acc",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "false",
"Cache-Control": "no-store, no-cache",
"Date": "Mon, 04 May 2020 08:16:24 GMT",
"Content-Length": "468",
"Content-Type": "application/json",
"Expires": "-1"
},
"body": {
"status": 400,
"message": "Microsoft SQL: Cannot insert the value NULL into column 'id', table '.dbo.Details'; column does not allow nulls. INSERT fails.\r\nclientRequestId: 3332d425-3e10-4f04-b618-63f359168acc",
"error": {
"message": "Microsoft SQL: Cannot insert the value NULL into column 'id', table 'dbo.Details'; column does not allow nulls. INSERT fails."
},
"source": "sql-eus2.azconn-eus2.p.azurewebsites.net"
}
}
Note:I am not using any gate-way please guide me on the above task if you have any resource please let me
know
Logic App-Defination:
Designer
previous error history:
error:
data I am Passing in Payload schema:
enter image description here

The error is occurring because you are running the trigger from the azure portal. See when I run the trigger as shown in the image below,
And I encounter following error
"Microsoft SQL: Cannot insert the value NULL into column 'id', table 'librarymanagement.dbo.DepartmentTable'; column does not allow nulls. INSERT fails."
To properly invoke the HTTP trigger Logic APP, you need to make a HTTP API call to it. If you are just learning, you can use POSTMAN to make the call. Following are the steps you need to do
Copy the Logic APP url from the portal.
Create a new request in postman and select POST method and paste the url copied in step 1. Also paste the body as shown.
Now move to Headers and Set the values as shown below.
Click on Send

Related

new klaviyo node SDK

I'm trying to use Klaviyo for the first time, and the natural starting point seems to be their new Node SDK. Unfortunately, their documentation seems to be an odd combination of extremely detailed, and laking any details.
I've set up my account and gotten my API key, but am failing to get a simple registration to succeed.
I thought I could do this:
import { ConfigWrapper, Profiles } from 'klaviyo-api';
import logger from '../utils/logger';
import requireEnvVariable from '../utils/requireEnvVariable';
export async function subscribe(profile) {
const apiKey = requireEnvVariable('KLAVIYO_PK');
ConfigWrapper(apiKey);
const user = Profiles.createProfile(profile)
.then(data => logger.debug({data}, 'Got profile data'))
.catch(error => {
logger.warn(error, 'Klaviyo error');
return error;
});
return true;
}
For profile, I'm passing in
{
"email": "me#example.com",
"phone_number": "",
"first_name": "Bob",
"last_name": "Smith"
}
but it responds with an error:
WARN: Klaviyo error
env: "development"
err: {
"type": "Error",
"message": "Bad Request",
"status": 400,
"response": {
"req": {
"method": "POST",
"url": "https://a.klaviyo.com/api/profiles/",
"data": {
"email": "me#example.com",
"phone_number": "",
"first_name": "Bob",
"last_name": "Smith"
},
"headers": {
"authorization": "Klaviyo-API-Key <my private key>",
"revision": "2022-10-17",
"user-agent": "klaviyo-api-node/1.0.2",
"content-type": "application/json",
"accept": "application/json"
}
},
"header": {
"date": "Wed, 28 Dec 2022 23:34:14 GMT",
"content-type": "application/vnd.api+json",
"content-length": "211",
"connection": "close",
"cf-ray": "780e1b056c3728f5-ORD",
"allow": "GET, POST, HEAD, OPTIONS",
"vary": "Cookie, Accept-Encoding",
"cf-cache-status": "DYNAMIC",
"cid": "UDiE82",
"ratelimit-limit": "700, 75;w=1, 700;w=60",
"ratelimit-remaining": "699",
"ratelimit-reset": "44",
"x-robots-tag": "noindex, nofollow",
"server": "cloudflare"
},
"status": 400,
"text": "{\"errors\":[{\"id\":\"5648779b-3e1a-4ccf-80c4-dc19b8b32a2c\",\"status\":400,\"code\":\"invalid\",\"title\":\"Invalid input.\",\"detail\":\"The payload provided in the request is invalid.\",\"source\":{\"pointer\":\"/data\"},\"meta\":{}}]}"
}
}
The various examples under Optional Parameters made me think that the above would Just Work; however, the docs also say, "For example values / data types, as well as whether parameters are required/optional, please reference the corresponding API Reference link," and "This SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior."
So looking at the Create Profile API Reference, I tried both
const user = Profiles.createProfile({attributes: profile})
and
const user = Profiles.createProfile({type: 'profile', attributes: profile})
but they both end up with the same error (except the reported data is updated appropriately, e.g.,
"status": 400,
"response": {
"req": {
"method": "POST",
"url": "https://a.klaviyo.com/api/profiles/",
"data": {
"type": "profile",
"attributes": {
"email": "me#example.com",
"phone_number": "",
"first_name": "Bob",
"last_name": "Smith"
}
},
What's the right way to use the new SDK? Or should I ignore this, and go back to creating manual fetch calls against their API?

Unable to update CosmosDB via LogicApps

I am unsure as to why I am constantly facing the following errors when trying to use Logic Apps to update a document in CosmosDB:
PartitionKey extracted from document doesn't match the one specified in the header
One of the specified inputs is invalid
For error 1, I sent the following request via LogicApps:
{
"method": "post",
"headers": {
"x-ms-documentdb-is-upsert": "True",
"x-ms-documentdb-raw-partitionkey": "12347"
},
"path": "/dbs/bc-gamification-management/colls/bcpoints/docs",
"host": {
"connection": {
"name": <omitted as this shouldn't matter>
}
},
"body": {
"curr_point": 500,
"id": "12347",
"overall_point": 1400
}
}
Not too sure where I got this idea but for error 2, I omitted the partition key from the body request:
{
"method": "post",
"headers": {
"x-ms-documentdb-is-upsert": "True",
"x-ms-documentdb-raw-partitionkey": "12347"
},
"path": "/dbs/bc-gamification-management/colls/bcpoints/docs",
"host": {
"connection": {
"name": <omitted as this shouldn't matter>
}
},
"body": {
"curr_point": 500,
"overall_point": 1400
}
}
I have tried troubleshooting this using: https://learn.microsoft.com/en-us/azure/cosmos-db/sql/troubleshoot-bad-request and various other methods like, using "id" and "/id" in the Partition key value instead of the actual value of the partition key. But all these methods did not work and I am not too sure why...
FYI, the CosmosDB has items with the following sample:
{
"id": "12347",
"overall_point": 1200,
"curr_point": 300,
"_rid": <omitted as this shouldn't matter>,
"_self": <omitted as this shouldn't matter>,
"_etag": <omitted as this shouldn't matter>,
"_attachments": <omitted as this shouldn't matter>,
"_ts": <omitted as this shouldn't matter>
}
The "id" field is also the Partition Key for the Collection. Please advice :")
What you need is something like this
{
"method": "post",
"headers": {
"x-ms-documentdb-is-upsert": "True",
"x-ms-documentdb-raw-partitionkey": "\"12347\""
},
"path": "/dbs/testdb/colls/testcoll/docs",
"host": {
"connection": {
"name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
},
"body": {
"curr_point": 500,
"id": "12347",
"overall_point": 1400
}
}
You need to put your partition key within quotes, like this.

Azure Translator API always gives me 404

I'm trying to use translator API through a free trial subscription. After creating it, I set resource groups and add cognitive service to it. On that cognitive service page, I followed the "Quick Start" guide and got a pair of keys and ENDPOINT url.
Then I followed this document. It says an API key and endpoint are needed to use translator API. And I get them from RESOURCE MANAGEMENT>Keys and Endpoint section.
https://learn.microsoft.com/en-gb/azure/cognitive-services/translator/quickstart-translate?pivots=programming-language-javascript
But I always get 404 status code from this API every time I send a request. Is there anything I do wrong? How can I use this API?
SubscriptionID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
My code:
const subscriptionKey = 'my-sub-key'; // There are two keys, key1 and key2. I use key1 here.
const endpoint = 'https://japaneast.api.cognitive.microsoft.com/';
const options = {
method: 'POST',
baseUrl: endpoint,
url: 'translate',
qs: {
'api-version': '3.0',
'to': 'en'
},
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString()
},
body: [{
'text': 'hello world'
}],
json: true,
};
request(options, function (err, resFromMicrosoft, body) {
res.json(resFromMicrosoft);
}
Error response:
{
"statusCode": 404,
"body": {
"error": {
"code": "404",
"message": "Resource not found"
}
},
"headers": {
"content-length": "56",
"content-type": "application/json",
"apim-request-id": "e2ae69cc-b93c-4db2-aef4-47096eb3ec61",
"strict-transport-security": "max-age=31536000; includeSubDomains; preload",
"x-content-type-options": "nosniff",
"date": "Fri, 19 Jun 2020 06:11:24 GMT",
"connection": "close"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "japaneast.api.cognitive.microsoft.com",
"port": null,
"hostname": "japaneast.api.cognitive.microsoft.com",
"hash": null,
"search": "?api-version=3.0&to=en",
"query": "api-version=3.0&to=en",
"pathname": "/translate",
"path": "/translate?api-version=3.0&to=en",
"href": "https://japaneast.api.cognitive.microsoft.com/translate?api-version=3.0&to=en"
},
"method": "POST",
"headers": {
"Ocp-Apim-Subscription-Key": "my-sub-key",
"Content-type": "application/json",
"X-ClientTraceId": "8eedf6f4-db0c-45cb-a95b-92a2797df067",
"accept": "application/json",
"content-length": 83
}
}
}
As mentioned in the documentation, please use the global endpoint - https://api.cognitive.microsofttranslator.com/
I saw your comment about getting 401 after using the global endpoint.
You still need to use the global endpoint as mentioned by Swetha.
This might help https://github.com/MicrosoftDocs/azure-docs/issues/57430#event-3480744006
(From the above page)
"It looks like you are using a common cognitive service resource and a key. Most the services have moved to using an individual resource type and if you can create and use the translator resource the steps mentioned in the documentation should work as is."

How can I create a calendar event on Outlook with Microsoft Graph API?

I have an app that integrates with Office365 and I am attempting to create a calendar event on an Outlook calendar using the Microsoft Graph API. Here is what I have so far:
request.post({
url:'https://graph.microsoft.com/v1.0/me/events',
form: {
"Id": null,
"Subject": "Discuss the Calendar REST API",
"Body": {
"ContentType": "Text",
"Content": "This is some content."
},
"Start": {
"DateTime": "2016-01-24T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"End": {
"DateTime": "2016-01-25T19:00:00",
"TimeZone": "Pacific Standard Time"
},
"ShowAs": "Free",
"IsReminderOn":false
},
headers: {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/json"
}
}, function(err, httpResponse, body) {
if (err) {
console.log('addMicrosoftAccessToken() ERROR = ' + err);
callback(err, false);
} else {
console.log('httpResponse = ' + JSON.stringify(httpResponse));
callback(null, true);
}
})
The problem is that the event isn't saved on the users Outlook calendar. Also, I'm not getting an error in the log. I suspect that I'm not sending the proper form data in the request. Any ideas?
UPDATE: Here is the httpResponse I'm getting in the log:
{
"statusCode": 500,
"body": "{\r\n \"error\": {\r\n \"code\": \"UnknownError\",\r\n \"message\": \"\",\r\n \"innerError\": {\r\n \"request-id\": \"8ebe2efc-649c-4d8d-bee1-be2457cc3a45\",\r\n \"date\": \"2016-01-25T19:05:27\"\r\n }\r\n }\r\n}",
"headers": {
"cache-control": "private",
"transfer-encoding": "chunked",
"content-type": "application/json",
"server": "Microsoft-IIS/8.5",
"request-id": "8ebe2efc-649c-4d8d-bee1-be2457cc3a45",
"client-request-id": "8ebe2efc-649c-4d8d-bee1-be2457cc3a45",
"x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"East US\",\"Slice\":\"SliceB\",\"ScaleUnit\":\"000\",\"Host\":\"AGSFE_IN_4\",\"ADSiteName\":\"EST\"}}",
"outboundduration": "707.5019",
"duration": "713.2419",
"x-powered-by": "ASP.NET",
"date": "Mon, 25 Jan 2016 19:05:27 GMT",
"connection": "close"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "graph.microsoft.com",
"port": 443,
"hostname": "graph.microsoft.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/v1.0/me/events",
"path": "/v1.0/me/events",
"href": "https://graph.microsoft.com/v1.0/me/events"
},
"method": "POST",
"headers": {
"Authorization": "Bearer blah blah",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"content-length": 643
}
}
}
UPDATE 2:
This link is titled "Create Event", and appears to have the response listed in both the request and response sections, making it particularly confusing:
http://graph.microsoft.io/docs/api-reference/v1.0/api/event_post_instances
Also, in the above link where it lists
POST https://graph.microsoft.com/v1.0/me/events/<id>/instances
what is <id>? It doesn't tell me what id is supposed to be?
UPDATE 3: This link is also titled "Create Event", yet it has a different POST URL:
http://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_events
Very confusing.
The reason why your me/events request fails is that you used the Azure Active Directory (AAD) authorization flow for accessing your personal Microsoft Account (Live Id) calendar. AAD allows creating users mapped to Microsoft Accounts such that when requesting an AAD token you're signing in with your Microsoft Account credentials. That way your credentials can be used to access both business (work or school) and consumer (personal) services. While the credentials are shared there are 2 distinct user accounts. When accessing business services like OneDrive for Business or SharePoint you need to sign in with the AAD user account in the context of your work or school organization. When accessing consumer services like Hotmail or OneDrive you need to sing in with the Microsoft Account (Live Id). You request is attempting to access an Outlook account in the context of your organization, which doesn't exist as your email address is already served by a personal Outlook account associated with your Microsoft Account. Please use the converged authorization flow (http://graph.microsoft.io/en-us/docs/authorization/converged_auth) to sign in with your personal Microsoft Account and you'll be able to access your personal email and calendar. Alternatively you can keep using the AAD authorization flow to access work or school calendars for AAD users not mapped to Microsoft Accounts.

Creating a calendar event on windows live REST API

I'm always getting time-outs (60sec) after making a post to create an event.
URL: https://apis.live.net/v5.0/me/events
JSON: {
"id": "",
"name": "Google 3",
"description": "mychild event",
"calendar_id": "calendar.c988c1d9bf3dcf4b.adasdasdeqe3231q23",
"start_time": "2014-04-30T08:30:00-05:00",
"end_time": "2014-04-30T09:30:00-05:00",
"is_all_day_event": false,
"visibility": "public"
}
I pass the access_token on the http headers with the format: Authorization: Bearer + AccessToken.
I've successfully created this very same event using the ISDK.
What I'm doing wrong? Any hint?
Tks,

Resources