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
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
My team is building a health app and thus using Asymmetrik FHIR API Server. We need to save a bundle consisting of Condition, Observation and Procedure. The bundle should create each individual object in their respective tables. But when we are using postman to hit the base URL with a very simple bundle object it is giving Invalid URL. Each service is individually working fine and able to create respective objects. How can we enable the root URL of this FHIR server?
POST URL: http://localhost:3000/4_0_0/
POST Object:
{
"resourceType": "Bundle",
"id": "f001",
"type": "transaction",
"entry": [
{
"resource": {
"resourceType": "Observation",
"status": "registered"
},
"request": {
"method": "POST",
"url": "Observation"
}
},
{
"resource": {
"resourceType": "Condition",
"code": {
"coding": {
"system": "http://hl7.org/fhir/ValueSet/condition-code",
"code": "",
"display": ""
}
}
},
"request": {
"method": "POST",
"url": "Condition"
}
}
]
}
ERROR:
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "not-found",
"details": {
"text": "Invalid url: /4_0_0/"
}
}
]
}
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
I'm attempting to add the data from action_fields to the bundle.request.url as a querystring. Here is raw bundle data
{
"auth_fields": {
"sub_domain": "abc",
"apiKey": "1234"
},
"request": {
"files": {},
"url": "https://abc.my.workfront.com/attask/api/v7.0/project?&method=post",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Accept": "application/json"
},
"params": {
"apiKey": "1234"
},
"data": "{\"status\": \"PLN\", \"name\": \"Test 2\"}",
"method": "POST"
},
"action_fields": {
"status": "PLN",
"name": "Test 2"
},
"action_fields_full": {
"status": "PLN",
"name": "Test 2"
},
"meta": {
"frontend": false
},
"action_fields_raw": {
"status": "PLN",
"name": "Test 2"
},
"url_raw": "https://{{sub_domain}}.my.workfront.com/attask/api/v7.0/project?&method=post",
"zap": {}
}
I'm working off of an example Zapier provides and came up with this
'use strict';
var Zap = {
project_pre_write: function(bundle) {
// bundle.request.method = "POST";
console.log(bundle.request.action_fields["status"]);
bundle.request.url = "http://abc.my.workfront.com/attask/api/v8.0/project?method=post";
bundle.request.params = $.param(bundle.request.action_fields);
console.log(bundle.request.params);
return bundle.request;
}
};
But I have this error thrown
TypeError: Cannot read property 'jquery' of undefined:
I'm no Javascript expert (barely even a user) so any thoughts would be appreciated. The end result should look like this
http://abc.my.wrokfront.com/attask/api/v7.0/project?method=post&name=Test%202&status=PLN&apiKey=1234
Try this:
bundle.request.url += '&' + jQuery.param(bundle.action_fields);
I have a swagger tag document using the Swagger UI that always returns text/html but it should return application/json. The POST requests and every other type returns application/json but this particular GET request does not. The service end point code is correct. And if I change the request to POST it does return as application/json. So it is just type GET within swagger which does not return the correct type. Any thoughts how to correct the call within the UI to use the application/json?
This is swagger version 2.1.4 that was downloaded recently from the swagger site.
"/bankName": {
"get": {
"summary": "Bank Name Search",
"description": "Bank Name Search, input routing number to return bank name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "query",
"name": "routingNumber",
"description": "Input Bank Routing Number",
"required": true,
"type": "string",
}
],
"responses": {
"200": {
"description": "An array",
"schema": {
"type": "object",
"properties": {
"errorInfo": {
"$ref": "#/definitions/ErrorInfo"
},
"bankName": {
"type": "string",
}
}
}
},
"400": {
"description": "Invalid Request Input supplied"
},
"500": {
"description": "General Unexpected Error"
}
}
}
}
Accept:application/json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:localhost:9086
Origin:http://localhost:9086
Pragma:no-cache
Referer:http://localhost:9086/swagger/index.html
Here is the Java code Spring Restful definition:
#RequestMapping(value="bankName",
method=RequestMethod.GET,
produces=MediaType.APPLICATION_JSON_VALUE)
Have you tried this?
"/bankName": {
"get": {
"summary": "Bank Name Search",
"description": "Bank Name Search, input routing number to return bank name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "query",
"name": "routingNumber",
"description": "Input Bank Routing Number",
"required": true,
"type": "string",
}
],
"responses": {
"200": {
"description": "An array",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"errorInfo": {
"$ref": "#/definitions/ErrorInfo"
},
"bankName": {
"type": "string",
}
}
}
}
}
},
"400": {
"description": "Invalid Request Input supplied"
},
"500": {
"description": "General Unexpected Error"
}
}
}
}