Facebook API - Batch upload photos - json

I'm trying to batch upload photos and I keep getting a response back from Postman saying "Batch parameter must be a JSON Array" Does anyone see what is wrong with this because it looks like valid json to me. I've been rattling with this for a few hours making minor tweaks trying to get it to upload to no avail. I also have tried encoding the url.
https://graph.facebook.com/v2.11?batch=[{"method":"POST", "relative_url":"https://graph.facebook.com/v2.11/{pageid}/photos?access_token={access-token}", "body":"link_url":"https://{link-to-image}/wmphotos/999995/6d5cc4169bbf4e7dbe31f3739e025412/a572c29dff_640.jpg"}]&access_token={access-token}

Looking at your code, it seems that the JSON object in your batch array is actually malformed. body:link_url:link should be body: {link_url:link}
Bad:
[
{
"method":"POST",
"relative_url":"foo",
"body":"link_url":"link"
}
]
Good:
[
{
"method":"POST",
"relative_url":"foo",
"body":{"link_url":"link"}
}
]

Related

Postman: POST request of nested JSON via form-data not working (while via raw-data ok)

I want to POST the following JSON-object via Postman:
{
"title": "test_title",
"date": "2021-12-31",
"attachments": [
{
"name": "test_attachment"
}
]
}
This works perfectly fine, when using Postman's raw input form for the request-body: I get a "201 Created"-response back.
However, when using the form-data to POST the data, I get the error "Invalid data. Expected a dictionary, but got str." (see also screenshot below) What am I doing wrong here? I tried all kind of other versions to enter the attachment-key:value pair but nothing worked so far
I managed to make it work! (note: I added some additional fields compared to the screenshot in question. See below for details:
You did nothing wrong.
If you want to make a request with json object, then you go with raw type (json) in postman.
If you want to upload file, then you use form-data
One more thing, status 201 means the request is succeed, your object has been created.
var express = require('express')
const multer = require('multer')
const upload = multer()
var app = express()
app.use(express.json());
app.post('/test',upload.none(), function (req, res, next) {
res.send(req.body)
})
app.listen(80, function () {
console.log('web server listening on port 80')
})
Above is a sample endpoint which works with both form-data and json , just do a post to http://localhost:80/test with both form data and raw json
you can see both will get parsed correclty
APIs are just abstraction , its like a function that takes in many attribute, how you parse it depends on the implementation ( how the api function is written) .
so answer is "Talk to the developer" on how the API is implemented and what it is supporting
I'm having issue in placing json into form format the way Daniel did in Postman. Need help in figuring out what is it required to place the cascaded json objects into form data format. Please see here that I'm trying to accomplish.
JSON Format (to be filled into Postman form-data section:
{
"primary_object": {
"child_object_1": [{"id": 12345678, "value": "abc"},{"id": 87654321, "value": "xyz"}],
"child_object_2": [
"first_val",
"second_val"
]
}
}

How to save a JSON-object and use it in another request?

i'm currently trying to set up some JMeter testplans. I am pretty new to this (started a week ago) and don't have much programming experience either, so i hope you could help me in this case.
I already set up some http requests and have some simple JSON Extractor post processors to save some of the variables and use them with the "${variable}" notation.
But now i need to save and modify an object from a response to use that in the next http request.
My respose is a extremely big JSON object and the part im interested in looks something like this:
{
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
}
Note that for whatever reason these objects {"part":"1"...} are inside a nested array. And they are also pretty big.
I would like to safe those objects in a variable to use them in my next http request which should looks like this:
{
"instanceChange": {
"functionChecks": [
{"part": "1"...},
{"part": "2"...},
...
{"part": "20"...}
]
}
}
So what im really trying to find is a way to save all of the possible objects inside the nested array "resultInstance" and put them inside the non nested array "functionChecks".
I already looked inside the JMeter documentation but because of my poor programming background i cant find a way to realize this.
I think i need something like the JSR223 PostProcessor and "simply go through the resultInstance-array and use smth. like an getObject() on these", but i cant figure out the code i need and if its even possible to safe objects in variables in Jmeter.
Im pretty thankful for every bit of help or advice :).
Thanks in advance,
aiksn
Add JSR223 PostProcessor as a child of the request which returns the JSON response
Put the following code into "Script" area:
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def request = ['instanceChange': ['functionChecks': response.payload.workspace.resultInstance]]
vars.put('request', new groovy.json.JsonBuilder(request).toPrettyString())
That's it, you should be able to refer the generated request body as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
let response ={
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
};
let requestObj={
"instanceChange": {
"functionChecks": [
]
}
};
response.payload.workspace.resultInstance.forEach(myFunction);
myFunction(item, index) {
requestObj.instance.functionsCheck.push(item[0]);
}

Translate revit model to svf from bucket id

Im trying to translate a revit model to svf using this endpoint https://developer.api.autodesk.com/modelderivative/v2/designdata/job
According to the docs this endpoint needs at lest these two attributes to work:
urn
formats
First I got the objectId from the desired object inside my bucket :
"objectId":"urn:adsk.objects:os.object:gkwz1o52jxgqnqkhay5dlgcg7e2xglal_tutorial_bucket/rst_basic_sample_project.rvt"
and then I used https://www.base64encode.org/ to encode this string and get my urn, following the advice from this question how to get the urn of the bucket file. The result urn was this:
dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Z2t3ejFvNTJqeGdxbnFraGF5NWRsZ2NnN2UyeGdsYWxfdHV0b3JpYWxfYnVja2V0L3JzdF9iYXNpY19zYW1wbGVfcHJvamVjdC5ydnQ=
Finally I got the format from the examples and I removed the = from the urn string.
My final body data is this:
{
"input": {
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Z2t3ejFvNTJqeGdxbnFraGF5NWRsZ2NnN2UyeGdsYWxfdHV0b3JpYWxfYnVja2V0L3JzdF9iYXNpY19zYW1wbGVfcHJvamVjdC5ydnQ"
},
"output": {
"formats": [
{
"type": "svf",
"views": ["2d", "3d"]
}
]
}
}
But im getting this message:
I thought that was I getting the right object, and getting the urn, but still don't know what I'm doing wrong.
The endpoint URL, payload, and the base64-encoded object ID all seem to be fine. Try a couple of things:
Make sure that you that you're using POST method when calling the endpoint
Make sure that you're using the same Forge credentials (client ID and secret) you used when uploading the Revit model to the bucket
Try other ways of calling the endpoint, for example, using Postman or the VSCode extension

Malformed JSON in Batch when getting Unified Group images

I'm using request https://graph.microsoft.com/v1.0/$batch API to fetch group images and within batch, single image response contains "Content-Type":"image/pjpeg" and that breaks json parsing of the response (unexpected token X in the JSON...).
Request:
{
"requests": [
{
"id":"88aec8df-ea5e-4ad6-8534-3b1ac70693e2",
"method":"GET",
"url":"/groups/88aec8df-ea5e-4ad6-8534-3b1ac70693e2/photo/$value"
},
{
"id":"beeadb9d-02cf-4437-ab7d-7762a58e70a6",
"method":"GET",
"url":"/groups/beeadb9d-02cf-4437-ab7d-7762a58e70a6/photo/$value"
}
]
}
Batch response from Chrome console
Seems that Graph batch does not Base64 encode pjpeg images correctly to response json. Normal "Content-Type":"image/jpeg" images in batch works fine.
Did not find anything related to this from known issues.
For sanity purposes: this was a bug in the batch processing that has been addressed since.

Empty response after sending request to couchDB

I've got problem with CouchDB request. Record from view looks like:
{
"total_rows":79293,
"offset":0,
"rows":[
{"id":"401417608421000",
"key":["2015-08-03T12:07:01+0000"],
"value":0}]
}
request looks like:
http:/ip:port/testDB/_design/reports/_view/experiments?key=["2015-08-03T12:07:01+0000"]
it returns
{
"total_rows":79382,
"offset":0,
"rows":[ ]
}
I read https://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
and change url to
http:/ip:port/testDB/_design/reports/_view/experiments?key=%5B%222015-08-03T12:0‌​7:01+0000%22%5D
but it didn't helped.
Directly I want to send request with startDate and endDate.
It's the plus sign that is making the query fail. If you encode the url you should at least try to encode the entire parameter, this works for me:
?key=%5B"2015-08-03T12%3A07%3A01%2B0000"%5D
And after a bit of testing I found the plus sign to be the problem, so a prettier key-parameter looks like this and works for me:
?key=["2015-08-03T12:07:01%2B0000"]