I am trying to update a Sharepoint file's metadata using the Indy TidHTTP component in my Delphi program.
Within this program I have successfully managed to do everything else I need to do with the Sharepoint files (create/rename/delete/edit/Checkout etc). But whenever I try to update some metadata property I get a "400 Bad Request" exception.
I know that my RequestDigest string is correct because I am able to upload new contents to the file.
I have seen many similar problems reported and have tried all of the suggestions without success.
(One suggestion was to access the file as a list item rather than using the file url, which I have done in the code below.)
var
str,body,MyUrl: string;
stream: TStringStream;
begin
MyUrl:=MySite+'_api/web/Lists/getByTitle(''CM Library'')/Items(2)';
body:='{"__metadata":{"type":"SP.Data.CM_x0020_LibraryItem"},"Title":"UpdatedTitle"}';
stream := TStringStream.Create(body, TEncoding.UTF8);
try
IdHTTP.Request.Accept:='application/json;odata=verbose';
IdHTTP.Request.ContentType:='application/json';
IdHTTP.Request.ContentLength:=stream.size;
IdHTTP.Request.CustomHeaders.Values['X-RequestDigest']:=RequestDigest;
IdHTTP.Request.CustomHeaders.Values['IF-MATCH']:='*';
IdHTTP.Request.CustomHeaders.Values['X-HTTP-Method']:='MERGE';
try
str := IdHTTP.Post(MyUrl,stream);
except
on E : Exception do
ShowMessage('Exception: '+E.Message);
end;
finally
stream.Free;
end;
// Displays 'Exception: HTTP/1.1 400 Bad Request'
I found it! I needed to add ";odata=verbose" to Request.ContentType (as well as Request.Accept)
Sorry to trouble the community, but I was struggling with this for several days!!
Related
I'm working on a project in Delphi 10.1 Berlin which integrates with GitHub. This project intends to download repositories via ZIP files. However, I'm facing some issues.
Originally, I chose (as always) to use Indy to integrate with the GitHub API. I've always used Indy for all web API consumption. However, I'm not having any success using it with GitHub.
The API requires HTTPS. I have obtained the latest OpenSSL DLLs for use with Indy, and am using the Indy library with Delphi 10.1 Berlin.
I have setup a TIdHTTP component with a TIdSSLIOHandlerSocketOpenSSL attached. I've set that IO Handler to all the Method options available, and not one gives me a valid response. I get one of two different responses...
When using sslvSSLv3, I get: error:14094410:SSL routines: SSL3_READ_BYTES:sslv3 alert handshake failure.
When using sslvTLSv1_2, I get: error:1409442E:SSL routines:SSL_READ_BYTES:tlsv1 alert protocol version
I had to resort to TRESTClient for now just to be able to work with the API. But it doesn't handle binary properly.
The test is as simple as https://api.github.com. I can call that in Chrome and Postman, and get a response. Just not via Indy.
How can I accomplish a connection with GitHub's API via Delphi's Indy library?
This Indy HTTP subclass works with the GitHub API.
type
TIndyHttpTransport = class(TIdCustomHTTP)
public
constructor Create;
end;
implementation
uses
IdSSLOpenSSL;
{ TIndyHttpTransport }
constructor TIndyHttpTransport.Create;
var
SSLIO: TIdSSLIOHandlerSocketOpenSSL;
begin
inherited Create;
HTTPOptions := HTTPOptions + [hoNoProtocolErrorException, hoWantProtocolErrorContent];
SSLIO := TIdSSLIOHandlerSocketOpenSSL.Create(Self);
SSLIO.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
SSLIO.SSLOptions.Mode := sslmClient;
SSLIO.SSLOptions.VerifyMode := [];
SSLIO.SSLOptions.VerifyDepth := 0;
Self.IOHandler := SSLIO;
// Request.UserAgent := 'my useragent string';
end;
Maybe your code also needs to modify the user agent string (because I use this code with different service providers, not only GitHub. Some of them require a modified user agent string instead of the default).
Source: https://github.com/michaelJustin/daraja-framework/blob/master/demo/common/IndyHttpTransport.pas
I am trying to retrieve a value from a HTTP web service call in sharepoint designer. This should be simple. the Rest query is simple, and always returns only a single value:
https://Site.sharepoint.com/sites/aSiteName/_api/web/lists/getByTitle('MyListTitle')/items/?$select=Title&$top=1
In the Sharepoint Designer workflow, I'm setting the required Accept and Content-type header to the value of "application/json;odata=verbose
I am unable to get the value of the "Title" field that is returned by the call.
when I execute the REST query in the browser, I get the following data returned:
{"d":{"results":[{"__metadata":{"id":"af9697fe-9340-4bb5-9c75-e43e1fe20d30","uri":"https://site.sharepoint.com/sites/aSiteName/_api/Web/Lists(guid'6228d484-4250-455c-904d-6b7096fee573')/Items(5)","etag":"\"1\"","type":"SP.Data.MyListName"},"Title":"John Doe"}]}}
I've tried dozens of variations of the dictionary 'query', but they always return blank.
I'm using the 'get an item from a dictionary' action in SP Designer, using item name or path values like:
d/results(0)/Title
d/Title
d/results/Title
and literally dozens of other variations - but it always returns blank.
I'm writing the raw response from the webRequest to the list for debugging, and it shows the value like this:
{"odata.metadata":"https:\/\/site.sharepoint.com\/sites\/aSiteName\/_api\/$metadata#SP.ListData.MyListTitle&$select=Title","value":[{"odata.type":"SP.Data.MyListTitle","odata.id":"616ed0ed-ef1d-405b-8ea5-2682d9662b0a","odata.etag":"\"1\"","odata.editLink":"Web\/Lists(guid'6228d484-4250-455c-904d-6b7096fee573')\/Items(5)","Title":"John Doe"}]}
I must be doing something simple that is wrong?
Using "d/results(0)/Title" is right. Check the steps in article below to create a workflow.
CALLING THE SHAREPOINT 2013 REST API FROM A SHAREPOINT DESIGNER WORKFLOW
It working fine in my test workflow.
I faced the exact same issue. In my case the reason was that in the API call, the header was not set properly.
As you would have noticed many times, that if you type the variables inline when creating the "Call Http Web service" action, those might not get set properly. The surest way is to open the properties and set from there. In my case when i opened the properties i found that RequestHeaders was not set. Once i set it from there, i got the desired results.
Hope this helps to someone in future, this question being unanswered till now!!
tried dump those json called from sharepoint workflow into a list. Sometimes you'll get a different format than when you called that from browser. I experienced this issue when calling API projectserver (project online). When I called it using servistate (chrome extension) it returns d/results, but when I dump the value into the list I got value and yet I used same request header value.
i'm facing issue while running rest api service in loadrunner(VUGEN),in soap ui it is working fine.
My Data contains around 10 fields but while request it is breaking one parameter into two then i'm facing internal server error.
Please help and unable to continue in new line in case i want to write it in another line
Code is :
Action()
{
web_custom_request("Calculate",
"URL=http://sdfsdfsdfgsdfgsdfgsdfgsdfgsd/sdfgsdf/sdfgsd",
"Method=POST",
"Resource=0",
"EncType=application/json",
"Mode=HTTP",
"Body={\"program\":\"L002\",\"Number\":null,\"serviceNumber\":\"09000\",\"customerStateName\":\"{state}\",\"storeCode\":\"{store}\",\"Amount\":\"{amount}\",\"paymentDetails\":[{\"type\":\"{types}\",\"amount\":{amount}\"}]}",LAST);
return 0;
}
Unable to write it in two lines of code ,in case i'm trying to write then it is giving syntax error like , is missing or " is missing.Unable to write please any one help.
Response coming as:
{"program":"L002","Number":null,"serviceNumber":"09000","customer
StateName":"MAHARASHTRA","storeCode":"1111","invoiceAmount":"50","paymentDetails":[{"type"
:"CASH","amount":50"}]}
Line is breaking i.e customerStateName into customer,StateName because of this i'm getting Bad Request in Response,Please help.
Since LoadRunner 12.53, you have a new and easier way for making REST API calls, using the web_rest() API. See blog post about it.
I'm trying to use a service of DocuSign API in an abap project. I want to send a document to a specific email so it can be signed. But im getting the following error:
"errorCode": "INVALID_REQUEST_PARAMETER",## "message": "The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime, or 'envelope_ids' or 'transaction_ids' must be specified.
I tried the following:
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url (https://demo.docusign.net/restapi/v2/accounts/XXXXXX')
proxy_host = co_proxy_host
proxy_service = co_proxy_service
IMPORTING
client = lo_http_client
lo_http_client->request->set_method( method = 'POST').
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'X-DocuSign-Authentication'
value = get_auth_header( ). (json auth header)
CALL METHOD lo_http_client->request->set_cdata
EXPORTING
data = create_body( ).
This is my body:
CONCATENATE
`{`
`"emailSubject": "DocuSign REST API Quickstart Sample",`
`"emailBlurb": "Shows how to create and send an envelope from a document.",`
`"recipients": {`
`"signers": [{`
`"email": "test#email",`
`"name": "test",`
`"recipientId": "1",`
`"routingOrder": "1"`
`}]`
`},`
`"documents": [{`
`"documentId": "1",`
`"name": "test.pdf",`
`"documentBase64":` `"` l_encoded_doc `"`
`}],`
`"status": "sent"`
`}` INTO re_data.
The api request to get the Baseurl is working fine. (I know the error is quite specific what the problem is, but i cant find any sources on the docusign api documentation that one of the mentioned parameters should be added to the request)
Thank you in regards
The error message seems to indicate that you're Posting to an endpoint that requires certain query string parameters -- but you're not specifying them as expected in the query string. I'd suggest you check the DocuSign API documentation for the operation you are using, to determine what query string parameters it requires, and then ensure that you're including those parameters in your request URL.
If you can't figure this out using the documentation, then I'd suggest that you update your post to clarify exactly what URL (endpoint) you are using for the request, including any querystring parameters you're specifying in the URL. You can put fake values for things like Account ID, of course -- we just need to see the endpoint you are calling, and what qs params you're sending.
To create an envelope, use
https://demo.docusign.net/restapi/v2/accounts/XXXXXX/envelopes
instead of
https://demo.docusign.net/restapi/v2/accounts/XXXXXX
Thank you for all the answers, i found the mistake. Creating the request wasn´t the problem. I was using the wrong "sending"-method -_-.
now its working :)
lo_rest_client->post( EXPORTING io_entity = lo_request_entity ).
I'm trying to retrieve attachments in the Office365 rest api. Since I want to avoid downloading the entire attachments, I'm using a select clause to avoid downloading the content, which is in the ContentBytes property:
$select="ContentId,ContentType,Id,IsInline,Name,Size"
So basically, I want to retrieve everything except the content. However, this gives the following error message (json):
{
"error":
{
"code": "RequestBroker-ParseUri",
"message": "Could not find a property named 'ContentId' on type 'Microsoft.OutlookServices.Attachment'."
}
}
It's telling me that ContentId doesn't exist, which contradicts the specifications.
Edit: Here is the full request:
GET /api/v2.0/me/messages/AAMkAGZlZjI3N2I3LTg1YWUtNDFiNC05MGI0LTVjYTVmZGI5NGI2YQBGAAAAAABzr8uDji9LRqgTCEsDv22wBwBWTXbvZW0dTKuxUGxpK4-lAAAAAAEMAABWTXbvZW0dTKuxUGxpK4-lAAC5QnKBAAA=/attachments?%24select=ContentId%2CContentType%2CId%2CIsInline%2CName%2CSize
Even more strange, when I do the same query without specifying any select clause, it returns me a full attachment object, including a ContentId.
Anybody can help?
In case anyone has the same question for microsoft graph, you need to pass this filter:
$select=microsoft.graph.fileAttachment/contentId
like this:
GET https://graph.microsoft.com/v1.0/me/messages/attachments?$select=microsoft.graph.fileAttachment/contentId
The request that you posted is getting the message specifications but not the attachments. Since you need to get the content id, you need to add /attachments to the request with any required parameters.
GET https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments/{attachment_id}
So please add the attachments to your query to be able to get the content id.
Hope this helps.
Solved it. The answer was suggested by Brian's comment and I found an additional hint here.
Since 'ContentId' is a property of a FileAttachment, you need to specify that in the request, like so:
$select="Microsoft.OutlookServices.FileAttachment/ContentId,ContentType,Id,IsInline,Name,Size"
That did the trick. Thanks for the suggestions.