scrapy post request not updating data in airtable - web-scraping

I need to create records in an airtable base and have the following code in scrapy:
url = "https://api.airtable.com/v0/appuhKmlhLIIEszLm/Table%201"
payload = json.dumps({
"records": [
{
"fields": {
"Name": "Temporada 6"
}
},
{
"fields": {
"Name": "Temporada 2"
}
}
]
})
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
yield scrapy.Request(method = "POST",url = url, headers=headers, body=payload)
I checked the code with python requests and works, however, when I use this scrapy code, no info is uploaded, do you know why is this?

Related

Build an Authenticated GET API in R

I can't figure out how to set up an API correctly. I have an example in Python and would like to understand how to reproduce it
with R, how to correctly choose attributes and authenticate.
import requests
import json
url = "https://developer.junglescout.com/api/product_database_query?marketplace=us"
payload = json.dumps({
"data": {
"type": "product_database_query",
"attributes": {
"include_keywords": [
"videogames"
],
"categories": [
"Video Games"
],
"exclude_unavailable_products": True
}
}
})
headers = {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.junglescout.v1+json',
'Authorization': 'KEY_NAME:MY_API_KEY'
}
response = requests.request("POST", url, headers=headers, data=payload)

Add user to SharePoint group using Power Automate

I would like to use Power Automate to add a user in as a member to a SharePoint Site using HTTP request.
The flow continues to fail on me and I'm wondering if anyone managed to do this successfully in the past?
I got the Group ID from :
https://{org name}.sharepoint.com/sites/{site name}/_api/web/id
I have attached included the input and output of the HTTP Request (within flow) below
Raw Inputs
{
"host": {
"connectionReferenceName": "shared_sharepointonline",
"operationId": "HttpRequest"
},
"parameters": {
"dataset": "https://{REDACTED}.sharepoint.com/",
"parameters/method": "POST",
"parameters/uri": "_api/web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users",
"parameters/headers": {
"accept": "application/json;odata.metadata=none",
"content-type": "application/json"
},
"parameters/body": "{'LoginName':'i:0#.f|membership|{REDACTED}#{REDACTED}.com'}"
}
}
Raw Outputs
{
"statusCode": 400,
"headers": {
"Pragma": "no-cache",
"x-ms-request-id": "cb6ab59f-909a-2000-ac2f-2217e416179a",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Cache-Control": "no-store, no-cache",
"Set-Cookie": "{REDACTED};Path=/;HttpOnly;Secure;Domain=sharepointonline-we.azconn-we.p.azurewebsites.net,ARRAffinitySameSite={REDACTED}24;Path=/;HttpOnly;SameSite=None;Secure;Domain=sharepointonline-we.azconn-we.p.azurewebsites.net",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"Date": "{TIME & DATE}",
"Content-Length": "457",
"Content-Type": "application/json",
"Expires": "-1"
},
"body": {
"status": 400,
"message": "The expression \"web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users\" is not valid.\r\nclientRequestId: 1cc16a39-7d9c-4290-b07d-4c7329611fb8\r\nserviceRequestId: cb6ab59f-909a-2000-ac2f-2217e416179a",
"source": "https://{REDACTED}.sharepoint.com/_api/web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users",
"errors": [
"-1",
"Microsoft.SharePoint.Client.InvalidClientQueryException"
]
}
}
The error I get is:
"The expression "web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users" is not valid.
clientRequestId: 1cc16a39-7d9c-4290-b07d-4c7329611fb8
serviceRequestId: cb6ab59f-909a-2000-ac2f-2217e416179a"
This makes me think the group ID is incorrect. Can someone please advise if this is incorrect or if I have maybe formatted the uri incorrectly?
Try to use the body like this:
{
'__metadata': {
// Type that you are modifying.
'type': 'SP.User'
},
'LoginName': '<<User Login Name>>'
}

How activate OSPF in a router Cisco-IOS-XE using RESTCONF?

I'm trying to activate OSPF routing protocol in a router using a python script with restconf. I send the request to this url https://(router ip)/restconf/data/Cisco-IOS-XE-ospf-native-router:10 but i get this return message: { "errors": { "error": [ { "error-message": "uri keypath not found", "error-tag": "invalid-value", "error-type": "application" } ] } }
I tried with differents urls but no one was the correct and i don't know what is wrong, the url or the content of the body , can someone help me?
This is the content of my script:
import json
import requests
requests.packages.urllib3.disable_warnings()
api_url = "https://(ip)/restconf/data/Cisco-IOS-XE-ospf-native-router:10"
headers = {"Accept": "application/yang-data+json",
"Content-type": "application/yang-data+json"}
basicauth = ("user", "password")
body = '{"router":{"ospf":[{"id":10, "router-id":"1.1.1.1", "network":[{"ip": "172.16.199.1", "mask": "0.0.0.0", "area": 0},{"ip":"192.168.56.101", "mask": "0.0.0.0", "area":0}]}]}}'
requests.put(api_url, auth=basicauth, headers=headers, data=body, verify=False)
resp = requests.get(api_url, auth=basicauth, headers=headers, verify=False)
response_json = resp.json()
print(json.dumps(response_json, indent=5))
OSPF config with RESTCONF can just be modify, not create.
ospf_data = '''
{
"Cisco-IOS-XE-native:router": {
"Cisco-IOS-XE-ospf:router-ospf": {
"ospf": {
"process-id": [
{
"id": 10
}
]
}
}
}
}
'''
def modify_ospf(data):
ospf_api = "/restconf/data/Cisco-IOS-XE-native:native/router"
ospf_uri = "https://" + host + ospf_api
headers = {'Content-Type': 'application/yang-data+json','Accept': 'application/yang-data+json'}
ospf_config_result = requests.request("PUT",
url=ospf_uri,
auth=(username,password),
data=data,
headers=headers,
verify=False)
modify_ospf(ospf_data)
Your body seems not vaild YANG format.
body = '{"router":{"ospf":[{"id":10, "router-id":"1.1.1.1", "network":[{"ip": "172.16.199.1", "mask": "0.0.0.0", "area": 0},{"ip":"192.168.56.101", "mask": "0.0.0.0", "area":0}]}]}}'
You have to follow YANG format like:
$ curl -k -s -u user:password -X GET -H 'Accept: application/yang-data+json' https://172.31.5.1/restconf/data/Cisco-IOS-XE-native:native/Cisco-IOS-XE-native:router/ospf
{
"Cisco-IOS-XE-ospf:ospf": [
{
"id": 10,
"router-id": "1.1.1.1",
"network": [
{
"ip": "172.16.199.1",
"mask": "0.0.0.0",
"area": 0
},
{
"ip": "192.168.56.101",
"mask": "0.0.0.0",
"area": 0
}
]
}
]
}

LinkedIn Assets API: No AWS key returned when registering multi-part upload

I'm trying to upload a video > 200MB via https://api.linkedin.com/v2/assets. When registering a MULTIPART_UPLOAD I do not receive the "x-amz-server-side-encryption" or "x-amz-server-side-encryption-aws-kms-key-id" headers information anywhere in the response. I do get those when registering a SINGLE_REQUEST_UPLOAD and I'm able to successfully upload a video file < 200MB using that mechanism.
Example response for registering a multi-part upload:
{
"value": {
"uploadMechanism": {
"com.linkedin.digitalmedia.uploading.MultipartUpload": {
"metadata": "{METADATA}",
"partUploadRequests": [
{
"headers": {
"Content-Length": "5242880",
"Content-Type": "application/octet-stream"
},
"urlExpiresAt": 1547231882996,
"byteRange": {
"lastByte": 5242879,
"firstByte": 0
},
"url": "{AWS_UPLOAD_URL}"
},
{
"headers": {
"Content-Length": "5242880",
"Content-Type": "application/octet-stream"
},
"urlExpiresAt": 1547231882996,
"byteRange": {
"lastByte": 10485759,
"firstByte": 5242880
},
"url": "{AWS_UPLOAD_URL}"
},
{
"headers": {
"Content-Length": "3585789",
"Content-Type": "application/octet-stream"
},
"urlExpiresAt": 1547231883023,
"byteRange": {
"lastByte": 580302588,
"firstByte": 576716800
},
"url": "{AWS_UPLOAD_URL}"
}
]
}
},
"mediaArtifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:{ASSET_URN},urn:li:digitalmediaMediaArtifactClass:aws-userUploadedVideo)",
"asset": "urn:li:digitalmediaAsset:{ASSET_URN}"
}
}
I have tried to upload to those urls without the two headers and get a 403 Forbidden response saying I'm missing signed headers. The "x-amz-server-side-encryption" and "x-amz-server-side-encryption-aws-kms-key-id" should be returned in the register response right? If not, how do I make requests to aws without them?

share on linkedin returns "Can not parse JSON share document"

I am trying to share a post on linkedin.
I managed to log in and get returned an id and an accessToken but when I follow the REST APIs way of sharing an update I keep getting:
Error: failed [400] {
"errorCode": 0,
"message": "Can not parse JSON share document.\nRequest body:\n\nError:\nnull",
"requestId": "NWGE7D4LSW",
"status": 400,
"timestamp": 1451699447711
}
My http POST looks like this:
HTTP.post('https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=' + accessToken, {
'headers': {
'Content-Type': "application/json",
'x-li-format': "json"
},
'comment': "test!",
'visibility': {
'code': "anyone"
}
});
this worked:
HTTP.post('https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=' + Meteor.user().services.linkedin.accessToken, {
headers: {
"Content-Type": "application/json",
"x-li-format": "json"
},
data: {
comment: "testing",
visibility: {
code: "anyone"
}
}
});

Resources