Data API v3 - models / post problems


(All3d World) #1

Hello,
There are a few problems with the data api v3

  1. When I post a new model, the uid of the new model is not returned in the response

  2. When using the swagger UI to test the API, the category keyword is doubled somehow
    https://docs.sketchfab.com/data-api/v3/index.html#!/models/post_v3_models
    you can see it in the generated curl command
    curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Token c4101261832f45d6b72ca92d87ccd625' -F name=test -F categories=categories=animals -F modelFile=@"test.zip" -F isPublished=true -F description=test desc 'https://api.sketchfab.com/v3/models'

response body:
{
"detail": {
"categories": [
"Select a valid choice. categories=animals is not one of the available choices."
]
}
}

  1. How should I format the data for categories (array[string]))
    When I enter the uid, it's not accepted:

eg for "Products & Technology", "uid" is "d7cebaeca8604ebab1480e413404b679"

I tried values like :
d7cebaeca8604ebab1480e413404b679
"d7cebaeca8604ebab1480e413404b679"
{ "d7cebaeca8604ebab1480e413404b679"}
[{ "d7cebaeca8604ebab1480e413404b679"}]
{ "uid:" "d7cebaeca8604ebab1480e413404b679"}
[{ "uid:" "d7cebaeca8604ebab1480e413404b679"}]

but none of those are accepted as valid choices...


(Klaasnienhuis) #2

About the categories, I've had the same issue https://forum.sketchfab.com/t/patch-api-issue/11676?u=klaasnienhuis
Providing the categories as an array of strings worked for me, but that was still the V2 API. Like so
"categories": [
"22a2f677efad4d7bbca5ad45f9b5868e",
"d7cebaeca8604ebab1480e413404b679"
]


(Tribble42) #3

Hi,

Thank you for your feedback.

Regarding the model uid, it is returned in the Location header. Every POST on the v3 API returns the location of the newly created resource in the Location header.

As for the categories, you stumbled upon a documentation issue (which is still being improved btw, more examples will soon come to help you guys use it). The Category slug should be used, not the uid.

Let me know if it works for you.

Regards

Fred


(Tribble42) #4

Regarding the categories duplicate issue in the curl command, it looks like a bug of the API doc generator we use (http://swagger.io/).

I'll investigate and fix ASAP.


(All3d World) #5

Hi,

Thanks for the info.
As for the first problem : I found the newly created model uid in the header.

As for categories problem : it works fine for a single category, eg

products-technology

but not for multiple categories, like

architecture,products-technology

or [architecture,products-technology]

Or maybe I have to use another syntax ?


(All3d World) #6

Thanks, but I use the V3 api, I tried that


(Tribble42) #7

@all3d.world I updated the API doc, it should work better now.

To upload a model with multiple categories in the swagger ui, simply enter multiplie categories slugs separated by new lines.

Feel free to ping me if you still have issues.


(All3d World) #8


(Tribble42) #9

What are you doing to get this error ? https://sketchfab.com/models/b8580995a971487cbca24349bb2865e8 was uploaded using

curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Token XXX' -F name=test -F categories=animals-creatures -F categories=products-technology -F modelFile=@"pikachu.zip" -F isPublished=true -F description=test 'https://api.sketchfab.com/v3/models'

Keep in mind that even though our API doc offers a simplified UI to test the API, you MUST still use the proper syntax for arrays when using formData or JSON in your code.


(Reflection3dt) #10

Hey tribble42 !Can you explaine more clearly about acquiring the uid in V3 POST API?Can you post the Python code if possible? I am still using the V2 and it has been working pretty good. Much appreciated!


(Reflection3dt) #11

Hey tribble42,

I managed to figure out how to grab the uid from Location Header. Thanks a lot for your help!
Regards,

Tantan


(Tribble42) #12

@reflection3dt glad you found out yourself.

We're working on adding different code samples to simplify the usage of our API. Bear with us ! :slight_smile:

Best

Fred


(All3d World) #13

Hi tribble42,

Thanks for the tip.
When I use multiple statements to add the categories (one by one), it works fine!
(I use C#)
content.Add(new StringContent("architecture"), "categories");
content.Add(new StringContent("products-technology"), "categories");

Before I tried to add a multiline value in one statement, and that didn't work.


(Kirakira) #14

Hi tribble42,

I can't seem to figure out how to retrieve the Location Header from the POST.

xhr.getResponseHeader('Location'); returns null
xhr.getAllResponseHeaders(); returns cache-control: no-cache content-type: application/json

'Access-Control-Expose-Headers: Location' is enabled and I can see the header in the browser debug tools.

Is there something else that's missing?
Thanks for your help!


(Tribble42) #15

@all3d.world glad it worked out :slight_smile: Please let me know if you need help with something else.

@kirakira I just uploaded a model using the sandbox from https://docs.sketchfab.com/data-api/v3/index.html#!/models/post_v3_models
and I see the location header in the response headers

Not sure how to help you :confused: Can you paste a code sample?


(Kirakira) #16

Hey tribble42,

Thanks for the quick response!
I see the location header in the Chrome tool, like on your screenshot, but I can't retrieve it in my code.

$.ajax({
                url: "https://api.sketchfab.com/v3/models?token=myToken",
                data: myFormData,
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                enctype: 'multipart/form-data',
                success: function (xml,status,xhr) {
                    console.log(xhr.getAllResponseHeaders(); //prints only cache-control and content-type
                    console.log(xhr.getResponseHeader('Location'); //null
                },
                error: function (response) {
                console.log(JSON.stringify(response));
            }})

I am using Node js and I have the CORS set in the app.js file as such:

app.use(function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Location');
  res.header('Access-Control-Expose-Headers', 'Location');
next()
})

Which doesn't seem to help at all.
Should there be an extra step somewhere?


(Tribble42) #17

@kirakira from the look of it I don't see any error but we'll test it and come back to you when we find something.

We'll also soon (next week probably) update the endpoint to return the uid, uri of the created model in the response body because this behaviour with the Location header has already caused too many issues to you guys :slight_smile:

Best,

Fred


(Tribble42) #18

@kirakira we've got an update:

Looks like you stumbled upon an issue :slight_smile: We'll fix it and release early next week.

In the meantime I can suggest you a "hackish" workaround: You can retrieve your latest created model by hitting https://api.sketchfab.com/v3/me/models?sort_by=-createdAt

Realy sorry for the disagreament !

Best,

Fred


(Kirakira) #19

@tribble42 Thank you so much!


(Tribble42) #20

Hi @kirakira ,

I forgot to update this thread but your issues above should now be fixed.

Also we released a few code samples to use the V3 API https://sketchfab.com/developers/data-api/v3 (Only python for now, JS and other languages are WIP)

Best,

Fred