I am working on a web app and I need to get posts from Instagram by certain hashtag
I used the api found here https://www.instagram.com/developer/endpoints/tags/
but it behaves unexpectedly it only works for one hashtag, if I tried with another one it just return empty array
ex1: https://api.instagram.com/v1/tags/firstTag/media/recent?access_token=MYACCESSTOKEN
ex2: https://api.instagram.com/v1/tags/secondTag/media/recent?access_token=MYACCESSTOKEN
where MYACCESSTOKEN is my access token.
for ex1 it return expected response but for ex2 it returns :
`{
"pagination": {
"deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead"
},
"data": [],
"meta": {
"code": 200
}
}`
Related
I'm a very newbie in JS (I started to learn 3 days ago) and can't find what happened wrong in my code.
I'm trying to get the API response from the following URL: https://api.dictionaryapi.dev/api/v2/entries/en/dog
If the request is made with Postman the response is right. That's means, the dict returned in JSON has the field "meaning" and the sub-fields "partOfSpeech", "definitions", ...
"meanings": [
{
"partOfSpeech": "noun",
"definitions": [
{
"definition": "A mammal, Canis familiaris or Canis lupus familiaris, that has been domesticated for thousands of years, of highly variable appearance due to human breeding.",
"synonyms": [],
"antonyms": [],
"example": "The dog barked all night long."
But if I try to get the response in my code with Axios, the field "meaning" has the wrong structure, and seems that some parts of the response are lost.
The structure returned by axios:
meaning: { noun: [Array], verb: [Array] }
In "meaning", sub-fields like "partOfSpeech" doesn't exist!
noun: [
{
definition: 'Meat from a dog eaten as food.',
synonyms: [],
antonyms: [],
example: 'We visited South Korea this time around, where we ate dog meat for the first time.'
},
{
definition: 'Meat prepared to be given to a dog as food.',
synonyms: [],
antonyms: []
},
Below is a part of my code
const axios = require('axios').default;
async function getInfo(URL, params) {
try {
const response = await axios.get(URL, params);
return response.data;
} catch (error) {
return error;
}
}
function searchWordDefinition(word) {
return getInfo(dict_URL + word);
}
var dict_URL = 'https://api.dictionaryapi.dev/api/v1/entries/en/';
var words = ["dog"];
Your Axios script uses the V1 of the API, your POSTMAN example uses V2.
Change your dict_URL to https://api.dictionaryapi.dev/api/v2/entries/en/ and you should be good.
I'm attaching user info (got by authorization header) with each request (post/put/get/delete) to request headers
...
req.headers.user = {
phone: "+37066666666",
id: "bda5a3c0-2e95-4d6d-bf1f-6c1c8f1edcaa"
};
...
and I have POST request sent by POSTMAN (for example) where I'm sending this body as JSON object:
{
"title": "test",
"users": [
{
"phone": "+37066666666"
}
]
}
where later my code checks if there are owner in this users array and it should append owner if not. but I can't do that since user object that was set in headers have different phone number than phone number of the first user in the users object. Even the number is the same.
So I printed the number stored in headers and the one sent with POST request and this is what I saw:
the number stored in headers after utf=8 decode method: \x2B\x33\x37\x30\x36\x35\x31\x35\x36\x35\x39\x30\xE2\x80\xAC\xE2\x80\xAC\xE2\x80\xAC
and the number sent with POST request:
\x2B\x33\x37\x30\x36\x35\x31\x35\x36\x35\x39\x30
so how this can be fixed? apparently my method to find user doesn't work since the numbers "are not the same"
req.body.users.find(v => v.phone === req.headers.user.phone)
this method will return "undefined" even the printed v.phone and req.headers.user.phone values are the same (on console).
the problem was my macbook "paste" function. it was pasting invisible characters:
"users": [
{
"phone": "+370...<202c><202c>",
...
}
Hello I'm trying to access to an especific key from a JSON. I'm using node.js and angular 7
The JSON I got is stringfy and it comes from an API.
This is the JSON I got
"search": {
"entry": [
{
"dn": "uid=080030781,c=mx,ou=s,o=i.com",
"attribute": [
{ "name": "mail", "value": ["CAMILA.CAMPOS.TELLEZ#mail.com", "MX08#mail.com"] }]
}
],
"return": {
"code": 0,
"message": "Success",
"count": 1
}
}
}
I need to access to the key "value", because I need to get the value "camila.campos.tellez#mail.com".
I get the JSON from an API declarated in a node.js file called app.js, then I catch the response from it using this service.ts file
getApproverMail(name) {
console.log('entered to rootservice');
return this.http.get(this.baseUrl + '/costing/operations?name=' + name);
}
Finally I can access to this through a component.ts fil with this code
findApproverMail() {
this.rootService.getApproverMail(this.aproverName).subscribe((res) => {
this.email = res;
console.log('Test: ' + res);
});
}
And the browser console prints the JSON I have show you. But how can I access only to the mail's value?
P.D I need only the mail because after I got it the web site needs to send an email to that direction
JSON stands for JavaScript Object Notation. Any valid JSON is an object in JavaScript (and TypeScript). You can use dot notation to navigate into the object:
findApproverMail() {
this.rootService.getApproverMail(this.aproverName).subscribe((res) => {
this.email = res.search.entry[0].attribute[0].value[0];
console.log('Test: ' + res);
});
}
I would recommend defining an interface in the shape of what you expect from the service. It's cleaner than just indexing around an any typed object.
Also note that I hard code 0 indexes because that answers your question. You might consider a more dynamic / flexible way to get the address or elements you need.
I need to retrieve the inventory summary for all Stock Items so that I can update an external site's inventory according to the "Available For Shipment" field on the inventory summary. I have attempted running the inventory summary via the rest API using the following method after logging in:
URL: https://mycompany.acumatica.com/entity/Default/6.00.001/InventorySummaryInquiry
Method: PUT
Request Body:
{
"InventoryID": "CW-500-MC-30"
}
However I receive this response:
{
"message": "The request is invalid.",
"modelState": {
"": [
"Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path 'InventoryID', line 2, position 30."
]
}
}
If there is a way to run the inquiry and have it return ALL stock items in an array, that would be ideal.
If that's not possible, what do I need to change to get the individual stock item inventory summary to work?
UPDATE:
After modifying my request body as #samol518 suggested, the request worked, but returned a very limited set of data (below). I'm looking to get to the "quantity available for shipment". Do I need to provide additional parameters to get more data returned?
{
"id": "bf8e0bbc-63dc-4491-802d-090367af203a",
"rowNumber": 1,
"note": null,
"ExpandByLotSerialNumber": {},
"InventoryID": {
"value": "CW-500-MC-30"
},
"LocationID": {},
"WarehouseID": {},
"custom": {},
"files": []
}
If I am not mistaken the correct structure for the Request Body should resemble the following :
Request Body :
{
"InventoryID": {"value": "CW-500-MC-30"}
}
Though if you want to retrieve all Stock Item, you could try and customize the inquiry in order to do so.
Update:
in order to retrieve all record, you might notice that the result fields are in a sub entity in the endpoint definition on the Web Service Endpoint screen (SM207060).
in order to return the data for these detail type sub entities, you must add the expand key word to your URL in the following format.
$expand=results
So your final URL should look like :
https://mycompany.acumatica.com/entity/Default/6.00.001/InventorySummaryInquiry?$expand=Results
I currently have an app running on actions on google using API.AI. I have modified all the response members to be camelCase as suggested and got it working. Now I am trying to return a basic card, but I can not figure out how to properly return it.
Does anyone have the most basic JSON response, returning a basic card to the Google assistant?
currently, the most basic v2 API response I can have is the following:
{
speech: "",
displayText: "",
data: {
google: {
expectUserResponse: true,
isSsml: true,
permissionsRequest: null
}
},
contextOut: [ ],
source: "webhook"
}
I have some Gists showing the JSON responses here.
Right now, it includes Lists, Basic Card and Carousel, but I will add Transactions hopefully soon. Hope it might help somehow
This is what I use for Voice Tic Tac Toe
"google": {
"expect_user_response": true,
"rich_response": {
"items": [
{
"simple_response": {
"text_to_speech": "Your move was top. I moved left"
}
},
{
"basic_card": {
"image": {
"url": "https://server/010200000.png",
"accessibility_text": "Tic Tac Toe game board"
}
}
}
]
}
}
I ran the facts about google action and looked at the fulfillment JSON output to learn how to do this.
https://github.com/actions-on-google/apiai-facts-about-google-nodejs
Note that all responses must include at least one, and no more than two, simple_response items.