Related
I'm trying to write tests to see if a service is OK, Unknown, or Unreachable via my API. However, all of my tests come back as having passed. I know that all my servers are in an "OK" state, though, and that none of them are "Unreachable" or "Unknown." I believe the "unknown" and "unreachable" tests should be failing. What am I doing wrong?
Here's the body of the response:
{
"result": {
"dhcpServers": [
{
"ref": "DHCPServers/4",
"name": "unixdns",
"address": "10.9.0.220",
"resolvedAddress": "10.9.0.220",
"username": "",
"password": "",
"type": "ISC",
"state": "OK",
"security": "Unknown",
"customProperties": {},
"enabled": true,
"dhcpv6": false
},
{
"ref": "DHCPServers/15",
"name": "mmappliance",
"address": "10.9.0.156",
"resolvedAddress": "10.9.0.156",
"username": "",
"password": "",
"type": "ISC",
"state": "OK",
"security": "Unknown",
"customProperties": {},
"enabled": true,
"dhcpv6": false
},
{
"ref": "DHCPServers/19",
"name": "WIN-51",
"proxy": "10.9.0.150",
"address": "10.9.0.150",
"resolvedAddress": "10.9.0.150",
"username": "",
"password": "",
"type": "MSDHCP",
"state": "OK",
"security": "Unknown",
"customProperties": {},
"enabled": true,
"dhcpv6": true
},
{
"ref": "DHCPServers/22",
"name": "WIN-PM",
"proxy": "10.9.0.100",
"address": "10.9.0.100",
"resolvedAddress": "10.9.0.100",
"username": "",
"password": "",
"type": "MSDHCP",
"state": "OK",
"security": "Unknown",
"customProperties": {},
"enabled": true,
"dhcpv6": true
}
],
"totalResults": 4
}
}
I've written the following tests:
let jsonData = pm.response.json()
pm.test('DHCP service is ok', () => {
_.each(jsonData.dhcpServers, (item) => {
pm.expect(item.state).to.have.body('OK')
})
})
pm.test('DHCP service is Unknown', () => {
_.each(jsonData.dhcpServers, (item) => {
pm.expect(item.state).to.have.body('Unknown')
})
})
pm.test('DHCP service is unreachable', () => {
_.each(jsonData.dhcpServers, (item) => {
pm.expect(item.state).to.have.body('Unreachable')
})
})
//Unknown - DHCP Server Controller status is unknown.
//OK - DHCP Server Controller and service are both OK.
//Unreachable - DHCP Server Controller is offline or otherwise unreachable.
//Out of date - DHCP Server Controller has a different version than Central.
//Updating - DHCP Server Controller version is being updated.
//Uninitialized - DHCP Server is on a uninitialized appliance that needs to be manually initialized.
//Detached - DHCP Server has been detached without removing it from the system.
//DHCP Service Down - DHCP Server service is down and DNS server is not responding to queries.
//DHCP Service Impaired - DHCP Server service is running but impaired.
You miss one level to get dhcpServers. It should be jsonData.result.dhcpServers, not jsonData.dhcpServers,
Use .eql('OK') instead of .to.have.body('OK')
The test would be:
pm.test('DHCP service is ok', () => {
_.each(jsonData.result.dhcpServers, (item) => {
pm.expect(item.state).eql('OK');
})
})
I'm using ImageInput component inside an iterator to upload images in my create form and it generates a structure like this:
"data": {
"items": [
{
"id": 1,
"title": "test",
"subTitle": "test",
"additionalAttributes": {
"price": "3452345"
},
"images": [
{
"src": {
"rawFile": {
"path": "test.jpg"
},
"src": "blob:https://localhost:44323/82c04494-244a-49eb-9d0e-6bca5a3469f7",
"title": "test.jpg"
},
"title": "d"
}
]
}
],
"contact": {
"firstName": "test",
"lastName": "test",
"jobTitle": "test",
"emailAddress": "test#test.com",
"phoneNumber": "23234"
},
"theme_id": 1,
"endDate": "2020-06-19T22:27:00.000Z",
"status": "2"
}
}
What I'm trying to do is sending the image to an API for saving in a folder. Blob URL is an internal object in the browser son it can't be used in the API, so I tried to convert the Blob URL into a binary and send to API.
Following the tutorial I can not get the expected result. Here is my code:
I created a new dataProvider like this:
export const PrivateEventProvider = {
create: (resource: string, params: any) => {
convertFileToBase64(params.data.items[0].images[0].src.src).then(
transformedPicture => {
console.log(`transformedPicture: ${transformedPicture}`);
}
);
const convertFileToBase64 = (file: { rawFile: Blob }) =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(file.rawFile);
});
And I have this error
Unhandled Rejection (TypeError): Failed to execute 'readAsDataURL' on
'FileReader': parameter 1 is not of type 'Blob'.
enter image description here
So my question is, which is the correct way of uploading images to a folder using react-admin?
We are trying to figure out whether Docusign can be used in productive scenarios for our client requirements.
We have a UI5 application which will be used to sign Documents. We have created a template in the demo instance of Docusign.
However when we are trying to create an envelope from the application we are getting 400 Error Unable to parse multipart body. Now the same payload when used in POSTMAN application results in the envelope getting created successfully. The headers passed are also the same.
In Ui5 App :
var settings = {
"async": true,
"crossDomain": true,
"url": "/docusign/envelopes",
"method": "POST",
"timeout": 0,
"headers": {
"Authorization": "User DnVj27euWrCi4ANoMV5puvxVxYAcUCG3PlkUSpWpC08=, Organization 6ba64ce816dec995b17d04605e329a30, Element X4XuUq/T5UUh2o9xwaamZCCRwOKUCPr1Kv1Nj+qHPj0=",
"Content-Type": "application/json"
},
"data": JSON.stringify({
"status": "sent",
"compositeTemplates": [{
"compositeTemplateId": "1",
"inlineTemplates": [{
"recipients": {
"signers": [{
"email": "johndoe#testmail.com",
"name": "John Doe",
"recipientId": "1",
"roleName": "Signer",
"clientUserId": "12345",
"tabs": {
"textTabs": [{
"tabLabel": "firstName",
"value": "John"
}, {
"tabLabel": "lastName",
"value": "Doe"
}, {
"tabLabel": "phoneNo",
"value": "022-635363"
}, {
"tabLabel": "email",
"value": "test#gmail.com"
}]
}
}]
},
"sequence": "1"
}],
"serverTemplates": [{
"sequence": "1",
"templateId": "0bf97611-a457-4e8e-ac7e-1593c17ba3f6"
}]
}]
})
};
var deferred = $.Deferred();
$.ajax(settings).done(function (response) {
deferred.resolve(response);
}.bind(this)).fail(function (error) {
deferred.reject(error);
}.bind(this));
In Postman :
Help would be greatly appreciated in resolving this issue.
Could you stringify outside of the json settings and perhaps break your call down a little before placing everything in settings.
i.e. Try and re-shape your jquery ajax call:
var headers = {"Authorization": "User DnVj27euWrCi4ANoMV5puvxVxYAcUCG3PlkUSpWpC08=, Organization 6ba64ce816dec995b17d04605e329a30, Element X4XuUq/T5UUh2o9xwaamZCCRwOKUCPr1Kv1Nj+qHPj0=", "Content-Type": "application/json" };
var payload = JSON.stringify({
"status": "sent",
"compositeTemplates": [{
"compositeTemplateId": "1",
"inlineTemplates": [{
"recipients": {
"signers": [{
"email": "johndoe#testmail.com",
"name": "John Doe",
"recipientId": "1",
"roleName": "Signer",
"clientUserId": "12345",
"tabs": {
"textTabs": [{
"tabLabel": "firstName",
"value": "John"
}, {
"tabLabel": "lastName",
"value": "Doe"
}, {
"tabLabel": "phoneNo",
"value": "022-635363"
}, {
"tabLabel": "email",
"value": "test#gmail.com"
}]
}
}]
},
"sequence": "1"
}],
"serverTemplates": [{
"sequence": "1",
"templateId": "0bf97611-a457-4e8e-ac7e-1593c17ba3f6"
}]
}]
});
$.ajax({
"async": true,
"crossDomain": true,
"url": "/docusign/envelopes",
"method": "POST",
"timeout": 0,
"headers": headers,
"data": payload
});
I am sure this will lead you to your final "consolidated" answer.
If the exact same JSON is being sent from Postman and from the UI5 application, then you'll get the same results. But you aren't, so something is different.
Probably the UI5 system is sending the API as a mime multi-part request, but isn't setting the content type for the JSON request part correctly.
To verify: use the DocuSign API logger to see what is being received by DocuSign. Compare between the request being sent from UI5 and from Postman.
To fix: you'll need to set additional UI5 parameters so the request is NOT sent as a multi-part mime message. Or send the multi-part message with the needed settings. See the docs and see a multi-part example.
PS PLEASE post an answer to your question with the solution to your problem (once you've found it) to help others in the future. Thank you!!
I was able to fix the issue by directly using the Docusign API (https://demo.docusign.net/restapi/v2/accounts). I was earlier using the SAP Openconnector to connect to Docusign.
https://api.openconnectors.eu3.ext.hanatrial.ondemand.com/elements/api-v2
Thanks all for the help.
I have run into the very same issue recently, and almost decided to give up, but finally, I have managed to find a way to make it work!
The thing is that you need to execute the Ajax call in the following way:
_createEnvelops: function () {
var deferred = $.Deferred();
var oTemplateData = this._getTemplateData();
var oFormData = new FormData();
oFormData.append('envelope', JSON.stringify(oTemplateData));
var settings = {
"async": true,
"crossDomain": true,
"url": '/docusign/envelopes',
"method": "POST",
"data": oFormData,
processData: false,
contentType: false,
"headers": {
"Authorization": sAuthToken
}
};
$.ajax(settings).done(function (response) {
deferred.resolve(response);
}.bind(this)).fail(function (error) {
deferred.reject(error);
}.bind(this));
return deferred;
},
Maybe it will be useful for someone in the future ;)
I use Expo, and I want to add access to my app to users which have a Google account. Then I need to get info about Google calendars of the user which login into my app.
I implement login function using: Expo.Google.logInAsync(options) (https://docs.expo.io/versions/latest/sdk/google). My scope look like this:
scopes: ['https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/calendar.readonly']
When someone tries to login into my app, it asks about permission to see calendars list. In response I get:
Object {
"accessToken": "a",
"idToken": "b",
"refreshToken": "c",
"serverAuthCode": "d",
"type": "success",
"user": Object {
"email": "e",
"familyName": "f",
"givenName": "g",
"id": "h",
"name": "i",
"photoUrl": "j",
},
}
I received data about the user, but I don't have any data about its calendars.
I tried to get data about calendars (https://developers.google.com/calendar/v3/reference/calendarList) with this function:
getUsersCalendarList = async (accessToken) => {
let calendarsList = await fetch('https://www.googleapis.com/calenda/v3/users/me/calendarList', {
headers: { Authorization: `Bearer ${accessToken}`},
});
return calendarsList;
}
In response I got:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "67b8b161-690f-4ff6-9cee-1dce12840ebd",
"offset": 0,
"size": 994,
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "67b8b161-690f-4ff6-9cee-1dce12840ebd",
"offset": 0,
"size": 994,
},
},
"headers": Headers {
"map": Object {
"alt-svc": Array [
"quic=\":443\"; ma=2592000; v=\"44,43,39,35\"",
],
"cache-control": Array [
"public, max-age=0",
],
"content-type": Array [
"application/json; charset=UTF-8",
],
"date": Array [
"Thu, 17 Jan 2019 11:30:32 GMT",
],
"expires": Array [
"Thu, 17 Jan 2019 11:30:32 GMT",
],
"server": Array [
"GSE",
],
"vary": Array [
"X-Origin",
],
"x-content-type-options": Array [
"nosniff",
],
"x-frame-options": Array [
"SAMEORIGIN",
],
"x-xss-protection": Array [
"1; mode=block",
],
},
},
"ok": false,
"status": 403,
"statusText": undefined,
"type": "default",
"url": "https://www.googleapis.com/calendar/v3/users/me/calendarList",
}
How can I get a list of user's google calendars in Expo?
I find the solution here: React-Native JSON fetch from URL. One needs to use json() function on returned object.
The getUsersCalendarList schulde look like this:
getUsersCalendarList = async (accessToken) => {
let calendarsList = await fetch('https://www.googleapis.com/calenda/v3/users/me/calendarList', {
headers: { Authorization: `Bearer ${accessToken}`},
});
return calendarsList.json();
}
You can also add the access token as a parameter on the request.
https://www.googleapis.com/calenda/v3/users/me/calendarList?access_token={token}
I am not a react dev so not exactly sure how to fix your header. It looks ok.
I am looking for the complete "happy path" to place an order using Magento2's REST API. So far these are all the steps I have followed. What else am I missing?
Create a user: [POST] /rest/V1/customers
Log In (create a token): [POST] /rest/V1/integration/customer/token
Get Product Categories for navigation: [GET] /rest/V1/categories
Get Products:
4.1 Get Category Products: [GET] /rest/V1/categories/{category_id}/products
4.2 Or search for a product: [GET] /rest/V1/products
Create a cart: [POST] /rest/V1/carts/mine
Add items to cart: [POST] /rest/V1/carts/mine/items
Get cart payment information [GET] /rest/V1/carts/mine/payment-information
...
What other things do I have to do to place the order?
create empty cart
url : http://www.xxxxxx.com/rest/V1/carts/mine
call: post
response: cartID eg: 4290
Add item to the cart
url : http://www.xxxxxx.com/rest/V1/carts/mine/items
body:
{"cartItem":{
"sku":"JFCO00017","qty":1,"name":"Devil May Cry III 3 Dante Cosplay Costume","price":81.55,"product_type":"simple","quote_id":"4290","product_option":{"extension_attributes":{"custom_options":[{"option_id":"thumbnail","option_value":"\/d\/e\/devilmaycryiii3dantecosplay_1_.jpg"},{"option_id":"color_2","option_value":"Red"},{"option_id":"google_size","option_value":"xxs"}]}}}
}
Add billling info
url : http://www.xxxxxx.com/rest/V1/carts/mine/billing-address
body:
{
"address": {
"city": "noida",
"company": "iprag",
"countryId": "IN",
"email": "manish+2#gmail.com",
"firstname": "Manish",
"lastname": "Kumar",
"postcode": "201301",
"region": "UP",
"saveInAddressBook": 1,
"street": ["D-84"],
"telephone": "8802xxxx90"
},
"useForShipping": true
}
get shipping-methods
url : http://www.xxxxxx.com/rest/V1/carts/mine/shipping-methods
{
"carrier_code": "flatrate",
"method_code": "flatrate",
"carrier_title": "Flat Rate",
"method_title": "Fixed",
"amount": 10,
"base_amount": 10,
"available": true,
"error_message": "",
"price_excl_tax": 10,
"price_incl_tax": 10
}
add shipping info
url : http://www.xxxxxx.com/rest/V1/carts/mine/shipping-information
body:
{
"addressInformation": {
"billingAddress": {
"city": "noida",
"company": "iprag",
"email": "nkn#gmail.com",
"firstname": "Manish",
"lastname": "Kumar",
"postcode": "335001",
"region": "UP",
"street": ["D-84"],
"telephone": "9413433217"
},
"shippingAddress": {
"city": "noida",
"company": "iprag",
"email": "nkn#gmail.com",
"firstname": "Manish",
"lastname": "Kumar",
"postcode": "335001",
"region": "UP",
"street": ["D-84"],
"telephone": "9413433217"
},
"shippingCarrierCode": "flatrate",
"shippingMethodCode": "flatrate"
}
}
response: payment method and cart detail
Order place
URL : http://www.xxxxxx.com/rest/V1/carts/mine/order
body :
{
"paymentMethod":{"method":"checkmo"},
"shippingMethod":
{
"method_code":"flatrate",
"carrier_code":"flatrate",
"additionalProperties":{}
}
}
response: orderid
Ok, I finally got it right.
Save payment information and create order [POST] /rest/V1/carts/mine/payment-information