Post

2 followers Follow
0
Avatar

Help with proper url PUT structure for changing app field (relationship)

I have been most of my interacting with the API using php, but some things have gotten confusing so I've switched to making simple http requests instead. 

I'm trying to change/update an app field (relationship field) within an item using an http request, but it isn't working properly and I'm not sure why. My request is as follows in Python:

(company is the id of the item that needs to be changed, the number at the end of the url is the field-id within the app of the item that will be updated)

r = requests.put('https://api.podio.com/item/'+company+'/value/116111303', json=payload, headers=headers)

The JSON (payload) being sent is {'fields':{'investors-2':investor}}  where investor is the id of the item that will be referenced from company item. "investors-2" is the external id of the field that will be manipulated.

Finally, the headers are just the headers required for Podio authorization (access token).

The PUT is going through successfully, but nothing is changing within Podio. The result should be that the "investor" item is now referenced from within the "company" item.

What am I doing wrong?

Could I get an example of the proper URL structure/request?

Samson Burton

Please sign in to leave a comment.

4 comments

0
Avatar

Hi Samson,

I think the request you are sending is not going through successfully - you probably get a "Bad Request" (400) status code.

The payload for the app field and the operation you are using (Update item values) can be one of the following:

{ "value":item_id_1 }

or

[{ "value":item_id_1 }, { "value":item_id_2}, ...]

or

[item_id_1, item_id_2, ...]

br
Marek

Marek Hruzik 0 votes
0
Avatar

When I use your suggested structure, I actually get a 204 response, but no change within Podio. Could I get an example of what a proper request would look like? The only inputs will be: 

1) The "Investor" item id (in the 'company' app)

2) The "Company" item id (in the 'company' app)

The investor field (relationship field) within the company item needs to be updated to link to the investor item. It maybe should be noted that both items are in the same app?

Basically, could I get an EXAMPLE of the entire request (with mock IDs)? This one thing has been an obstacle many times and I keep coming back to it. I really appreciate the help.

Samson Burton 0 votes
0
Avatar

204 in the response means that item values did not change. Are you sure that you are trying to set a new value?

Here is an example of series of requests to my test app:

1. Set 2 related items:

PUT /item/381985274/value/115981312 HTTP/1.1
Accept: application/json
Authorization: Bearer (secret)
Content-Type: application/json; charset=utf-8
User-Agent: HTTPie/0.9.1

[
{
"value": 385598611
},
{
"value": 365002670
}
]

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"revision": 16,
"title": "Marek"
}

Response status is 200. Received a revision number.

2. Set 2 related items (same request with the same values!):

PUT /item/381985274/value/115981312 HTTP/1.1
Accept: application/json
Authorization: Bearer (secret)
Content-Type: application/json; charset=utf-8
User-Agent: HTTPie/0.9.1
[
{
"value": 385598611
},
{
"value": 365002670
}
]

HTTP/1.1 204 No Content

Response status is 204. This means there was no change.

3. Set 1 related item:

PUT /item/381985274/value/115981312 HTTP/1.1
Accept: application/json
Authorization: Bearer (secret)
Content-Type: application/json; charset=utf-8
User-Agent: HTTPie/0.9.1

[
{
"value": 385598611
}
]

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
"revision": 17,
"title": "Marek"
}

Response status is 200. Received new revision number.

br
Marek

Marek Hruzik 0 votes