BigCommerce cart redirect url - bigcommerce

I used BigCommerce v3 API to create cart redirect url
https://developer.bigcommerce.com/api/v3/#/reference/cart/server-to-server-cart/create-redirect-url
Got 2 links (cart_url and checkout_url). When I tried to use cart link I got cart page with empty cart and error message "Your cart couldn't be retrieved. Please click here to continue shopping."
Has anyone faced the same?
import json
import requests
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Auth-Client': '***',
'X-Auth-Token': '***'
}
store = '***'
cart_uuid = '********-****-****-****-************'
url = 'https://api.bigcommerce.com/stores/{}/v3/carts/{}/redirect_urls'.format(store, cart_uuid)
response = requests.post(url, headers=headers)
response_dict = json.loads(r.text)

To make a cart redirect URL there are two ways:
While creating the cart:
https://api.bigcommerce.com/stores/{$$.env.store_hash}/v3/carts?include=redirect_urls
Pass in redirect_urls as the include.
After the cart is created:
https://api.bigcommerce.com/stores/{$$.env.store_hash}/v3/carts/{cartId}/redirect_urls
Use redirect_urls as part of the request url, along with the cartId.
Make sure to replace cartId with the id that comes back in the response for /POST Cart. Also make sure the cart is still valid by doing a /GET request for the cart id.
Carts are only valid for 30 days.

Related

Sync Token in Postman

A fresher to postman, currently working on API project where I need to delivery to the API and Token the client to integrate with them system, good is I successfully configure the Authorization as OAuth Type as Password Credentials and receiving perfect response as 200.
The issue/confusion is Token is getting expire every hour, I need to Get new Access Token every time.
So, the question is, is it anyway I can overcome this issue?
that no need to get new/refresh token.
can provide the one fix token to client.
You can do it like here. You can get the token in the pre-request field of the collection or request.
https://stackoverflow.com/a/73911458/10126763
EDIT
We can adapt it like this:
Take this and paste it in the "pre-request" field of the collection or the request you will use directly. Create an "environment" value named "accessToken". When each request is run, this method will run first and send the token value to the value in the environment.
// Set refresh and access tokens
const loginRequest = {
url: "exampleurl.com/etc/etc", //YOUR URL
method: 'GET',
header: {
'content-type': 'application/json',
'Accept': "*/*"
} //Since you will be using GET, I deleted the body. If you are sending value you can get the body field from the other example in the link.
};
pm.sendRequest(loginRequest, function (err, res) {
pm.environment.set("accessToken", res.json().accessToken); //The token returned in the response and the environment value to which the value will be sent
});

React native JSON Parse error:Unrecognized token '<'

i want to ask json parse api link must be hosting under by https?
i got this error because my hosting was not secure?
anyone know this problem?
this is my code:
fetch('http://xxx.xxx.x.xx/reactnative/register.php', {
method: 'post',
header:{
'Accept': 'application/json',
'Content-type': 'application/json'
},
body:JSON.stringify({
name: userName,
email: userEmail,
password: userPassword,
})
but my link cant run https:// on the browser
Is this cause me cant parse the data to the link?
This is most likely caused by the response you're receiving being an html page. Make sure your server is set up to receive the information you're trying to send in JSON form. You could try sending your data in application/x-www-form-urlencoded format (in case that's how the server is expecting the data) like so:
body: `name=${userName}&email=${userEmail}&password=${userPassword}`

Angular-5 StripeConnect -303 Error -Response for Preflight is invalid (Redirect)

I am doing StripeConnect(Standard Account Type) with Angular 5 and Asp.NetCore.
I am able to get redirected to required URL with code={} value.
When I am trying to use this code in below URL,
https://connect.stripe.com/oauth/token\client_secret={{secret test key}}\code={{code}}\grant_type = authorization_code"
1.I get preflight is invalid (Redirect) error in browser from my angular solution.
2.The html for stripe login page from Postman.
The code I wrote for making the post call to above URL (in angular) is :
getCredentialsFromStripe(code: any)
{
let Url = "https://connect.stripe.com/oauth/token";
//\client_secret=" + {{key}} + "\code=" + code + "\grant_type
= authorization_code";
return this.http.post(Url, {
Body: "client_secret = {{key}}\code =" + code,
Headers: {
'Authorization': 'Bearer '+ code,
"Accept": "application/json; charset=UTF-8",
"Access-Control-Allow-Origin": "https://connect.stripe.com/oauth/token"
}
}).map(res => res.json());
}
As per suggestions on internet,I tried making the post call from backend(.NET core(2.0) API for me),but didn't get through in creating account for standard account type.
Moreover testing from postman is giving the full html page of login ,instead of getting this object:
{
"token_type": "bearer",
"stripe_publishable_key": "{PUBLISHABLE_KEY}",
"scope": "read_write",
"livemode": false,
"stripe_user_id": "{ACCOUNT_ID}",
"refresh_token": "{REFRESH_TOKEN}",
"access_token": "{ACCESS_TOKEN}"
}
Can anybody give me a lead on this.I have been stuck past two days.
Any thoughts will be really appreciated.
Well,I was able to fix it. Instead of creating accounts using the URL (given above) in angular project (following the node.js documents),I called the stripe api's in Asp.net core (my api solution) and called them.It worked easily.

Manully add csrf token With Slim ,Axios and ForData

I have a a modal that would submit a file without using an actual form, I am using FormData, so upload it to server. This will work if csrf token is disabled, my question is, how would I send the csrf token manually? I am using slim,axios and vuejs.
var formData = new FormData();
formData.append('fileme',file);
axios.post(uyab.uploadUrl, formData,{
headers: {
'Content-Type': 'multipart/form-data',
'csrf_name': uyab.csrf_name,
'csrf_value': uyab.csrf_value,
'Accept': 'application/json',
},
})
But this will return error of failed csrf token
I created a function that would fetch csrf name and values from specific routes, and thus returning with correct values, the only problem is I dont know how to make it work in vuejs using spa approach

KeystoneJS Signup via Rest request

Using sydjs as book to get everything working
I'm trying to signup users via POST request via api:
/api/app/signup-email
Whenever I send data with only email&pass - everything works. If I try to add name parameter - it always fails.
Registration on front-end works as it should
Sending data as:
let parameters = [
"email": "\(email)",
"password": "\(password)",
"name": [
"first": "\(firstname)",
"last": "\(lastname)"
]
]
Maybe anyone has any idea why it doesn't work with name included? Thx.
It won't work because login request in Keystone need a _CSRF token validation, you need to provide it as parameter.
One example is first make a GET request to your login page (The CSRF Token will be in the HEADER response), save it and then make your login request passing the CSRF token obtained in the previous request.
This will be helpful KeystoneJS signin
I implemented a login against the REST-API of keystone (v4.0.0-beta.5). On the client-side I chose npm request. I enabled request's cookie-functionality (config option request.defaults({ jar: true });).
The login consisted of two separate-requests:
A simple GET-request against: https://www.yourkeystoneapp.com/keystone/session/signin
npm request will receive a cookie containing the CSRF token. There is nothing else you need to do with it. npm request will use the received cookie for all subsequent http-requests.
A POST-request containing a simple JSON body with your credentials:
{
email: 'user#yourkeystoneapp.com',
password: 'yourpassword'
}
The POST-request will be answered by Keystone with a valid user-object, if the credentials were correct.
All subsequent http-requests will be part of a valid session, as long as the CSRF-token is valid.
Code examples:
// enable cookies
request.defaults({
jar: true
});
// first request to obtain the cookie
request('https://www.yourkeystoneapp.com/signin', {/* some options */});
// second request to POST your credentials
var loginOptions = {
method: 'POST',
url: 'https://www.yourkeystoneapp.come/api/session/signin',
headers: {
'content-type': 'application/json',
'accept': 'application/json'
},
body: JSON.stringify({
email: 'user#yourkeystoneapp.com',
password: 'yourpassword
})
};
// issue POST request.
request(loginOptions);
// You are now logged in
If you are using npm request, as I did, you have to take a couple of measures to sync the requests you issue, as npm request works asynchronously. Making use of npm request's API and its callback-functions is mandatory.