Hi (Sorry for my english)
I have a POST service and I have to send some parameters in json format, but I don't find a solution. I found an example in the page number three of Google haha, but I need to send a object array and I don't know how I can send un array.
<WebView
source={
{
uri: Urls.base + '/store/checkout',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: "param1=test¶m2=test"
}} />
In ReactNative Documentation say that "body" param is a String, so I can't send a json.
I should send this json
{
"delivery": 2,
"payment": 1,
"userName": "test#test.pe",
"name": "Joseph",
"lastname": "Test",
"userEmail": "tes#test.pe",
"userPhone": "11223344",
"userAddress": "Av AAA 742",
"totalAmount": 1500,
"user": 5,
"detail": [
{ "product": 1, "quantity": 2 },
{ "product": 2, "quantity": 1 },
{ "product": 5, "quantity": 3 }
]
}
thanks
Related
I attempting to use the JWT oAuth method to authenticate with the DocuSign API to create a template. I keep receiving the response "You need to enable JavaScript to run this app". I'm not great with connecting with APIs and needs some guidance. It works fine with the X-DocuSign-Authenticate method but DocuSign will not allow this for REST after March 2023. This is a DocuSign demo developer account.
I've tried the code below but keep getting the same error.
function createTemplate() {
var driveFile = DriveApp.getFileById("FILEID");
var changeorderEncode = Utilities.base64Encode(driveFile.getBlob().getBytes());
const JWT = "MY_ACCESS_TOKEN";
const url = 'https://account-d.docusign.com/oauth/token/restapi/v2.1/accounts/<accountid>/templates';
var payload =
{
"envelopeTemplateDefinition": {
"name": "TestTemplate5"
},
"documents": [
{
"documentBase64": changeorderEncode,
"documentId": "1",
"fileExtension": "pdf",
"name": "Change Order Test 5"
}
],
"emailSubject": "1234 Easy St Change Order",
"recipients": {
"signers": [
{
"name": "Recipient Name",
"recipientId": "1",
"tabs": {
"signHereTabs": [
{
"documentId": "1",
"pageNumber": "1",
"tabLabel": "Signature2",
"xPosition": "407",
"yPosition": "650"
},
{
"documentId": "1",
"pageNumber": "1",
"tabLabel": "Signature",
"xPosition": "140",
"yPosition": "650"
}
],
"dateTabs": [
{
"documentId": "1", //notes
"pageNumber": "1",
"tabLabel": "date",
"xPosition": "140",
"yPosition": "715"
},
{
"documentId": "1",
"pageNumber": "1",
"tabLabel": "date",
"xPosition": "407",
"yPosition": "715"
}
],
"textTabs": [
{
"documentId": "1",
"pageNumber": "1",
"name": "Project Address",
"value": "1234 Easy St, Roseville, CA 95678",
"width": 55,
"xPosition":"76",
"yPosition":"159"
}
],
}
}
]
},
"status": "created"
};
var options =
{
"method" : "post",
"headers":
{
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": JWT,
"Accept": "application/json",
"contentType": "application/x-www-form-urlencoded",
},
"payload" : JSON.stringify(payload),
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
Your URL is slightly incorrect.
account-d.docusign.com/oauth/token is the endpoint you'd use to get a token. You would use
demo.docusign.net/restapi/v2.1/{{account_id}}/templates to create a template
You can get your baseUrl from the userInfo endpoint. All of this information is available on the JWT Authentication page
I also think your content-type should be application/json since you are sending a JSON (json.stringify(payload) converts it into a json)
I'll also add a link to the API Reference which will allow you to get the correct endpoint and the payload schema for all endpoints
I get an array from the API as follows:
[ { "URL": "", "avatar": "", "characterID": 853, "creationDate": "2022-01-22T17:12:42", "description": "description", "foreignSuggestionID": 0, "id": 5, "seriesID": 0, "type": "IMAGE", "userID": 168314031248113660 } ]
However I expect
[ { "URL": "", "avatar": "", "characterID": 853, "creationDate": "2022-01-22T17:12:42", "description": "description", "foreignSuggestionID": 0, "id": 5, "seriesID": 0, "type": "IMAGE", "userID": 168314031248113664} ]
The userID gets transformed in the request by Javascript, since when I use transformResponse: data => data I get the correct ID.
This gets me to the conclusion that it cannot contain the large number in Javascript. My question here would be, is there a way to make sure that a specific value within the json array is seen as a bigint or can I convert the column into a string on receiving the response?
I use axios and my code is as follows:
this.$axios.get(url, {
withCredentials: 'true'
})
.then(response => {
this.data = response.data
})
I hope you guys are having a wonderful day.
I have set up a webhook in my woocommerce that sends JSON data to Google sheets. The webhook has been working great for months now, just today, I am having some trouble with it. I have tracked the issue to be in google sheets receiving the JSON data, but I don't know why this is happening.
Let me explain.
https://docs.google.com/spreadsheets/d/18G-yVDjYeccl6kznpZgSuRTysRMAu57pwY2oGf6-KWI/edit?usp=sharing
This is the google sheet, when it gets Woocommerce JSON data, it populates a new row.
The problem
Sometimes google sheets doesn't populate the row upon receiving a new order. The problem doesn't lie with woocommerce, because I have checked woocommerce with reqbin and the webhook fires with every order.
Furthermore, when I send requests from reqbin.com to my sheet, the sheet performs the operation successfully 5-6 out of 10 times. Other times it shows an error.
The Error
The error is due to google sheets not being able to parse JSON data, because the JSON data it receives 5 out of 10 times is not proper JSON data. Other 5 times, it is just as it should be. I have put a catch statement if the sheet is unable to parse JSON. Instead of appending new row with the parsed data, it appends the raw received data to the sheet.
It is clear now that there is some issue with google sheets handling that JSON data because when the same data is sent from reqbin.com to webhook.site, it is perfectly as it should be 10/10 times.
How to reproduce the issue
Open this google sheet. https://docs.google.com/spreadsheets/d/18G-yVDjYeccl6kznpZgSuRTysRMAu57pwY2oGf6-KWI/edit?usp=sharing
Open reqbin.com and webhook.site, and send the following JSON from reqbin.com to webhook.site 10 times to see if any kind of error occurs.
{ "id": 47222, "parent_id": 0, "status": "processing", "currency": "PKR", "version": "5.1.0","prices_include_tax": false, "date_created": "2021-06-10T01:23:46", "date_modified": "2021-06-10T01:23:46", "discount_total": "0", "discount_tax": "0", "shipping_total": "150", "shipping_tax": "0", "cart_tax": "0", "total": "1850", "total_tax": "0", "customer_id": 0, "order_key": "wc_order_7gIuR7px6MX9C", "billing": { "first_name": "Name", "last_name": "", "company": "", "address_1": "Address", "address_2": "", "city": "City", "state": "", "postcode": "", "country": "PK", "email": "email#email.com", "phone": "1234" }, "shipping": { "first_name": "Name", "last_name": "", "company": "", "address_1": "Address", "address_2": "", "city": "City", "state": "", "postcode": "", "country": "Country" }, "payment_method": "cod", "payment_method_title": "Cash on delivery", "transaction_id": "", "customer_ip_address": "8.8.8.8", "customer_user_agent": "Mozilla/5.0 (Linux; Android 11; M2102J20SG) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.88 Mobile Safari/537.36", "created_via": "checkout", "customer_note": "", "date_completed": null, "date_paid": null, "cart_hash": "64d834c72eecc8e32b9d83fd67d10d9c", "number": "47222", "meta_data": [ { "id": 869388, "key": "_shipping_calculator", "value": "" }, { "id": 869389, "key": "is_vat_exempt", "value": "no" }, { "id": 869391, "key": "_wfacp_report_data", "value": { "wfacp_total": "0.00" } }, { "id": 869392, "key": "_woofunnel_cid", "value": "4" }, { "id": 869393, "key": "_wfacp_post_id", "value": "24852" }, { "id": 869394, "key": "_wfacp_source", "value": "https://website.com/checkouts/checkout-page/" }, { "id": 869395, "key": "_wfacp_timezone", "value": "Asia/Karachi" }, { "id": 869396, "key": "order_comments", "value": "" }, { "id": 869412, "key": "_new_order_email_sent", "value": "true" }, { "id": 869424, "key": "_woofunnel_custid", "value": "4" }, { "id": 869425, "key": "_pys_purchase_event_fired", "value": "1" }, { "id": 869426, "key": "_wfob_stats_ids", "value": [] }, { "id": 869427, "key": "_wfocu_thankyou_visited", "value": "yes" } ], "line_items": [ { "id": 35114, "name": "MTECH Ultra Resilient Knife", "product_id": 11074, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "1700", "subtotal_tax": "0", "total": "1700", "total_tax": "0", "taxes": [], "meta_data": [], "sku": "", "price": 1700, "parent_name": null } ], "tax_lines": [], "shipping_lines": [ { "id": 35115, "method_title": "Fast Shipping (2-4 Days)", "method_id": "flat_rate", "instance_id": "1", "total": "150", "total_tax": "0", "taxes": [], "meta_data": [ { "id": 275053, "key": "Items", "value": "MTECH Ultra Resilient Knife × 1", "display_key": "Items", "display_value": "MTECH Ultra Resilient Knife × 1" } ] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "date_created_gmt": "2021-06-09T20:23:46", "date_modified_gmt":"2021-06-09T20:23:46", "date_completed_gmt": null, "date_paid_gmt": null, "currency_symbol": "₨","_links": { "self": [ { "href": "https://website.com/wp-json/wc/v3/orders/47222" } ],"collection": [ { "href": "https://website.com/wp-json/wc/v3/orders" } ] } }
Now send the same data to the following google sheet to see if it appends the row correctly each time.
https://script.google.com/macros/s/AKfycbxupm9bje86F4PQQkyys_LWtXs_kj279R0ipgnZ-cLd7aiEADf1AN_prhk28vOPW9JsRQ/exec
How do I solve the issue? Please let me know if you need any more information. Thanks.
Edit:
Instead of getting a full JSON body like mentioned above, the google sheets seems to be getting the following JSON.
{contextPath=, queryString=, parameter={}, postData=FileUpload, parameters={}, contentLength=3981.0}
I would like to know why the google sheets default parameter (e) contains this instead of a full JSON body sent to it.
Edit # 2
I would like to know why the google sheets default parameter (e) contains this instead of a full JSON body sent to it.
This is because (e) has a body which will always contain those parameters. The error is due to Google Sheets receiving an empty JSON body. I am still unable to understand why this happens. When I send the same JSON to API testing sites, they always receive full JSON body. Google sheets, in some cases, does not. Why is that?
I managed to solve the issue with some trial and error. For anyone facing the same issue in the future, here is what worked for me.
I was using e.postData.contents to get the JSON body but this seems to have stopped working, which was causing the JSON body to be empty. I tried e.postData.getDataAsString(); which seems to be working just fine and the issue has been resolved.
i am trying to send a batch request with graph api batch request using axios.
When I tried with postman i tried the following -
I am trying to post a send api with batch request.
url = https://graph.facebook.com?access_token=EA...`.
raw body = `{
"batch":[
{
"method": "POST",
"relative_url": "me/messages?access_token=<ACCESS_TOKEN>",
"body": "{ \"messaging_type\": \"MESSAGE_TAG\",\r\n \"tag\": \"ISSUE_RESOLUTION\",\r\n \"recipient\": {\r\n \"id\": \"1111944272264076\"\r\n },\r\n \"message\": {\r\n \"text\": \"hello, world!\"\r\n }}"
}
]
}
and the response is
[
{
"code": 400,
"headers": [
{
"name": "WWW-Authenticate",
"value": "OAuth \"Facebook Platform\" \"invalid_request\" \"(#100) The parameter recipient is required\""
},
{
"name": "Expires",
"value": "Sat, 01 Jan 2000 00:00:00 GMT"
},
{
"name": "Strict-Transport-Security",
"value": "max-age=15552000; preload"
},
{
"name": "Facebook-API-Version",
"value": "v2.10"
},
{
"name": "Content-Type",
"value": "text/javascript; charset=UTF-8"
},
{
"name": "X-App-Usage",
"value": "{\"call_count\":0,\"total_cputime\":0,\"total_time\":0}"
},
{
"name": "Access-Control-Allow-Origin",
"value": "*"
},
{
"name": "Cache-Control",
"value": "no-store"
},
{
"name": "Vary",
"value": "Accept-Encoding"
},
{
"name": "Pragma",
"value": "no-cache"
}
],
"body": "{\"error\":{\"message\":\"(#100) The parameter recipient is required\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"BdrR5exbYCu\"}}"
}
]
response code is 200. i have given recipient in body.
You don't need to URL encode the entire body. Only the content of each parameter. Try this as the body for request:
{
"batch":[
{
"method":"POST",
"relative_url":"me/messages",
"body": "recipient={\"id\": \"1111944272264076\"}&message={\"text\": \"hello, world!\"}"
}
]
}
Note: Instead of URL coding, I just escaped the characters. Makes the code much more readable
I have a json like this (there might be some syntax errors, I did extract and rewrite some private data)
"todo-items": [{
"id": 3511710,
"company-name": "company1",
"author" : "Jon Doe",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}],
"creation-date": 20160101
}, {
"id": 3511474,
"company-name": "company1",
"author" : "Jon Don",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}, {
"id": 10103,
"name": "4.Automotive",
"color": "#9b7cdb"
}],
"creation-date": 20160101
}, {
"id": 3511478,
"company-name": "company1",
"author" : "Peter Jon Doe",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}, {
"id": 9706,
"name": "3.sales",
"color": "#37ced0"
}, {
"id": 9562,
"name": "3.IT",
"color": "#37ced0"
}],
"creation-date": 20160101
}]
and I use alasql with xlsx.core libraries to export this to excel file.
For first I remove STATUS from original json (provided by teamwork API) and then I change JSON to javascript array
$.ajax({
type: "GET",
url: requrl,
headers: {"Authorization": "BASIC " + window.btoa(key + ":xxx")},
success: function(data) {
delete data.STATUS;
//alert(data);
//console.log(data);
var arr = $.map(data, function(el) { return el });
//console.log(arr);
alasql("SELECT * INTO XLSX('test.xlsx',{headers:true}) FROM ? ",[arr]);
},
error: function(response) {
alert(response);
}
});
this works nice and I can my json extract as excel file
but I have issues with tags objects in this json..when I change it to array and then save it in excel, all columns are ok except tags, where I see just [object][object]
Could you help me how to get these tags also into correct array? The best would be one tag = one column in excel
edit:
this is desired output - max # of tags in JSON will define number of columns tags (doesnt matter if it is tags tags tags or tags tags2 tags3)