Is there any way to implement DialogFlow-cx directly with React native App as DialogFlow ES version does?
I am trying with the REST API also But not working.
I want to Call the Dialogflow CX API from my React-Native App.But I am getting 404, I have downloaded the private key as a JSON file from the service Account also.
Here is a sample code that I have tried
let data = {
"queryInput": {
"text": {
"text": "Hi!"
},
"languageCode": "en"
},
"queryParams": {
"timeZone": "Asia/Colombo"
}
}
fetch(DEFAULT_BASE_URL + this.projectId +"/locations/"+ this.location + "/agent/"+ this.agentId +"/sessions/" + this.sessionId + ":detectIntent", {
method: "POST",
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Authorization': 'Bearer ' + this.accessToken,
'charset': "utf-8"
},
body: JSON.stringify(data)
})
.then(function (response) {
console.log("RESPONSE=== ");
console.log(response);
// var json = response.json().then(onResult)
})
.catch(onError);
};
I changed the agent to agents in URL and it worked.
Here is a reference doc From Google https://cloud.google.com/dialogflow/cx/docs/quick/api
Related
I am working with AWS Amplify, specifically with Auth; I am trying to get the listUsersInGroup from Cognito pool using the next function in React:
import { Auth, API } from 'aws-amplify';
const listUsersInGroup = async (group) => {
let apiName = 'AdminQueries';
let path = '/listUsersInGroup';
let myInit = {
body: {
"groupname": group
},
headers: {
'Content-Type' : 'application/json',
Authorization: `${(await Auth.currentSession()).getAccessToken().getJwtToken()}`
}
};
const supervisorGet = await API.get(apiName, path, myInit);
}
But the API response is having code 403 and the response brings the message: {"message":"groupname is required"}
I made tests with other HTTP methods like listUsers, listGroups, listGroupsForUser and works correctly.
Can anyone help on this issue?
I found the example below in the Amplify documenation for admin actions.
It looks like the myInit object you are making is using body, but the example has queryStringParameters. That's why it's not finding the groupname key.
let nextToken;
async function listEditors(limit){
let apiName = 'AdminQueries';
let path = '/listUsersInGroup';
let myInit = {
queryStringParameters: {
"groupname": "Editors",
"limit": limit,
"token": nextToken
},
headers: {
'Content-Type' : 'application/json',
Authorization: `${(await Auth.currentSession()).getAccessToken().getJwtToken()}`
}
}
const { NextToken, ...rest } = await API.get(apiName, path, myInit);
nextToken = NextToken;
return rest;
}
I am new to shopify, can anyone help me how to setup the checkout API for shopify. I am creating a mobile app with react for a shopify website using API. I tried the one in the shopify docs but it return some error.
post: https://{apikey}:{password}#{hostname}/admin/api/2020-10/checkouts.json
body raw json
{
"checkout": {
"line_items": [
{
"product_id": 5584792125605,
"variant_id": 35877399986341,
"quantity": 1
}
]
}
}
header
X-Shopify-Access-Token : storefront access token
Response
{
"errors": "[API] Invalid API key or access token (unrecognized login or wrong password)"
}
But I've given API key and access token correctly. Is there anything else i should do( I tested this in postman)
Using react native, you have to give the apikey and the password in the Header like this.
getShopifyOrders = () => {
let authorization = base64.encode(
'${Constants.Shopify.key}:${Constants.Shopify.password}'
);
fetch(
'https://${Constants.Shopify.admin_url}/admin/api/2021-04/orders.json',
{
method: "get",
headers: new Headers({
Authorization: 'Basic ${authorization}',
}),
}
)
.then((response) => response.json())
.then((json) => {
console.log(json);
})
.catch((error) => {
console.error(error);
});
};
With Constants.Shopify.key = 'Your_api_key' and Constants.Shopify.password = 'Your_password'
Note : In this code, you have to replace the ' with backsticks ;)
I am trying to implement PayPal REST API with my .net application. For this I am using the sandbox accounts. By referring the demos/documents below code is written which will first create the order and then will make the payment for the same order.
However, my issue is I am not able to grab the order ID. Though I am getting in res.json() from below code. I need to get the order ID, set it to some variable and use it in the subsequent requests. This below code I have got from the demo link and made some changes as per my requirement.
Also in the OnApprove block I am not getting the data.id.
<div id="paypal-button-container"> </div>
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function (data, actions) {
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
body: JSON.stringify({
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
]
})
}).then(function (res) {
return res.json();
}).then(function (data) {
return data.id;
});
},
// Finalize the transaction
onApprove: function (data, actions) {
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders/' + data.id + '/capture/', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
}).then(function (res) {
return res.json();
}).then(function (details) {
console.log(details);
// Show a success message to the buyer
alert('Transaction completed');
});
}
}).render('#paypal-button-container');
</script>
Also, Can I execute my own APIs from the PayPal buttons ?
Any help on this appreciated !
Your code seems perfect(almost). You just need to keep in mind the scope of the variables here. As the 'data' variable is restricted to the 'then' block, you will need to create a new variable to hold the value of 'data.id' and use it in the onApprove block.
I've added a new variable called 'orderID' in the code below and this seems to be working.
<script>
var orderID; //Declared a variable
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function (data, actions) {
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
body: JSON.stringify({
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
]
})
}).then(function (res) {
return res.json();
}).then(function (data) {
orderID = data.id; //storing the id in our variable
return data.id;
});
},
// Finalize the transaction
onApprove: function (data, actions) {
//using the id stored in our variable
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders/' + orderID + '/capture/', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
}).then(function (res) {
return res.json();
}).then(function (details) {
console.log(details);
// Show a success message to the buyer
alert('Transaction completed');
});
}
}).render('#paypal-button-container');
</script>
The implementation you are doing is ideally used for cases when there is a server side component involved, and the API call to the PayPal servers is done via the server.
If you implementation does not require a server side then I will highly recommend to follow the Smart Payment Buttons implementation - https://developer.paypal.com/docs/checkout/integrate/#
I am trying to perform a simple post request in React Native with a module that I also use for my website.
I have an api.ts file where the following is defined:
import { ajax } from 'rxjs/observable/dom/ajax';
import { AjaxRequest } from 'rxjs/observable/dom/AjaxObservable';
const ApiClient = {
loginUser: (email: string, password: string) => {
let requestBody = {email, password};
let url = `${dotenv.REACT_APP_API_URL}/api/users/login`;
return createRequestOptions(url, HttpOptions.POST, requestBody);
}
}
The request options method is as follows:
const createRequestOptions = (url: string, method: string, requestBody?: object) => {
let requestOptions: AjaxRequest = {
method: method,
url: url,
crossDomain: true,
responseType: 'json',
headers: {
'Content-Type': 'application/json',
}
};
if ((method === HttpOptions.POST || method === HttpOptions.PUT) && requestBody) {
requestOptions.body = requestBody;
}
console.log(requestOptions);
return ajax(requestOptions);
};
The output of the requestOptions is as follows:
Object {
"body": Object {
"email": "myemail#gmail.com",
"password": "mypassword",
},
"crossDomain": true,
"headers": Object {
"Content-Type": "application/json",
},
"method": "POST",
"responseType": "json",
"url": "http://localhost:3001/api/users/login",
}
Finally in my epic I have the following:
const authLoginEpic: Epic = (action$, store) =>
action$.pipe(
ofType(ActionTypes.AUTH_LOGIN_REQUEST),
mergeMap((action: AuthLoginRequest) =>
ApiClient.loginUser(action.payload.username, action.payload.password).pipe(
map((res: any) => {
return AuthLoginReceive.create({response: res.response, email: action.payload.username});
}),
catchError((err) => {
console.log(JSON.stringify(err));
For some reason the catchError is triggered and I have no idea why this may be. The output of the log is:
{"message":"ajax error","name":"AjaxError","xhr":{"UNSENT":0,"OPENED":1,"HEADERS_RECEIVED":2,"LOADING":3,"DONE":4,"readyState":4,"status":0,"timeout":0,"withCredentials":false,"upload":{},"_aborted":false,"_hasError":true,"_method":"POST","_response":"","_url":"http://localhost:3001/api/users/login","_timedOut":false,"_trackingName":"unknown","_incrementalEvents":false,"_requestId":null,"_cachedResponse":null,"_headers":{"content-type":"application/json"},"_responseType":"json","_sent":true,"_lowerCaseResponseHeaders":{},"_subscriptions":[]},"request":{"async":true,"crossDomain":true,"withCredentials":false,"headers":{"Content-Type":"application/json"},"method":"POST","responseType":"json","timeout":0,"url":"http://localhost:3001/api/users/login","body":"{\"email\":\"mymail#gmail.com\",\"password\":\"mypassword\"}"},"status":0,"responseType":"json","response":null}
The Ajax error is not very descriptive. Does anyone what I may be doing wrong?
It seems that this happened due to the simple fact that the api address was set to localhost or 127.0.0.1
Ensure to have set this to your local network IP address!
I came around this solution but this is not working for me.
Following is my code:
axios.post('http://myurl/api/login', {
email: 'john#doe.com',
password: '123456'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(response => {
if (response.data) {
this.AuthToken = response.data.token
console.log(this.AuthToken)
axios.get('http://myurl/userdetails/:uid', {
uid: 'D123'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': this.AuthToken
}
}).then(response => {
if (response.data) {
// this.AuthToken = response.data
console.log(response.data)
}
}).catch(error => {
console.log('User Data response Error: ' + error)
})
}
}).catch(error => {
console.log('Login Error: ' + error)
})
I'm getting token from the first POST Login API call. I used that toke to pass into another API call as Authentication token. But I get error: Missing Authorization Headers
Found the solution:
axios.defaults.headers.common['Authorization'] = this.AuthToken;
Try to add another header. "Access-Control-Allow-Headers" : "*".