new klaviyo node SDK - node.js

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?

Related

How to get full user data in Auth0 using /users API?

Based on this article, https://auth0.com/docs/api/authentication#get-user-info, I am able get user info. The challenge is, instead of getting full user info, I am getting partial info.
I have "scope": "openid profile email" defined in my JWT. How can I retrieve full info? Am I missing something?
Code:
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://YOUR_DOMAIN/userinfo',
'headers': {
'Authorization': 'Bearer {TOKEN}',
'Cookie': 'COOKIE'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Actual Response:
{
"email": "janedoe#exampleco.com",
"email_verified": true,
"name": "Jane Josephine Doe",
"nickname": "JJ",
"picture": "http://exampleco.com/janedoe/me.jpg",
"sub": "248289761001",
"updated_at": "1556845729"
}
Expected Response:
{
"address": {
"country": "us"
},
"birthdate": "1972-03-31",
"email": "janedoe#exampleco.com",
"email_verified": true,
"family_name": "Doe",
"gender": "female",
"given_name": "Jane",
"locale": "en-US",
"middle_name": "Josephine",
"name": "Jane Josephine Doe",
"nickname": "JJ",
"phone_number": "+1 (111) 222-3434",
"phone_number_verified": false,
"picture": "http://exampleco.com/janedoe/me.jpg",
"preferred_username": "j.doe",
"profile": "http://exampleco.com/janedoe",
"sub": "248289761001",
"updated_at": "1556845729",
"website": "http://exampleco.com",
"zoneinfo": "America/Los_Angeles"
}
You can create some Action and call them as you will get all user details inside function.
Login to Auth0 >>> leftside-menu-bar >>> Library >> Action

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.

When I used nodejs sdk to translate file is failed

When I used nodejs sdk to translate file is failed.
I uploaded the ifc file already. And I use nodejs SDK - ForgeSDK.DerivativesApi to translate " ifc " to " svf ". But when I check the job process ,I got " TranslationWorker-InternalFailure " error.
According to the sdk reference(forge sdk for nodejs on github ). My post body is:
{
"input":{
"urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Ym9pbGVyL2JyaWRnZTIuaWZj"
},
"output":{
"formats":[{
"type":"svf",
"views":["2d","3d"]
}]
}
When I used postman to call "https://developer.api.autodesk.com/modelderivative/v2/designdata/{urn}/manifest" api.It response me:
{
"Result": {
"statusCode": 200,
"headers": {
"access-control-allow-credentials": "true",
"access-control-allow-origin": "*",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 06 Mar 2018 09:16:00 GMT",
"x-ads-app-identifier": "platform-viewing-2018.01.02.49.b4217d5-production",
"x-ads-duration": "212 ms",
"x-ads-startup-time": "Mon Feb 26 02:55:52 UTC 2018",
"content-length": "439",
"connection": "Close"
},
"body": {
"type": "manifest",
"hasThumbnail": "false",
"status": "failed",
"progress": "complete",
"region": "US",
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Ym9pbGVyL2JyaWRnZTIuaWZj",
"version": "1.0",
"derivatives": [
{
"name": "bridge2.ifc",
"hasThumbnail": "false",
"status": "failed",
"progress": "complete",
"messages": [
{
"type": "error",
"message": "Unrecoverable exit code from extractor: -1073741829",
"code": "TranslationWorker-InternalFailure"
}
],
"outputType": "svf"
}
]
}
}
But when I used postman to call " https://developer.api.autodesk.com/modelderivative/v2/designdata/job " api
to translate is successed.
what different the api and the sdk?
This is what I'm using to translate using the NPM
var translateFile = function(encodedURN){
logs(chalk.bold.green("**** Translating file derivative"));
var postJob =
{
input: {
urn: encodedURN
},
output: {
formats: [
{
type: "svf",
views: ["2d", "3d"]
}
]
}
};
return new Promise(function(resolve, reject) {
derivativesApi.translate(postJob, {}, oAuth2TwoLegged, oAuth2TwoLegged.getCredentials()).then(
function(res){
resolve(res);
},function(err){
reject(err);
}
)
});
};
And if you want to test it also I have a Node Uploader sample using the NPM calls to do the whole process.
https://github.com/jaimerosales/modelderivative-nodejs-tutorial

Google Street View Publish return's "Photo does not have upload reference." after statusCode 200

I'm using NodeJS to upload panoramic images.
When I make #2 informed in the Google documentation, I get the following return:
Request
{
"url": "UPLOAD_URL",
"body": "/PATH_TO_PANO/pano.jpg",
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "image/jpeg"
}
}
Response
{
"statusCode": 200,
"body": "",
"headers": {
"x-guploader-uploadid": "AEnB2UoJt4gvmmU6gXZvWDRu4b0DUCeT5vuPKLGcZqM4Tzo9HssCLoloTgAACRmxmP0U5DDYvHXpThCjRslW80bEKLZjUjJB3QNZ5w- j0jd8jdtVnH8X0c",
"content-length": "0",
"date": "Tue, 26 Sep 2017 21:05:17 GMT",
"server": "UploadServer",
"content-type": "text/html; charset=UTF-8",
"alt-svc": "quic=\":443\"; ma=2592000; v=\"39,38,37,35\"",
"connection": "close"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "streetviewpublish.googleapis.com",
"port": 443,
"hostname": "streetviewpublish.googleapis.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/media/user/USER_ID/photo/PHOTO_ID",
"path": "/media/user/USER_ID/photo/PHOTO_ID",
"href": "https://streetviewpublish.googleapis.com/media/user/USER_ID/photo/PHOTO_ID"
},
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "image/jpeg",
"content-length": 45
}
}
}
But when I upload the metadata of the photo, I get the following message:
Request
{
"url": "https://streetviewpublish.googleapis.com/v1/photo?key=YOUR_API_KEY",
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
"Content-Length": 9385487
},
"data": {
"uploadReference": {
"uploadUrl": "UPLOAD_URL"
},
"pose": {
"heading": 110,
"latLngPair": {
"latitude": -29.937386,
"longitude": -60.996952
}
},
"captureTime": {
"seconds": 1506448064836
}
}
}
Response
{
"error": {
"code": 400,
"message": "Photo does not have upload reference.",
"status": "INVALID_ARGUMENT"
}
}
There are not many references to basing myself and finding the problem. For that reason I would like the help of someone who may have gone through something similar.
I have replicated your issue. I've encountered this error when I didn't specify the UPLOAD_URL in the request.
{
"error": {
"code": 400,
"message": "Photo upload url does not match required format.",
"status": "INVALID_ARGUMENT",
"details": [
{
...
}
]
}
}
Make sure that you have added the UPLOAD_URL in the request. Check this documentation for more information.

box.com node client - cannot access files created by collaborator

I'm the co-owner on a box.com file.
My boss is the owner.
I'm using https://www.npmjs.com/package/box-node-sdk to manage the files
The node client has my bosses' enterprise credentials
He made a folder
I made several other sibling folders
I can retreive his
I can't retreive mine
We're both listed as collaborators on all the files
The error I get looks like this:
{
"statusCode": 404,
"response": {
"statusCode": 404,
"body": {
"type": "error",
"status": 404,
"code": "not_found",
"context_info": {
"errors": [
{
"reason": "invalid_parameter",
"name": "item",
"message": "Invalid value 'd_11786923812'. 'item' with value 'd_11786923812' not found"
}
]
},
"help_url": "http://developers.box.com/docs/#errors",
"message": "Not Found",
"request_id": "338009555580a32f872f7c"
},
"headers": {
"server": "ATS",
"date": "Fri, 21 Oct 2016 15:23:36 GMT",
"content-type": "application/json",
"content-length": "324",
"cache-control": "no-cache, no-store",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"vary": "Accept-Encoding",
"age": "0",
"connection": "keep-alive"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.box.com",
"port": 443,
"hostname": "api.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/2.0/folders/11786923812",
"path": "/2.0/folders/11786923812",
"href": "https://api.box.com/2.0/folders/11786923812"
},
"method": "GET",
"headers": {
"User-Agent": "Box Node.js SDK v1.1.0",
"Authorization": "[REMOVED BY SDK]",
"accept": "application/json"
}
}
}
}
EDIT: So, I can get folder 0 and it's not where I'm looking BUT, I did check earlier and added a file where I thought I was looking and it did show up, so I'm guessing that my boss would have to create the files...

Resources