rest api: article update with csv - shopware

i want to use the rest api for updating my articles with a csv file.
the manual apdate recoding to this link here works:
https://developers.shopware.com/developers-guide/rest-api/examples/batch/
but how can i load my csv file?
i only fount the links below, which are al little bit older:
https://forum.shopware.com/discussion/11727/api-artikel-import-mit-csv-datei
https://forum.shopware.com/discussion/15796/lagerbestand-abgleich-csv-mit-hilfe-von-api
$api = Shopware()->Api();
...
$data_path = $api->load("http://www.XXXXXX.de/import/test.csv";
this doesn't work in shopware 5

First of all the Rest API is an API which has to be called by URL with parameters. You cannot instanciate it within you PHP code directly. It is used if you want to have another software connect to shopware.
In you case there is another way. You can use the Resources that the API internally also uses.
$manger = new \Shopware\Components\Api\Manager();
$resource = $manger->getResource('Article');
foreach ($csvRows as $row){
// create an array for the csv > article mapping
$data = [];
$data['name'] = $row['csv_row_name'];
// do all mappings into the data array
// ....
// create the article from that array
$article = $resource->create($data);
}
In this documentation you can see which fields are required in the $data array to successfully create an article
https://developers.shopware.com/developers-guide/rest-api/api-resource-article/

Related

How to create an image import job using KTA SDK?

I am trying to create a job using SDK. Simple job with send email activity work like a charm!
But when I try to create a job with variables input folder to import few images it doesn't work at all. Am I missing very trivial settings ?
My process has classification activity & extraction activities
Variables : DefaultImportFolder
FYI : My process works fine if I set import settings -> import sources. That tells me there is no issue with my process process Smile. But when I try to run through console app with dynamic variables, it doesn't work.
Following is my sample code. Any help?
ProcessIdentity processIdentity = new ProcessIdentity
{
Name = "SDK TestProcess"
};
var jobService = new TotalAgility.Sdk.JobService();
JobInitialization jobInitialization = new JobInitialization();
InputVariableCollection variablesCollections = new InputVariableCollection();
InputVariable inputVariable = new InputVariable
{
Id = "DefaultImportFolder",
Value = #"\\FolderPath",
};
variablesCollections.Add(inputVariable);
inputVariable = new InputVariable
{
Id = "ExportSuccess",
Value = "true"
};
variablesCollections.Add(inputVariable);
var createJobAndProgress = jobService.CreateJob(sessionId, processIdentity, jobInitialization);
Console.WriteLine($"Job ID {createJobAndProgress.Id}");
As Suggested by Steve, tried with WithDocuments method Still no luck .....
JobWithDocumentsInitialization jobWithDocsInitialization = new JobWithDocumentsInitialization();
Agility.Sdk.Model.Capture.RuntimeDocumentCollection documentsCollection = new Agility.Sdk.Model.Capture.RuntimeDocumentCollection();
Agility.Sdk.Model.Capture.RuntimeDocument runtimeDoc = new Agility.Sdk.Model.Capture.RuntimeDocument
{
FilePath = #"FolderPath\abc.tif",
};
documentsCollection.Add(runtimeDoc);
jobWithDocsInitialization.Documents = documentsCollection;
var jobIdentity = jobService.CreateJobWithDocuments(sessionId, processIdentity, jobWithDocsInitialization);
Console.WriteLine($"Job ID {jobIdentity.Id}");
A folder variable represents a reference to a folder that already exists in the KTA database, so you can't just set a file path to the variable. When you create a job via an import source, it is creating the folder and documents as part of creating the job.
To do the same in your code, you would use one of the "WithDocuments" APIs such as CreateJobWithDocuments which has parammeters specific to importing documents into the process, including by file path.
As discussed in this other answer (Kofax TotalAgility Send a PDF Document to Jobs Queue (KTA)), you may want to look at the sample code that is included with the product (that most people don't realize is available), and also look at other API functions for more context on the parameters needed for the "WithDocuments" APIs mentioned above.

How to remove FilteringScheme using C# API?

I am trying to figure out how to remove a FilteringScheme from the API. I was looking at the C# API but couldn't find a delete or remove method. The code below adds one but I am having trouble how to delete one after I add it. Does anyone have any suggestions?
// Add a new data filtering selection.
DataFilteringSelection dataFilteringSelection = document.Data.Filterings.Add("Filtering Scheme1");
// A filtering scheme has now been implicitly added for the new data filtering selection.
FilteringScheme myFilteringScheme = document.FilteringSchemes[dataFilteringSelection];
// Let the active page use the new filtering scheme.
document.ActivePageReference.FilterPanel.FilteringSchemeReference = myFilteringScheme;
I found out how to do that thanks to the TIBCO community answer. This is what I needed to do:
foreach (var fs in Document.FilteringSchemes)
{
if (fs.FilteringSelectionReference.Name == "Georgi")
{
context.Document.Data.Filterings.Remove(fs.FilteringSelectionReference);
}
}

Retrieve Documents from a Template

I created a template within my DocuSign developer Sandbox that contains one document. I'm using the C# SDK to try and send out an envelope to a user, based on a template.
Here's the code where I retrieve all of the templates.
TemplatesApi templateApi = new TemplatesApi(ApiClient.Configuration);
EnvelopeTemplateResults templateResults = templateApi.ListTemplates(AccountID);
The issue I am having is the EnvelopeTemplateResults does NOT have any documents associated with it.
When I use the REST API using POSTMAN, performing a GET to this URL, I can see that there's an envelopeTemplateDefinition, that has a Document on it, which is the one I want.
My question is, how, using the SDK API, can I get the envelopeTemplateDefinition ?
In order to have the ListTemplates method include the Documents info, you have to set an Include parameter:
var templatesApi = new TemplatesApi(apiClient.Configuration);
var listTemplatesOptions = new TemplatesApi.ListTemplatesOptions { include = "documents" };
var templateResults = templatesApi.ListTemplates(accountId, listTemplatesOptions);
If you are trying to get the Template Definition of a single template, the templatesApi.Get() method can be used with its own set of Include options:
var getTemplateOptions = new TemplatesApi.GetOptions { include = "documents" };
var templateDefinition = templatesApi.Get(accountId, templateId, getTemplateOptions);
Finally, if you're trying to get an actual PDF out of a specific template, that would be the templatesApi.GetDocument() method:
templatesApi.GetDocument(accountId, templateId, documentId);
Where DocumentId is the specific document you want to pull, or "Combined" if you want to pull all the documents in as a single PDF.
Chris, if you are using the v2 API, there's an endpoint:
GET /v2/accounts/{accountId}/templates/{templateId}/documents/{documentId}
you can try it here - https://apiexplorer.docusign.com/#/esign/restapi?categories=Templates&tags=TemplateDocuments&operations=get
the c# SDK inside TemplateAPI has GetDocument() and UpdateDocument() methods

Post to SMF Forum via PHP

I am building a CMS that supports a website which also contains an SMF forum (2.0.11). One of the modules in the CMS involves a "report" that tracks attendance. That data is queried to tables outside of smf, but in the same database. In addition to what it does now, I would also like for a post to be made in a specific board on the SMF forum containing the formatted content. As all of the posts are contained by the database, surely this is possible, but it seems there is more to it than a single row in a table.
To put it in the simplest code possible, below is what I want to happen when I click Submit on my page.
$title = "2015-03-04 - Attendance";
$author = "KGrimes";
$body = "Attendance was good.";
$SQL = "INSERT INTO smf_some_table (title, author, body) VALUES ($title, $author, $body)";
$result = mysqli_query($db_handle, $SQL);
Having dug through the smf DB tables and the post() and post2() functions, it seems there is more than one table involved when a post is made. Has anyone outlined this before?
I've looked into solutions such as the Custom Form Mod, but these forms and templates are not what I am looking for. I already have the data inputted and POST'ed to variables, I just need the right table(s) to INSERT it into so that it appears on the forum.
Thank you in advance for any help!
Source: http://www.simplemachines.org/community/index.php?topic=542521.0
Code where you want to create post:
//Define variables
//msgOptions
$smf_subject = "Test Title";
//Handle & escape
$smf_subject = htmlspecialchars($smf_subject);
$smf_subject = quote_smart($smf_subject, $db_handle);
$smf_body = "This is a test.";
//Handle & escape
$smf_body = htmlspecialchars($smf_body);
$smf_body = quote_smart($smf_body, $db_handle);
//topicOptions
$smf_board = 54; //Any board id, found in URL
//posterOptions
$smf_id = 6; //any id, this is found as ID in memberlist
//SMF Post function
require_once('../../forums/SSI.php');
require_once('../../forums/Sources/Subs-Post.php');
//createPost($msgOptions, $topicOptions, $posterOptions);
// Create a post, either as new topic (id_topic = 0) or in an existing one.
// The input parameters of this function assume:
// - Strings have been escaped.
// - Integers have been cast to integer.
// - Mandatory parameters are set.
// Collect all parameters for the creation or modification of a post.
$msgOptions = array(
'subject' => $smf_subject,
'body' => $smf_body,
//'smileys_enabled' => !isset($_POST['ns']),
);
$topicOptions = array(
//'id' => empty($topic) ? 0 : $topic,
'board' => $smf_board,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $smf_id,
);
//Execute SMF post
createPost($msgOptions, $topicOptions, $posterOptions);
This will create the simplest of posts with title and body defined by you, along with location and who the author is. More parameters can be found in the SMF functions database for createPost. The SSI and Subs-Post.php includes must be the original directly, copying them over doesn't do the trick.

Post an activity entry to all and to me

I try to post an activity entry with the ActivityService class. I want that all my followers and myself can see it.
this.
ActivityStreamService service = new ActivityStreamService();
service.postEntry("#me", "#all", "", jsonObject, header);
I saw my entry but not my follower
With this.
ActivityStreamService service = new ActivityStreamService();
service.postEntry("#public", "#all", "", jsonObject, header);
My follower saw the entry, but I do not see this.
Have anybody an idea which one is the correct combination?
There are a couple of ways...
1 - You can use the Distribution method
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Distributing_events_ic45&content=pdcontent
openSocial : {
"deliverTo":[
{"objectType":"person",
"id":"tag:example.org,2011:jane"}
]
}
*You will need a special j2ee role in order to distribute this content (trustedApplication Role in WidgetContainer Application)
2 - You can use the ublog
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Posting_microblog_entries_ic45&content=pdcontent
POST to my board: /ublog/#me/#all
{ "content": "A new test post" }
3 -
Otherwise, you need to do multiple posts
This means than the event would have to be sent separately to each user that is to receive the event. In order to ensure that this can be done more efficiently, an extension to the the Open Social spec allows for a few means of distribution in the data model
I hope this helps.
As well as the openSocial JSON object, you could use to JSON object
For example this JSON snippet:
"to":[
{"objectType":"person", "id":"#me"}.
{"objectType":"person", "id":"#public"}
{"objectType":"community", "id":"xxx-xx-xxx0x0x0x0x0x"}
]
...can be produced by updating your jsonObject like so:
// #me
JsonJavaObject meJson = new JsonJavaObject();
meJson.put("objectType","person");
meJson.put("id","#me");
// #public
JsonJavaObject publicJson = new JsonJavaObject();
publicJson.put("objectType","person");
publicJson.put("id","#public");
// Community
JsonJavaObject communityJson = new JsonJavaObject();
communityJson.put("objectType","community");
communityJson.put("id","xxx-xx-xxx0x0x0x0x0x");
// Shove them all in a list
List<JsonJavaObject> toJson = new ArrayList<JsonJavaObject>();
toJson.add(meJson);
toJson.add(publicJson);
toJson.add(communityJson);
// add to: [...] to the root JsonJavaObject
jsonObject.put("to", toJson ) ;
Also: Here's a video on adding a user to the trustedExternalApplication role.

Resources