I have a request that returns different 200 responses depending on the parameters passed in. I would like to link directly to a specific response. The responses are structured like so:
+ Response 200 (application/json) <--- Anchor 1
[
{
Response 1
}
]
+ Response 200 (application/json) <--- Anchor 2
[
{
Response 2
}
]
+ Response 200 (application/json) <--- Anchor 3
[
{
Response 3
}
]
Is it possible to add an anchor to the responses so I can link to the responses directly?
I think you might be looking for something like this, https://github.com/apiaryio/api-blueprint/issues/58#issuecomment-98200102.
Please be aware that the feature is not yet available but is planned soon.
Thanks.
Related
I'm implementing an API integration for DocuSign, and I'm currently hitting the following endpoint: /v2/organizations/{organizationId}/users
The documentaton for this: https://developers.docusign.com/docs/admin-api/reference/users/users/getusers/#response200_docusign.api.organizations.web.models.restapi.v2.response.organizationuserresponse
The documentation is showing a response field, user_status. However, when I call the API, I get a response as follows:
{
"users":[
{
"id":"xxx-xxx-xxx-xxx-xxx",
"user_name":"Xxxx",
"first_name":"",
"last_name":"Xxxx",
"membership_status":"active",
"email":"xxxx#gmail.com",
"membership_created_on":"2021-07-30T02:24:20.243",
"membership_id":"xxxx-xxxx-xxxx-xxxx-xxxx"
},
{
"id":"yyy-yyy-yyy-yyy-yyy",
"user_name":"Yyyyy",
"first_name":"Yyyyy",
"last_name":"2",
"membership_status":"active",
"email":"yyyyyyy#yyy.yyy",
"membership_created_on":"2021-07-30T02:26:59.313",
"membership_id":"yyy-yyy-yyy-yyy-yyy"
},
{
"id":"zzz-zzz-zzz-zzz-zzz",
"user_name":"Zzzzz",
"first_name":"Zzzz",
"last_name":"Zzzz",
"membership_status":"active",
"email":"zzz#zzz-zzz.net",
"membership_created_on":"2021-07-15T04:05:18.803",
"membership_id":"zzz-zzz-zzz-zzz-zzz"
}
],
"paging":{
"result_set_size":3,
"result_set_start_position":0,
"result_set_end_position":2,
"total_set_size":3
}
}
As you can see, we have no user_status. Do we need to send any request parameters, to expand the response, or has this field been removed from the API response without being updated on the API documentation?
Or, could I assume that the user is active, if it appears in the API response, with a membership_status of active?
Thank you very much!
membership_status is probably what you're looking for.
there's no such thing as user_status because a user can be a member of multiple accounts and each membership can have a different status.
Here is a useful diagram:
I am trying to get the comments on a pull request using GitHub API, for example:
https://api.github.com/repos/mapra99/members-only/pulls/1/comments
But it returns an empty array.
The same if I try to use the review comments endpoint:
https://api.github.com/repos/mapra99/members-only/issues/1/comments
Although there is a comment on that pull request:
https://github.com/mapra99/members-only/pull/1
How can I get the comment that is on that pull request using GitHub API? Why is it not possible to get if from any of those endpoints?
In fact, this is not a comment but a review :
Pull Request Reviews are groups of Pull Request Review Comments on the
Pull Request, grouped together with a state and optional body comment.
You can get the reviews using :
https://api.github.com/repos/mapra99/members-only/pulls/1/reviews
Or using GraphQL v4 to get reviews & comments :
{
repository(owner: "mapra99", name: "members-only") {
pullRequest(number: 1) {
reviews(first: 100) {
nodes {
body
}
}
comments(first: 100) {
nodes {
body
}
}
}
}
}
I am trying to make a post request which body consists of form-data. But the API rest spec, says the form data should look like this :
names[]= company name 1&names[]=company name 2
I tried
form: {'names[]': "google" ,'names[]': "kraft", 'fields[]': "Country",
'fields[]':"ISIN"}
But the server receives only the first names[] and fields[]. The second ones are cut.
Server: Post data: {"names"=>["kraft"], "fields"=>["ISIN"]}
Then I tried to add array as value:
form: {'names[]': ["google", "kraft"], 'fields[]': ["Country","ISIN"] }
Server: Post data: {"names"=>[{"0"=>"google", "1"=>"kraft"}], "fields"=>[{"0"=>"Country", "1"=>"ISIN"}]}
Looking at the server request, I see that it accepts body in this format:
BODY: names[]=google&names[]=kraft&fields[]=ISIN&fields[]=Country
But I cant construct such form in my node-client side.
I am using this library: https://www.npmjs.com/package/request
********* EDIT ********
This one actually woked:
form: "names[]=google&names[]=kraft&fields[]=Country&fields[]=ISIN"
Now the question is how to form this string using https://github.com/form-data/form-data
No append doesn't work I tried.
It's recommended for keys to be unique and not have brackets in their naming. In your case, names[] and fields[] repeat themselves
const form = {
form: {
names: ['google', 'kraft'],
fields: ['Country', 'ISIN']
}
};
request.post('http://yourwebsite.com', form);
EDIT
names[]=google&names[]=kraft&fields[]=ISIN&fields[]=Country
May be valid, but depending on framework/language, only one entry will be taken into consideration (first or last). So it is equivalent to
names[]=google&fields[]=ISIN // considering first are chosen
Also as you can see
Server: Post data: {"names"=>["kraft"], "fields"=>["ISIN"]}
The brackets were filtered out, so this will be again the same thing
names=google&fields=ISIN // considering first are chosen
I am creating a bot using dialogflow-fulfillment, and I am using Google Place API to pull additional information about hospitals.
I have made a dummy response, for the sake of example, that is returned by Google Place API, here is the link: http://www.mocky.io/v2/5c2b9f9e3000007000abafe3
{
"candidates" : [
{
"formatted_address" : "140 George St, The Rocks NSW 2000, Australia",
"name" : "Museum of Contemporary Art Australia",
"photos" : [
{
"height" : 3492,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/105784220914426417603/photos\"\u003eKeith Chung\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAaGaCX-kivNEaJ-z97AduTYgW3d98uv53-8skNrS1k1GTgOtiQ1-Z2gfWJydrpkrshuV_kHPKizl088dezEJgIxYGoTWqtJgah-u_I46qNNYMfUbk8LKBZqxzkHyIL1nWEhBO6lPa0NgvlyLGBrXpXFPUGhT0lAUj_oCiOWV2MEYdBeKf-kTtgg",
"width" : 4656
}
]
}
],
"status" : "OK"
}
I need to parse values of my choice from the JSON returned by Google Place API. For example, If I had to parse value of 'name' from the JSON above using Python, I would do this:
import requests, json
api_key = ''
r = requests.get('https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Museum%20of%20Contemporary%20Art%20Australia&inputtype=textquery&fields=photos,formatted_address,name&key=' + api_key)
x = r.json()
y = x['candidates']
print(y[0]['name'])
Above code for the job is lucid and works perfectly. Considering my inexperience in Nodejs, would you please let me know something similar in Nodejs to parse the value, for instance, the value of 'name'?
Your valuable reply will encourage me.
P.S: Humbly, the question involves first making a call to Google Place API and then parsing values from the returned JSON. Please follow the steps given in Python code above for better understanding.
Get the API response in an async HTTP request (there are tons of npm libraries like request to help you automatically set headers etc), then use standard library JSON.parse(body) to get an plain JavaScript object which contains a structured representation of the API response.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
I am able to get customer sources only 1st 10 via get customer API:
# stripe.customers.retrieve
{
"id": "cus_DE8HSMZ75l2Dgo",
...
"sources": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_DE8HSMZ75l2Dgo/sources"
},
...
}
But how do I get more? Is the only way via an AJAX call? I was thinking there should be a function somewhere in the SDK?
When you retrieve a Customer object via the API, Stripe will return the sources property which is a List object. The data property will be an array with up to 10 sources in it.
If you want the ability to get more sources than the 10 most recent ones, you will need to use Pagination. The idea is that you will first get a list of N objects (10 by default). Then you will request the next "page" from Stripe by asking for N objects again but using the parameter starting_after set to the id of the last object in the previous page. You will continue doing that until the has_more property in the page returned is false indicating you retrieved all the objects.
For example if your Customer has 35 sources, you would get the first page (10), then call list to get 10 more (20), then 10 more again (30) and then the last call would return only 5 sources (35) and has_more would be false.
To decrease the number of calls, you can also set limit to a higher value. The maximum value is 100 in that case.
Here's what the code would look like:
// list those cards 3 at a time
var listOptions = {limit: 3};
while(1) {
var sources = await stripe.customers.listSources(
customer.id,
listOptions
);
var nbSourcesRetrieved = sources.data.length;
var lastSourceId = sources.data[nbSourcesRetrieved - 1].id;
console.log("Received " + nbSourcesRetrieved + " - last source: " + lastSourceId + " - has_more: " + sources.has_more);
// Leave if we are done with pagination
if(sources.has_more == false) {
break;
}
// Store the last source id in the options for the next page
listOptions['starting_after'] = lastSourceId;
}
You can see a full running example on Runkit here: https://runkit.com/5a6b26c0e3908200129fbb5d/5b49eabda462940012c33880
Taking a quick look into the sources of the stripe-node package, it seems there is a stripe.customers.listSources method, which takes a customerId as parameter and requests to the correct url. I suppose it works similar to the listCards method. But I couldn't find it in the docs, so you have to treat it as an undocumented feature ... But maybe it's just an error in the docs. You could contact the support about it. We used stripe in an old project and they appreciated any input on their documentation.
As of stripe-node 6.11.0, you may auto-paginate list methods, including customer sources. Stripe provides a few different APIs for this to aid with a variety of node versions and styles.
See the docs here
The important part to notice is .autoPagingEach:
await stripe.customers.listSources({ limit: 100 }).autoPagingEach(async (source) => {
doSomethingWithYourSource(source)
})