Loading

Updating thing description / summary returns "null"

Please Login to Comment

Hey,

currently writing an automatic project deployment script, but getting hold up on the thing description patching.

I am able to upload most of the data specified in the API reference (name, license, category, is_wip and tags) as well as upload and delete files of all kinds, but uploading the description does not work, as the description always gets set to "null" after patching.

I am using the following params block for patching. All types are strings except "is_wip" which is bool, as defined in the API reference.

params = {
"name": thingdata["name"],
"license": thingdata["license"],
"category": thingdata["category"],
"description": thingdata["description"],
"is_wip": thingdata["is_wip"],
"tags": thingdata["tags"]
}

thingdata["description"] is meant to hold a markdown string, but for now I am just using the string "Autodeploy" for testing, which still isn't accepted, so my description will be "null" again.

Did the implementation of the description object change and is not just a bare string, or are there new, undocumented API objects for the new summary blocks etc. that I need to write instead?

Have you had success CREATING a brand new Thing via an API call (seems like it)? If so, any tips?

I've been tooling with POSTMAN and have been able to do numerous "read" type of operations, but get receive a "Bad Request" when trying various forms of write (update profile, create a thing).

Yes I did.

What I got working is:

  • Creating Things
  • Adding / updating metadata (other than summary / description)
  • Deleting / uploading and sorting images
  • Deleting / uploading and replacing outdated model files
  • Publish the Thing

I did not try to update the user profile like you did in your screenshot though.

What are you using for authentication? I don't remember ever seeing "bad request" as a response. Have you generated an API key by creating your own App on Thingiverse?
I needed to put the api token in the header as a bearer token like this:

headers = {"Authorization": "Bearer " + api_token}

And then put the parameters in the POST requests Body like this:

params = {"name": thingdata["name"],
"license": thingdata["license"],
"category": thingdata["category"],
"is_wip": thingdata["is_wip"],
"tags": thingdata["tags"]}

requests.patch("http://api.thingiverse.com/things/"

  • str(thingdata["id"])
  • "/", headers=headers,
    data=json.dumps(params))

You can check out the code and documentation here:

https://gitlab.com/Chrismettal/thingideploy

Thanks for the sanity check and code repo. That helped me diagnose the problem. I troubleshot using a flavor of your python, then went back to POSTMAN to imitate and it worked. Basically, I needed to have POSTMAN send "raw" JSON vs form data or encoded.

For the simplest of Python example that posts a new thing for any who wonder....

import requests
import json

url = "https://api.thingiverse.com/things/"

payload={
    "name": "Test Thing",
    "license": "cc-nc",
    "category": "Automotive"
}

headers = {
  'Authorization': 'Bearer YOUR_SECRET_BEARER_TOKEN_HERE'
}

response = requests.post(
url,
headers=headers, 
data=json.dumps(payload)
)

print(response.text)

Awesome, glad you got it working! Now if only Thingiverse would reply to the initial problem of updating Thing summaries, or does that work for you?

Well, this create/update Thing API is pretty worthless without the ability to update the description. I've tried about 20-30 different flavors of JSON payload (all related to what I see in the description ...details...parts...content...etc) with no luck (all yield null). I think we're dead in the water unless we skip the API and post data to their FORM endpoints (lots more effort).

Yes. I just hope Thingiverse hasn't abandoned the API fully.
Most likely the description endpoint just requires a specific format that is not documented. Doesn't seem like a Thingiverse dev has time to look at it though.