Xero CIS Contact Settings - xero-api

How do I create the CISSettings in a Contact via the API?
I tried using the endpoint :
POST https://api.xero.com/api.xro/2.0/Contacts/xero-contact-id/CISSettings
{
"CISSettings": [
{
"CISEnabled": true,
"Rate": 20.0
}
]
}
where xero-contact-id is the Xero ID
for an existing contact, but it return a validation error - Name cannot be blank

Related

Shopify cartDiscountCodesUpdate storefront API cartid

I want to apply discount coupon code to the cart page, I am trying to use the storefront API cartDiscountCodesUpdate which expect the cart id. How can I get this cart id. Here is what I tried. I have created the webhook cart/create which has payload id in the form of string something like '1eef2aa2c2b2e889ec325db72f0877ec'.
Then I tried calling this id which I got from cart/create response in storefront API cartDiscountCodesUpdate like:
mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]) {
cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
cart {
id
}
userErrors {
field
message
}
}
}
Query Varialbe:
{
"cartId": "gid://shopify/Cart/1eef2aa2c2b2e889ec325db72f0877ec",
"discountCodes": [
"64J1ZQMBN9W5"
]
}
But its response with below error. I think its the issue with incorrect cart id. Can anyone help me how to get cart id after the cart is created?
Response from cartDiscountCodesUpdate storefront API.
{
"data": {
"cartDiscountCodesUpdate": {
"cart": null,
"userErrors": [
{
"field": [
"cartId"
],
"message": "The specified cart does not exist."
}
]
}
}
}

Expose metafields to the Storefront API error

I want to expose the product metafields in shopify to my Storefront API.
I am referring to following documentation. https://help.shopify.com/en/api/guides/metafields/storefront-api-metafields
Following is the content of my body
mutation($input: MetafieldStorefrontVisibilityInput!) {
metafieldStorefrontVisibilityCreate( input: $input ) {
metafieldStorefrontVisibility {
id
}
userErrors {
field message
}
}
}
Following are the GRAPHQL VARIABLES
{
"input": {
"namespace": "global",
"key": "description_tag",
"ownerType": "PRODUCT"
}
}
Following is the URL
https://posdev07.myshopify.com/admin/api/2019-07/graphql.json
I get following error when I make the request.
{"errors":{"query":"Required parameter missing or invalid"}}

How to make a relationship of data from user pool to aws appsync model

I am new to amplify and appsync. I am trying to create a Post model that needs to have a relationship of the user who is creating the Post. The problem is my user is from cognito user pool.
What I want is the user from cognito I don't want to create new user table on dynamo db because cognito user pool already has its information I just want to get the user info that is creating that Post if I query the post.
How should I create a relationship of this?
I create amlify api like this
? Please select from one of the below mentioned services: GraphQL
? Choose the default authorization type for the API API key
? Enter a description for the API key:
? After how many days from now the API key should expire (1-365): 7
? Do you want to configure advanced settings for the GraphQL API Yes, I want to make some additional changes.
? Configure additional auth types? Yes
? Choose the additional authorization types you want to configure for the API Amazon Cognito User Pool
Cognito UserPool configuration
Use a Cognito user pool configured as a part of this project.
? Configure conflict detection? No
Here is my current schema.grapql
type Post
#model
#versioned
#aws_cognito_user_pools
#auth(rules: [{ allow: owner, queries: null }, { allow: public }]) {
id: ID!
title: String!
content: String
thumb: String
slug: String!
allow_comments: Boolean
owner: String!
post_type: String!
add_to_nav: Boolean!
version: Int!
comments: [Comment] #connection(name: "PostComments")
}
type Comment
#model
#versioned
#aws_cognito_user_pools
#auth(rules: [{ allow: owner, queries: null }]) {
id: ID!
content: String
version: Int!
post: Post #connection(name: "PostComments")
}
====================================================
EDIT: Added result of data that I want
Here is the query that I want to perform
query ListPost {
listPosts {
items {
title
content
owner{
username
id
email
first_name
last_name
}
}
}
}
}
Result that I want
{
"data": {
"listPosts": {
"items": [
{
"title": "title 1"
"content": "Test long text cotent"
"owner": {
"username": "user1"
"id": "234234234"
"email": "user1#test.com"
"first_name": "John"
"last_name": "Doe"
}
},
{
"title": "title 1"
"content": "Test long text cotent"
"owner": {
"username": "user1"
"id": "234234234"
"email": "user1#test.com"
"first_name": "John"
"last_name": "Doe"
}
},
]
}
}
}
I can't find any documentation how to build something like this.
This should help for anyone else that is looking into doing this:
https://docs.amplify.aws/cli-legacy/graphql-transformer/function/#usage
Scroll to:
Example: Get the logged in user from Amazon Cognito User Pools

Has the google oauth API response changed for email scope? The type of email has changed from 'account' to 'ACCOUNT'

We are using google login in our website and spring social library to implement oAuth 2. After getting accessToken , with scope as userInfo.email, we are trying to retrieve accountEmail. spring-social-google(version 1.0.0) is looking for key "account" in the emails property of the reponse. Below is code block from spring-social-sources org.springframework.social.google.api.plus.Person.class
public String getAccountEmail() {
if (emails != null) {
for (Entry<String, String> entry : emails.entrySet()) {
if (entry.getValue().equals("account")) {
return entry.getKey();
}
}
}
return null;
}
From Oct 27, google is responding with email map as "ACCOUNT" instead of "account"
Expert from logs before 27th - getEmails :: {xxxxxxx#gmail.com=account}
Expert from logs after 27th - getEmails :: {xxxxxxx#gmail.com=ACCOUNT}
I could not find any documentmentation from google regarding the change or reponse format. When i use API playground, i can see the type is coming as 'ACCOUNT'.
"image": {
"url": "....photo.jpg",
"isDefault": true },
"etag": "xxx",
"id": "xxx",
"kind": "plus#person",
"emails": [
{
"type": "ACCOUNT",
"value": "xxxx#gmail.com"
}
]
}
I just wanted to check if any one else faced the issue or if anyone has a documentation from google, which explains why the change happened.

Cognito custom claims missing with Amplify but not with Appsync Console

I have the following resolver, allowing me to retrieve information about the current user company (companyId is added as a custom field on the cognito user pool). The field on cognito is set to mutable.
{
"version" : "2017-02-28",
"operation" : "GetItem",
"key": {
"id" : $util.dynamodb.toDynamoDBJson($context.identity.claims.get("custom:companyId"))
}
}
This works fine when using the AWS AppSync interface (after login in) as the logs show:
{
"errors": [],
"mappingTemplateType": "Request Mapping",
"path": "[getMyClientCompany]",
"resolverArn": "arn:aws:appsync:eu-west-1:261378271140:apis/rue25cac6jc6vfbhvu32sjafqy/types/Query/fields/getMyClientCompany",
"transformedTemplate": "{\n \"version\" : \"2017-02-28\",\n \"operation\" : \"GetItem\",\n \"key\": {\n \"id\" : {\"S\":\"0c1c81db-a771-4856-9a30-d11bf8e3cab1\"}\n }\n}",
"context": {
"arguments": {},
"source": null,
"result": null,
"error": null,
"outErrors": []
},
"fieldInError": false
}
But doesn't work when the code comes from Amplify-js:
{
"errors": [],
"mappingTemplateType": "Request Mapping",
"path": "[getMyClientCompany]",
"resolverArn": "arn:aws:appsync:eu-west-1:261378271140:apis/rue25cac6jc6vfbhvu32sjafqy/types/Query/fields/getMyClientCompany",
"transformedTemplate": "{\n \"version\" : \"2017-02-28\",\n \"operation\" : \"GetItem\",\n \"key\": {\n \"id\" : {\"NULL\":null}\n }\n}",
"context": {
"arguments": {},
"source": null,
"result": null,
"error": null,
"outErrors": []
},
"fieldInError": false
}
The key that should be "custom:companyId" is "NULL" now
I imagine the issue is either with Amplify (version 0.4.8) or with the cognito user resolver for some reason
Any idea what could be going on?
There are two JWT tokens Cognito may utilize. ID and Access. ID token seems to contain those custom claims.
From Amplify you tweak the Authorization header to use ID token vs Access token.
Here's the code, put it in AWS Amplify configuration:
API: {
graphql_endpoint: 'https://****.appsync-api.***.amazonaws.com/graphql',
graphql_region: '***',
graphql_authenticationType: 'AMAZON_COGNITO_USER_POOLS',
graphql_headers: async () => {
try {
const token = (await Auth.currentSession()).idToken.jwtToken;
return { Authorization: token }
}
catch (e) {
console.error(e);
return {};
// Potentially you can retrieve it from local storage
}
}
}
Note, there seem to be several different keys to configure Amplify keys:
for example, aws_appsync_graphqlEndpoint vs API { graphql_endpoint }, I used the latter.