简体   繁体   中英

POSTMAN PUT request not updating values

Assuming the position of the API tester of https://imgur.com/ , Im testing the PUT request to change account settings. I am following this api doc在此处输入图像描述 Link for abovehttps://apidocs.imgur.com/#7bc88d39-d06d-4661-afff-38ea5b9a1d0a

Steps to check this

  1. Add the relevant info as below, I am setting show_mature and newsletter_subscribed to true

在此处输入图像描述 2. Set the Access token 在此处输入图像描述 3. Click on send the response for this is 200 as shown below 在此处输入图像描述

  1. Check if the details have updated as shown in the following screenshot在此处输入图像描述

Expected : To have show_mature and newsletter_subscribed values set to true Actual : show_mature and newsletter_subscribed values are false

Would be really appreciated if someone could let me know why this is happening? Thanks

From the Imgur API docs ...

Need help?

The Imgur engineers are always around answering questions. The quickest way to get help is by posting your question on StackOverflow with the Imgur tag .

Real helpful Imgur.

Answering here to provide a canonical answer in the tag for this nonsense.

All the API examples in the documentation use some form of multipart/form-data request body payloads. Eg

var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer {{accessToken}}");

var formdata = new FormData();

var requestOptions = {
  method: 'PUT',
  headers: myHeaders,
  body: formdata,
  redirect: 'follow'
};

fetch("https://api.imgur.com/3/account/{{username}}/settings", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

and

curl --location --request POST 'https://api.imgur.com/oauth2/token' \
--form 'refresh_token="{{refreshToken}}"' \
--form 'client_id="{{clientId}}"' \
--form 'client_secret="{{clientSecret}}"' \
--form 'grant_type="refresh_token"'

With the exception of any upload related endpoints, this is ABSOLUTELY INCORRECT . Passing data as multipart/form-data requires the API to handle that request content-type and guess what, the Imgur API does not .

What they do accept is application/x-www-form-urlencoded .

  • In Postman that's the x-www-form-urlencoded option, not form-data
  • In cURL that's the -d option, not --form
  • In JavaScript that's URLSearchParams , not FormData

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM