adobe / aio-lib-target Goto Github PK
View Code? Open in Web Editor NEWAdobe I/O Javascript SDK wrapping Adobe Target 1.0 APIs
Home Page: https://www.adobe.io
License: Apache License 2.0
Adobe I/O Javascript SDK wrapping Adobe Target 1.0 APIs
Home Page: https://www.adobe.io
License: Apache License 2.0
Error for GET calls - ' Request with GET/HEAD method cannot have body'
This is because of swagger client update to 3.10.2
Three steps:
npm install --save-dev openapi-schema-validator
Target SDK or Target API allow you to update Target A/B activities, including ones that have auto-allocate.
Unable to update Target A/B activities with SDK or API.
// Get and update single activity
const response = await targetClient.getABActivityById(395705);
const body = response.body;
await targetClient.updateABActivity(395705, body);
throws this error
[TargetSDK:ERROR_UPDATE_AB_ACTIVITY] Error: Conflict
at _callee$ (C:\Git\TargetAPI\node_modules\swagger-client\dist\index.js:623:816)
at tryCatch (C:\Git\TargetAPI\node_modules\regenerator-runtime\runtime.js:63:40)
at Generator.invoke [as _invoke] (C:\Git\TargetAPI\node_modules\regenerator-runtime\runtime.js:293:22)
at Generator.next (C:\Git\TargetAPI\node_modules\regenerator-runtime\runtime.js:118:21)
at asyncGeneratorStep (C:\Git\TargetAPI\node_modules\@babel\runtime-corejs2\helpers\asyncToGenerator.js:5:24)
at _next (C:\Git\TargetAPI\node_modules\@babel\runtime-corejs2\helpers\asyncToGenerator.js:27:9)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
status: 409,
statusCode: 409,
response: [Object]
}
In Postman, with this request https://mc.adobe.io/{{tenant}}/target/activities/ab/395705
that was given to me by your Postman collection from the documentation (no modifications made besides filling in variables), with body being the exact response from the corresponding Get request for ab activity, gives this error
{
"httpStatus": 409,
"requestId": "YqYAZftfoxjPU3F1ZKJHsGyPuzK2NAJo",
"requestTime": "2021-04-16T19:47:29.076182Z",
"errors": [
{
"errorCode": "VersionConflict.Resource",
"message": "Cannot create/update auto-allocate activity with this version of API"
}
]
}
SDK
"@adobe/aio-lib-target": "^2.1.1"
API
application/vnd.adobe.target.v3+json
Node.js
v14.15.4
Here's the whole Node.js file reproducing it:
const sdk = require('@adobe/aio-lib-target');
(async () => {
const client = await sdk.init('tenant', 'key', 'token');
try {
// Get single and update activity
const response = await client.getABActivityById(395705);
const body = response.body;
await client.updateABActivity(395705, body);
} catch(e) {
console.log(e.message);
}
})();
βοΈ Important announcement: Greenkeeper will be saying goodbye π and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io
9.3.1
to 9.4.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
fetch-mock is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 10 commits.
3cdc7ba
fixed broken tests
b1f33ec
fix linting
87a2758
Merge pull request #532 from chet-manley/feat-return-node-fetch-interface
d7a6577
feat: mock node-fetch's export pattern
3500688
Merge pull request #526 from pabloosso/patch-1
8c231ac
Fixed typo
e25f30a
Merge pull request #525 from willheslam/patch-1
5817bbf
Fix typo in mock_response.md
41b238f
Update cheatsheet.md
aa8311e
Update cheatsheet.md
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
23.1.0
to 23.1.1
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 2 commits.
6ffb998
chore(release): 23.1.1 [skip ci]
d03bcf4
fix(no-focused-tests): detect table format uage of .only.each
(#489)
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
While we are working on Adobe IO to get/update the offer in Adobe Target through Adobe IO Target library
When calling getOfferById() function, the following error occurred:
we are getting the below errors.
[TargetSDK: ERROR_GET_OFFER_BY_ID] Error: Not Acceptable
Can be easily reproduced in the following steps
Download the zip file and keep the js file in a folder. (see attached targetInit.zip)
targetInit.zip
You will need to replace the access token to a valid access token in the targetInit.js file, the problem can be reproduced with any Target company with json offers in the Offer library.
Open a command prompt in the folder the targetInit.js file exists. Run the below command.
npm install @adobe/aio-lib-target
Post that run the below command.
node targetInit.js
Replicate the issue with the above steps.
We are trying to give solution using Adobe IO serverless architecture to update the Target Activity/Offers through Adobe IO Target library.
Node.js latest version
see targetInit.js
const offer = await targetClient.getOfferById(offerID)
It seems the root cause is the get Offer Content call. which fails with a 406.
curl --location --request GET 'https://mc.adobe.io/tatadigital/target/offers/content/458563'
--header 'Authorization: Bearer '
--header 'x-api-key: '
Returns
{
"httpStatus": 406,
"requestId": "KsYtjLDzfFsvvcG9DiYAmPMibqnHEC3I",
"requestTime": "2021-06-11T00:12:22.634272Z",
"errors": [
{
"errorCode": "Unsupported.Feature",
"message": "Unsupported offer type. The only supported type is: content",
"meta": {}
}
]
}
All the offers returned when listing the offers are of Type = json
Changing the URL above to https://mc.adobe.io/tatadigital/target/offers/json/458563'
returns
{
"id": 458563,
"name": "/birthday_offers/experiences/0/pages/0/zones/0/1623150537848",
"content":
{ "ShowOffers": "true", "count": "5" }
,
"modifiedAt": "2021-06-08T12:26:30Z"
}
The JAVAScript code needs to examine the type of the offer and make the appropriate backend API call.
The Swagger spec seems to have support for content but not for a variable to take the type.
There seems to be a discrepancy in the SDK function targetClient.getOfferById(offersArray[i].id) call in that, it also needs type to construct the correct URL to fetch the offer.
Workaround is to maybe call the adobe.io rest API directly, since that works fine as mentioned above.
Permalink
shete
Aditi Shete added a comment - 6 days ago - edited
Withe the token and api key provided for tatadigital, with Accepts set to application/vnd.adobe.target.v2+json
I was able to run the adobe.io call successfully to get offers.
curl -X GET
'https://mc.adobe.io/tatadigital/target/offers?limit=10'
-H 'authorization: Bearer '
-H 'cache-control: no-cache'
*-H 'Accept: application/vnd.adobe.target.v2+json' *
-H 'x-api-key: '
Please investigate the the node.js side code which uses the Swagger client to make the above call (which seems to be succeeding with the apikey and token provided.)
Right now it is 98%
npm audit issue: https://github.com/swagger-api/swagger-js/releases/tag/v3.13.5
Using Node 14
Given the following code:
const aiolibtarget = require('@adobe/aio-lib-target')
console.log('Hi')
The following result should be produced:
Hi
Using Node 14
Given the following code:
const aiolibtarget = require('@adobe/aio-lib-target')
console.log('Hi')
The following result is produced:
/Users/mgoberling/repos/adobe/my-utils/utils/api-mesh-test/node_modules/@swagger-api/apidom-error/cjs/ApiDOMAggregateError.cjs:7
class ApiDOMAggregateError extends AggregateError {
^
ReferenceError: AggregateError is not defined
at Object.<anonymous> (/Users/mgoberling/repos/adobe/my-utils/utils/api-mesh-test/node_modules/@swagger-api/apidom-error/cjs/ApiDOMAggregateError.cjs:7:36)
at Module._compile (internal/modules/cjs/loader.js:1114:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:979:32)
at Function.Module._load (internal/modules/cjs/loader.js:819:12)
at Module.require (internal/modules/cjs/loader.js:1003:19)
at require (internal/modules/cjs/helpers.js:107:18)
at Object.<anonymous> (/Users/mgoberling/repos/adobe/my-utils/utils/api-mesh-test/node_modules/@swagger-api/apidom-error/cjs/ApiDOMError.cjs:8:52)
at Module._compile (internal/modules/cjs/loader.js:1114:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
Node 14.21.3
Build badges etc, as required via the internal wiki checklist
βοΈ Important announcement: Greenkeeper will be saying goodbye π and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io
9.1.0
to 9.1.1
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
fetch-mock is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Target API Calls that use the v3 Accept-header ('Accept: application/vnd.adobe.target.v3+json')
should be successful.
When I try to call getABActivityById
from my code, I get this error:
[TargetSDK:ERROR_GET_AB_ACTIVITY_BY_ID] Error: Conflict
at _callee$ (/Users/alexandraanton/_DATA/GIT_Repos/ADOBE-IO-TOOLS/node_modules/swagger-client/dist/index.js:581:816)
at tryCatch (/Users/alexandraanton/_DATA/GIT_Repos/ADOBE-IO-TOOLS/node_modules/regenerator-runtime/runtime.js:45:40)
at Generator.invoke [as _invoke] (/Users/alexandraanton/_DATA/GIT_Repos/ADOBE-IO-TOOLS/node_modules/regenerator-runtime/runtime.js:271:22)
at Generator.prototype.<computed> [as next] (/Users/alexandraanton/_DATA/GIT_Repos/ADOBE-IO-TOOLS/node_modules/regenerator-runtime/runtime.js:97:21)
at asyncGeneratorStep (/Users/alexandraanton/_DATA/GIT_Repos/ADOBE-IO-TOOLS/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator.js:5:24)
at _next (/Users/alexandraanton/_DATA/GIT_Repos/ADOBE-IO-TOOLS/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator.js:27:9)
at processTicksAndRejections (internal/process/task_queues.js:94:5) {
status: 409,
statusCode: 409,
response: [Object]
}
I have code that leverages the adobe-io-target lib, and that makes calls to getActivities
, getABActivityById
, getXTActivityById
as well as update activity API calls.
I have tried to fix the issue by changing the code to make another request intercept and add the necessary Accept headers. After this, it works. I am attaching the modified code here
index.js.zip
to give you an idea. Please have a look at getActivities, getABActivityById and getXTActivityById.
If the solution seems acceptable to you, I can create a PR to cover all API calls, otherwise please have a look and let me know your opinion.
Current version
const exportActivity = (activity) => {
return targetApi.initApi().then((sdk) => {
if (activity.type === 'abt') {
console.warn(chalk.red("Skipping activity"), activity)
return Promise.resolve(() => { })
}
if (activity.type === 'ab') {
return sdk.getABActivityById(activity.id);
}
if (activity.type === 'xt') {
return sdk.getXTActivityById(activity.id);
}
})
}
Update package.json as well, to be under the @adobe namespace.
I don't believe this has been published to npm, so we don't have to npm deprecate.
You need to add the .github directory and include the pull request, issue template and contributing files. You can get them from our starter-repo.
Using the sample code:
const activities = await targetClient.getActivities({limit:5, offset:0})
I always get 0 results:
{ total: 0, offset: 0, limit: 5 }
File .github/workflows/node.js.yml. See https://github.com/adobe/aio-cli-plugin-app/blob/5670908e7ef7ba63c903ee924520eeb018a9e448/.github/workflows/node.js.yml#L32-L36
API calls from the AIO Target SDK shall work as expected when used in Firefly Apps.
API calls like getOffers, getActivities are consistently sending Internal Server Error (HTTP 500) when invoked from Firefly Apps.
AIO JS SDK for Target in Firefly Apps.
// Here's the default invocation code generated from Firefly:
const { Target } = require('@adobe/aio-sdk')
const targetClient = await Target.init(params.tenant, params.apiKey, token)
const offers = await targetClient.getOffers({limit:5, offset:0})
const activities = await targetClient.getActivities({ limit: 5, offset: 0 })
error: [TargetSDK:ERROR_GET_ACTIVITIES] Error: Internal Server Error
error: [TargetSDK:ERROR_GET_OFFERS] Error: Internal Server Error
We've been seeing some issues raised here that's actually attributed to a permission issue in Admin Console. We should add this to our docs, likely in an FAQ session, as part of the doc to enable users to self-help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.