I'm trying to update a value received from API in JSON and send it back.
I updated the value as the following code but when I try to send it back "PUT" I get error 400 Bad Request
the API can be found here: Webex Update a Person API
could someone help me figure what am I doing wrong?
thanks a lot
def get_userID(user_id):
session = HTMLSession()
header = {
"Authorization": "Bearer %s" % token,
"Content-Type": "application/json",
}
session.get(
f"https://webexapis.com/v1/people/{user_id}",
headers=header,
verify=True,
)
user_details = webex_user_details.json()
user_details["emails"][0] = "newemail123#example.com"
webex_user_details = session.put(
f"https://webexapis.com/v1/people/{user_id}",
headers=header,
data=user_details,
verify=True,
)
print(webex_user_details)
I figured it out that I need to dump the new data as JSON after updating
user_details = json.dumps(user_details)
Related
I am developing my first API in lua to manage geodis transport in my company.
I finished the development and I have a 400 error my json request is correct is the header or a bad url can return me a 400 error?I tested on their site the request works correctly.
you will find below the calculation of the hash and the header and the url.
````url_webservice = "https://espace-client-rct.geodis.com/services/"`
````endpoint = url_webservice..Service
````t = os.date('*t')
````timestamp =os.time(t)
````milliseconde = (timestamp * 1000)
````message = cle..';'..id..';'..milliseconde..';'..'fr'..';'..url_Service..';'..jsonGEO
````Trace("log", "message:" ..message)
````local Hash = cryptographicHash(toLocal8Bit(message), "sha256")
````Trace("log", "hash:" ..Hash)
````local token = id..';'..milliseconde..';'..'fr'..';'..url_Service..';'..Hash
````Trace("log", "token:" ..token)
````local headers = {
````"Accept: */*",
````"Content-Type: application/json; charset=utf-8",
````"X-GEODIS-Service:" .. token
````}
````local request = ws:createHttpPostRequest(url, headers, jsonGEO)`
I've tried everything to make it work and I can't find the problem
I am attempting to create my first PowerBI Custom Connecter to connect to the Vimeo API. I am stuck on the final step of the authorization flow - getting back an access token. When trying out the Connecter in PowerBI, it seems to authenticate properly when I hit the access token endpoint, but I get back a warning "[unsupported_grant_type] Unsupported grant type"
It appears I am not sending the grant_type properly in the request. Here are Vimeo's requirements of what is sent along in the header and body of the request:
Header
Set value to
Authorization
basic base64_encode(x:y), where x is the client identifier and y is the client secret
Content-Type
application/json
Accept
application/vnd.vimeo.*+json;version=3.4
"In the request body, send the grant_type field with the value authorization_code. You must also set code to the authorization code string that you just received and redirect_uri to the redirect URI that you specified previously — don't use a different redirect URI."
{
"grant_type": "authorization_code",
"code": "{code}",
"redirect_uri": "{redirect_uri}"
}
Here is a snippet of code from the Customer Connector I am building. It is within this TokenMethod function that I am trying to fulfill the requirements of the table above. I am getting the sense I am not correctly placing the JSON in the body of the request, but I am stuck on what to try next:
TokenMethod = (grantType, tokenField, code) =>
let
queryString = [
grant_type = "authorization_code",
redirect_uri = redirect_uri,
client_id = client_id,
client_secret = client_secret
],
queryWithCode = Record.AddField(queryString, tokenField, code),
authKey = "Basic " & Binary.ToText(Text.ToBinary("client_id:client_secret"),BinaryEncoding.Base64),
tokenResponse = Web.Contents(token_uri, [
Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
Headers = [
#"Authorization" = authKey,
#"Content-type" = "application/json",
#"Accept" = "application/vnd.vimeo.*+json;version=3.4"
],
ManualStatusHandling = {400}
]),
body = Json.Document(tokenResponse),
result = if (Record.HasFields(body, {"error", "error_description"})) then
error Error.Record(body[error], body[error_description], body)
else
body
in
result;
I'm wondering if someone could please point out where I might be going astray in the code and why I am receiving the [unsupported_grant_type] error.
Many thanks for your time!
I changed Content-Type to "application/x-www-form-urlencoded" and it worked!
For GET and POST requests for a private server I work with I use in Google Sheets, do something like this, and I get a proper response. I use that response to update data and just as importantly for error checking by evaluating response.getResponeCode().
function postDataToServer(params){
let myjdService = getService();
let orgId = getOrgIdForSelectedOrg();
let link = https://GoodURLForPrivateDataIWorkWithALot/neededurlParameter/anotherNeededURLParameter;
let options = {
'method': 'put',
'payload': JSON.stringify(params),
'headers': {
'Accept': 'application/vnd.PRIVATE.v3+json',
'Content-Type': 'application/vnd.PRIVATE.v3+json',
'authorization': 'Bearer ' + myPrivateService.getAccessToken()
}
};
let response = UrlFetchApp.fetch(link, options);
return response.getResponseCode();
For all the GET and POST requests I do, I get a response. And from that response I can parse a response code. But for the specific server I work with, when I edit a record using PUT, a successful edit returns this:
204 No Content
And further, the last line return response.getResponseCode() returns an error the response is undefined.
Here's the error I get for doing anything with response:
ReferenceError: response is not defined
The PUT is working. I only know this because 1) when I check if edits are made with the server, they are 2) testing the PUT in Postman at least shows me the words "204 No Content" and 3) the documentation says that's exactly what I should expect.
But I still would like to find out how to evaluate this no-content response in my Google Sheets App for proper error tracking. At least some way to get the string "204". Any ideas? I can't even get Google Sheets to do say 204.
I tried to make a cart for this site: https://www.off---white.com/en/IT
When I tried to send values for the params of the cart, one of this params is a token of recaptcha. I tried manually to get the token using this project 'https://github.com/Cosmo3904/Recaptcha-Harvester-V2'
When I tried to make the request I pass all params:
token = 'recaptcha_token' #(I get it manually and expires every 110s)
payload = {"variant_id": "111380", "quantity": "1", 'g-recaptcha-response': token}
s = requests.Session()
resp2 = s.post("https://www.off---white.com/en/IT/orders/populate.json",headers=headers,data=payload)
print('STATUS CODE: ' + str(resp2.status_code))
unfortunately the response is every time 401, that means unauthorised. How can I solve this?
(To the session I pass headers and cookies so the page is right configured, I checked before trying login and it works)
import cfscrape
s = requests.Session()
scraper = cfscrape.create_scraper(s)
scraper.get('https://www.off---white.com/en/IT', headers=headers)
url = 'https://www.off---white.com/en/IT/orders/populate.json'
r = scraper.post(url, data={'variant_id' : 'variant', 'quantity' : 1, 'g-recaptcha-response': token}, headers=headers)
Try with cfscrape.
So I've been trying to set up my chat bot for Twitch. I want the user to be able to type !stats and then they'll see my Fortnite stats.
They can use the command and stuff, that's not what I'm having a problem with. I'm having some trouble sending a header to Fortnite Tracker API.
They want to recieve this: TRN-Api-Key: somelong-api-key-right-here in the header.
I've tried these methods:
require("httparty")
url = "https://api.fortnitetracker.com/v1/profile/pc/bentearzz"
header = {
key: "TRN-Api-Key: Somelong-api-key-here"
}
response = HTTParty.get(url, header: header)
puts(response.body)
and this
require("net/http")
require("json")
url = "https://api.fortnitetracker.com/v1/profile/pc/bentearzz"
uri = URI(url)
response = Net::HTTP::Get.new(uri)
response.basic_auth("TRN-Api-Key: 7af072f0-d195-4c44-b1b4-a8838080e4c4")
JSON.parse(response)
print(response)
Please help.
Your first one is on the right track. I think there are just a few syntax errors.
url = "https://api.fortnitetracker.com/v1/profile/pc/bentearzz"
headers = {
"TRN-Api-Key": "Somelong-api-key-here"
}
response = HTTParty.get(url, headers: headers)
puts(response.body)